Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new Natives for players #326

Open
wants to merge 15 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .vs/reapi/v17/.wsuo
Binary file not shown.
97 changes: 97 additions & 0 deletions reapi/extra/amxmodx/scripting/include/reapi_gamedll.inc
Original file line number Diff line number Diff line change
Expand Up @@ -1221,3 +1221,100 @@ native rg_player_relationship(const player, const target);
* @noreturn
*/
native rg_send_death_message(const pKiller, const pVictim, const pAssister, const pevInflictor, const killerWeaponName[], const DeathMessageFlags:iDeathMessageFlags, const KillRarity:iRarityOfKill);

/*
* Usually called whenever an entity gets attacked by a hitscan (such as a gun) weapon.
*
* @param index Client index
* @param attacker Attacker index
* @param flDamage The amount of damage
* @param vecDir Direction
* @param ptr Traceresult pointer
* @param bitsDamageType Damage type DMG_*
*
* @noreturn
*/
native rg_player_traceattack(const index, const attacker, const Float:flDamage, Float:vecDir[3], const ptr, const bitsDamageType);

/*
* Usually called whenever an entity takes any kind of damage.
*
* @param index Client index
* @param inflictor Inflictor index
* @param attacker Attacker index
* @param flDamage The amount of damage
* @param bitsDamageType Damage type DMG_*
*
* @return 1 on success, 0 otherwise
*/
native rg_player_takedamage(const index, const inflictor, const attacker, const Float:flDamage, const bitsDamageType);

/*
* Usually called whenever an entity gets a form of a heal.
*
* @param index Client index
* @param flHealth The amount of health
* @param bitsDamageType Damage type DMG_*
*
* @return 1 on success, 0 otherwise
*/
native rg_player_takehealth(const index, const Float:flHealth, const bitsDamageType);

/*
* Normally called whenever an entity dies.
*
* @param index Client index
* @param attacker Attacker index
* @param gib Use DMG_NEVERGIB or DMG_ALWAYSGIB
*
* @noreturn
*/
native rg_player_killed(const index, const attacker, const gib);

/*
* Typically adds points to the entity.
*
* @param index Client index
* @param score Adds the score to the current amount
* @param allowNegativeScore Allow Negative Score
*
* @noreturn
*/
native rg_player_addpoints(const index, const score, const bool:allowNegativeScore);

/*
* This will never return true if a client is not connected. If you need
* to know whether a client is alive, an additional call to is_user_connected() is unnecessary.
*
* @param index Client index
*
* @return 1 on success, 0 otherwise
*/
native rg_is_player_alive(const index);

/*
* Whether or not the entity is a net client.
*
* @param index Client index
*
* @return 1 on success, 0 otherwise
*/
native rg_is_player_net_client(const index);

/*
* returns the position in vector the exact position of the weapon in which the player is located
*
* @param index Client index
*
* @return Float:[3] The source position
*/
native Float:[3] rg_get_player_gun_position(const index);

/*
* Returns if the client is a bot.
*
* @param index Client index
*
* @return 1 on success, 0 otherwise
*/
native rg_is_player_bot(const index);
213 changes: 212 additions & 1 deletion reapi/src/natives/natives_misc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3345,6 +3345,207 @@ cell AMX_NATIVE_CALL rg_send_death_message(AMX *amx, cell *params)
return TRUE;
}

/*
* Usually called whenever an entity gets attacked by a hitscan (such as a gun) weapon.
*
* @param index Client index
* @param attacker Attacker index
* @param flDamage The amount of damage
* @param vecDir Direction
* @param ptr Traceresult pointer
* @param bitsDamageType Damage type DMG_*
*
* @noreturn
*/
cell AMX_NATIVE_CALL rg_player_traceattack(AMX* amx, cell* params)
{
enum args_e { arg_count, arg_index, arg_attacker, arg_damage, arg_dir, arg_trace, arg_dmg_type };

CHECK_ISPLAYER(arg_index);
CHECK_ISENTITY(arg_attacker);

CBasePlayer* pPlayer = UTIL_PlayerByIndex(params[arg_index]);
CHECK_CONNECTED(pPlayer, arg_index);

CAmxArgs args(amx, params);
pPlayer->TraceAttack(args[arg_attacker], args[arg_damage], args[arg_dir], args[arg_trace], args[arg_dmg_type]);
return TRUE;
}

/*
* Usually called whenever an entity takes any kind of damage.
*
* @param index Client index
* @param inflictor Inflictor index
* @param attacker Attacker index
* @param flDamage The amount of damage
* @param bitsDamageType Damage type DMG_*
*
* @return 1 on success, 0 otherwise
*/
cell AMX_NATIVE_CALL rg_player_takedamage(AMX* amx, cell* params)
{
enum args_e { arg_count, arg_index, arg_inflictor, arg_attacker, arg_damage, arg_dmg_type };

CHECK_ISPLAYER(arg_index);
CHECK_ISENTITY(arg_inflictor);
CHECK_ISENTITY(arg_attacker);

CBasePlayer* pPlayer = UTIL_PlayerByIndex(params[arg_index]);
CHECK_CONNECTED(pPlayer, arg_index);

CAmxArgs args(amx, params);
return pPlayer->TakeDamage(args[arg_attacker], args[arg_inflictor], args[arg_damage], args[arg_dmg_type]);
}

