Skip to content

Commit

Permalink
Add new native rg_observer_find_next_player
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathan-up committed Jul 27, 2024
1 parent 472d279 commit 583fac9
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 0 deletions.
12 changes: 12 additions & 0 deletions reapi/extra/amxmodx/scripting/include/reapi_gamedll.inc
Original file line number Diff line number Diff line change
Expand Up @@ -1185,6 +1185,18 @@ native rg_disappear(const player);
*/
native rg_set_observer_mode(const player, const mode);

/*
* Call origin function CBasePlayer::Observer_FindNextPlayer()
* @note Player must be a valid observer (m_afPhysicsFlags & PFLAG_OBSERVER).
*
* @param player Player index.
* @param bReverse If bReverse is true, finding order will be reversed
* @param name Player name to find.
*
* @noreturn
*/
native rg_observer_find_next_player(const player, const bool:bReverse = false, const name[] = "");

/*
* Emits a death notice (logs, DeathMsg event, win conditions check)
*
Expand Down
1 change: 1 addition & 0 deletions reapi/include/cssdk/dlls/API/CSPlayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ class CCSPlayer: public CCSMonster
virtual void SendItemStatus() = 0;
virtual void ReloadWeapons(CBasePlayerItem *pWeapon = nullptr, bool bForceReload = false, bool bForceRefill = false) = 0;
virtual void Observer_SetMode(int iMode) = 0;
virtual void Observer_FindNextPlayer(bool bReverse, const char *name = nullptr) = 0;
virtual bool SelectSpawnSpot(const char *pEntClassName, CBaseEntity* &pSpot) = 0;
virtual bool SwitchWeapon(CBasePlayerItem *pWeapon) = 0;
virtual void SwitchTeam() = 0;
Expand Down
29 changes: 29 additions & 0 deletions reapi/src/natives/natives_misc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3242,6 +3242,34 @@ cell AMX_NATIVE_CALL rg_set_observer_mode(AMX* amx, cell* params)
return TRUE;
}

/*
* Call origin function CBasePlayer::Observer_FindNextPlayer()
* @note Player must be a valid observer (m_afPhysicsFlags & PFLAG_OBSERVER).
*
* @param player Player index.
* @param bReverse If bReverse is true, finding order will be reversed
* @param name Player name to find.
*
* @noreturn
*/
cell AMX_NATIVE_CALL rg_observer_find_next_player(AMX* amx, cell* params)
{
enum args_e { arg_count, arg_index, arg_bReverse, arg_name };

CHECK_ISPLAYER(arg_index)

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

char nameBuf[MAX_PLAYER_NAME_LENGTH];
const char* name = getAmxString(amx, params[arg_name], nameBuf);
if (strcmp(name, "") == 0)
name = nullptr;

pPlayer->CSPlayer()->Observer_FindNextPlayer(params[arg_bReverse] != 0, name);
return TRUE;
}

/*
* Emits a death notice (logs, DeathMsg event, win conditions check)
*
Expand Down Expand Up @@ -3455,6 +3483,7 @@ AMX_NATIVE_INFO Misc_Natives_RG[] =
{ "rg_switch_best_weapon", rg_switch_best_weapon },
{ "rg_disappear", rg_disappear },
{ "rg_set_observer_mode", rg_set_observer_mode },
{ "rg_observer_find_next_player", rg_observer_find_next_player },
{ "rg_death_notice", rg_death_notice },
{ "rg_player_relationship", rg_player_relationship },

Expand Down

0 comments on commit 583fac9

Please sign in to comment.