/*
* Usually called whenever an entity gets a form of a heal.
*
* @param index Client index
* @param flHealth The amount of health
* @param bitsDamageType Damage type DMG_*
*
* @return 1 on success, 0 otherwise
*/
cell AMX_NATIVE_CALL rg_player_takehealth(AMX* amx, cell* params)
{
enum args_e { arg_count, arg_index, arg_health, arg_dmg_type };

CHECK_ISPLAYER(arg_index);

CBasePlayer* pPlayer = UTIL_PlayerByIndex(params[arg_index]);
CHECK_CONNECTED(pPlayer, arg_index);

CAmxArgs args(amx, params);
return pPlayer->TakeHealth(args[arg_health], args[arg_dmg_type]);
}

/*
* Normally called whenever an entity dies.
*
* @param index Client index
* @param attacker Attacker index
* @param gib Use DMG_NEVERGIB or DMG_ALWAYSGIB
*
* @noreturn
*/
cell AMX_NATIVE_CALL rg_player_killed(AMX* amx, cell* params)
{
enum args_e { arg_count, arg_index, arg_attacker, arg_gib };

CHECK_ISPLAYER(arg_index);
CHECK_ISENTITY(arg_attacker);

CBasePlayer* pPlayer = UTIL_PlayerByIndex(params[arg_index]);
CHECK_CONNECTED(pPlayer, arg_index);

CAmxArgs args(amx, params);
pPlayer->Killed(args[arg_attacker], args[arg_gib]);
return TRUE;
}

/*
* Typically adds points to the entity.
*
* @param index Client index
* @param score Adds the score to the current amount
* @param allowNegativeScore Allow Negative Score
*
* @noreturn
*/
cell AMX_NATIVE_CALL rg_player_addpoints(AMX* amx, cell* params)
{
enum args_e { arg_count, arg_index, arg_score, arg_allow_negative_score };

CHECK_ISPLAYER(arg_index);

CBasePlayer* pPlayer = UTIL_PlayerByIndex(params[arg_index]);
CHECK_CONNECTED(pPlayer, arg_index);

CAmxArgs args(amx, params);
pPlayer->AddPoints(args[arg_score], args[arg_allow_negative_score]);
return TRUE;
}

/*
* This will never return true if a client is not connected. If you need
* to know whether a client is alive, an additional call to is_user_connected() is unnecessary.
*
* @param index Client index
*
* @return 1 on success, 0 otherwise
*/
cell AMX_NATIVE_CALL rg_is_player_alive(AMX* amx, cell* params)
{
enum args_e { arg_count, arg_index };

CHECK_ISPLAYER(arg_index);

CBasePlayer* pPlayer = UTIL_PlayerByIndex(params[arg_index]);
CHECK_CONNECTED(pPlayer, arg_index);

return pPlayer->IsAlive();
}

/*
* Whether or not the entity is a net client.
*
* @param index Client index
*
* @return 1 on success, 0 otherwise
*/
cell AMX_NATIVE_CALL rg_is_player_net_client(AMX* amx, cell* params)
{
enum args_e { arg_count, arg_index };

CHECK_ISPLAYER(arg_index);

CBasePlayer* pPlayer = UTIL_PlayerByIndex(params[arg_index]);
CHECK_CONNECTED(pPlayer, arg_index);

return pPlayer->IsNetClient();
}

/*
* returns the position in vector the exact position of the weapon in which the player is located
*
* @param index Client index
*
* @return Float:[3] The source position
*/
cell AMX_NATIVE_CALL rg_get_player_gun_position(AMX* amx, cell* params)
{
enum args_e { arg_count, arg_index, arg_out };

CHECK_ISPLAYER(arg_index);

CBasePlayer* pPlayer = UTIL_PlayerByIndex(params[arg_index]);
CHECK_CONNECTED(pPlayer, arg_index);

CAmxArgs args(amx, params);
args[arg_out].vector() = pPlayer->GetGunPosition();
return TRUE;
}

/*
* Returns if the client is a bot.
*
* @param index Client index
*
* @return 1 on success, 0 otherwise
*/
cell AMX_NATIVE_CALL rg_is_player_bot(AMX* amx, cell* params)
{
enum args_e { arg_count, arg_index };

CHECK_ISPLAYER(arg_index);

CBasePlayer* pPlayer = UTIL_PlayerByIndex(params[arg_index]);
CHECK_CONNECTED(pPlayer, arg_index);

return pPlayer->IsBot();
}

AMX_NATIVE_INFO Misc_Natives_RG[] =
{
{ "rg_set_animation", rg_set_animation },
Expand Down Expand Up @@ -3460,6 +3661,16 @@ AMX_NATIVE_INFO Misc_Natives_RG[] =

{ "rg_send_death_message", rg_send_death_message },

{ "rg_player_traceattack", rg_player_traceattack },
{ "rg_player_takedamage", rg_player_takedamage },
{ "rg_player_takehealth", rg_player_takehealth },
{ "rg_player_killed", rg_player_killed },
{ "rg_player_addpoints", rg_player_addpoints },
{ "rg_is_player_alive", rg_is_player_alive },
{ "rg_is_player_net_client", rg_is_player_net_client },
{ "rg_get_player_gun_position", rg_get_player_gun_position },
{ "rg_is_player_bot", rg_is_player_bot },

{ nullptr, nullptr }
};

Expand Down Expand Up @@ -3748,4 +3959,4 @@ void RegisterNatives_Misc()

g_amxxapi.AddNatives(Misc_Natives_RG);
g_amxxapi.AddNatives(Misc_Natives_RH);
}
}
Loading