From 1ef3c5a753ed5ae7a27a5723f50d4ab636ec79e0 Mon Sep 17 00:00:00 2001 From: fant1kua Date: Sat, 14 Dec 2019 12:24:52 +0200 Subject: [PATCH] Add API to set if player can hear another player (#158) * Add API to set if player can hear another player --- gradle.properties | 2 +- .../scripting/include/reapi_gamedll.inc | 29 +++++++ reapi/include/cssdk/dlls/gamerules.h | 3 + reapi/include/cssdk/dlls/regamedll_api.h | 2 +- .../include/cssdk/game_shared/voice_gamemgr.h | 3 + reapi/src/natives/natives_misc.cpp | 84 +++++++++++++++++++ 6 files changed, 121 insertions(+), 2 deletions(-) diff --git a/gradle.properties b/gradle.properties index 8b095261..9c1255b4 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,3 +1,3 @@ majorVersion=5 -minorVersion=11 +minorVersion=12 maintenanceVersion=0 diff --git a/reapi/extra/amxmodx/scripting/include/reapi_gamedll.inc b/reapi/extra/amxmodx/scripting/include/reapi_gamedll.inc index cfc8fbad..787f1df4 100644 --- a/reapi/extra/amxmodx/scripting/include/reapi_gamedll.inc +++ b/reapi/extra/amxmodx/scripting/include/reapi_gamedll.inc @@ -863,3 +863,32 @@ native rg_check_win_conditions(); * @noreturn */ native rg_initialize_player_counts(&num_alive_terrorist = 0, &num_alive_ct = 0, &num_dead_terrorist = 0, &num_dead_ct = 0); + +/* +* Reset if player can hear another player. +* +* @param index Player id +* @noreturn +*/ +native rg_reset_can_hear_player(const index); + +/* +* Set if player can hear another player +* +* @param listener Listener player id +* @param sender Sender player id +* @param can_hear Can listener hear sender +* +* @noreturn +*/ +native rg_set_can_hear_player(const listener, const sender, const bool:can_hear); + +/* +* Get if player can hear another player +* +* @param listener Listener player id +* @param sender Sender player id +* +* @return boolean +*/ +native bool:rg_get_can_hear_player(const listener, const sender); diff --git a/reapi/include/cssdk/dlls/gamerules.h b/reapi/include/cssdk/dlls/gamerules.h index a4c31345..1e17e588 100644 --- a/reapi/include/cssdk/dlls/gamerules.h +++ b/reapi/include/cssdk/dlls/gamerules.h @@ -673,6 +673,9 @@ typedef struct mapcycle_s class CCStrikeGameMgrHelper: public IVoiceGameMgrHelper { public: virtual bool CanPlayerHearPlayer(CBasePlayer *pListener, CBasePlayer *pSender) = 0; + virtual void ResetCanHearPlayer(edict_t* pEdict) = 0; + virtual void SetCanHearPlayer(CBasePlayer* pListener, CBasePlayer* pSender, bool bCanHear) = 0; + virtual bool GetCanHearPlayer(CBasePlayer* pListener, CBasePlayer* pSender) = 0; }; extern CGameRules *g_pGameRules; diff --git a/reapi/include/cssdk/dlls/regamedll_api.h b/reapi/include/cssdk/dlls/regamedll_api.h index 9189cbf6..c689423f 100644 --- a/reapi/include/cssdk/dlls/regamedll_api.h +++ b/reapi/include/cssdk/dlls/regamedll_api.h @@ -38,7 +38,7 @@ #include #define REGAMEDLL_API_VERSION_MAJOR 5 -#define REGAMEDLL_API_VERSION_MINOR 12 +#define REGAMEDLL_API_VERSION_MINOR 13 // CBasePlayer::Spawn hook typedef IHookChainClass IReGameHook_CBasePlayer_Spawn; diff --git a/reapi/include/cssdk/game_shared/voice_gamemgr.h b/reapi/include/cssdk/game_shared/voice_gamemgr.h index 851c93ae..e8fdca4b 100644 --- a/reapi/include/cssdk/game_shared/voice_gamemgr.h +++ b/reapi/include/cssdk/game_shared/voice_gamemgr.h @@ -41,6 +41,9 @@ class IVoiceGameMgrHelper { // Called each frame to determine which players are allowed to hear each other. This overrides // whatever squelch settings players have. virtual bool CanPlayerHearPlayer(CBasePlayer *pListener, CBasePlayer *pTalker) = 0; + virtual void ResetCanHearPlayer(edict_t* pEdict) = 0; + virtual void SetCanHearPlayer(CBasePlayer* pListener, CBasePlayer* pSender, bool bCanHear) = 0; + virtual bool GetCanHearPlayer(CBasePlayer* pListener, CBasePlayer* pSender) = 0; }; // CVoiceGameMgr manages which clients can hear which other clients. diff --git a/reapi/src/natives/natives_misc.cpp b/reapi/src/natives/natives_misc.cpp index bbc34037..7c7cde4e 100644 --- a/reapi/src/natives/natives_misc.cpp +++ b/reapi/src/natives/natives_misc.cpp @@ -2214,6 +2214,86 @@ cell AMX_NATIVE_CALL rg_initialize_player_counts(AMX *amx, cell *params) return TRUE; } +/* +* Reset if player can hear another player. +* +* @param index Player id +* @noreturn +* +* native rg_reset_can_hear_player(const index); +*/ +cell AMX_NATIVE_CALL rg_reset_can_hear_player(AMX* amx, cell* params) +{ + enum args_e { arg_count, arg_index }; + + CHECK_GAMERULES(); + CHECK_ISPLAYER(arg_index); + + CBasePlayer* pPlayer = UTIL_PlayerByIndex(params[arg_index]); + CHECK_CONNECTED(pPlayer, arg_index); + + CSGameRules()->m_VoiceGameMgr.m_pHelper->ResetCanHearPlayer(pPlayer->edict()); + + return TRUE; +} + +/* +* Set if player can hear another player +* +* @param listener Listener player id +* @param sender Sender player id +* @param can_hear Can listener hear sender +* +* @noreturn +* +* native rg_set_can_hear_player(const listener, const sender, const bool:can_hear); +*/ +cell AMX_NATIVE_CALL rg_set_can_hear_player(AMX* amx, cell* params) +{ + enum args_e { arg_count, arg_listener, arg_sender, arg_can_hear }; + + CHECK_GAMERULES(); + CHECK_ISPLAYER(arg_listener); + CHECK_ISPLAYER(arg_sender); + + CBasePlayer* pListener = UTIL_PlayerByIndex(params[arg_listener]); + CHECK_CONNECTED(pListener, arg_listener); + + CBasePlayer* pSender = UTIL_PlayerByIndex(params[arg_sender]); + CHECK_CONNECTED(pSender, arg_sender); + + CSGameRules()->m_VoiceGameMgr.m_pHelper->SetCanHearPlayer(pListener, pSender, params[arg_can_hear] != 0); + + return TRUE; +} + +/* +* Get if player can hear another player +* +* @param listener Listener player id +* @param sender Sender player id +* +* @return boolean +* +* native bool:rg_get_can_hear_player(const listener, const sender); +*/ +cell AMX_NATIVE_CALL rg_get_can_hear_player(AMX* amx, cell* params) +{ + enum args_e { arg_count, arg_listener, arg_sender }; + + CHECK_GAMERULES(); + CHECK_ISPLAYER(arg_listener); + CHECK_ISPLAYER(arg_sender); + + CBasePlayer* pListener = UTIL_PlayerByIndex(params[arg_listener]); + CHECK_CONNECTED(pListener, arg_listener); + + CBasePlayer* pSender = UTIL_PlayerByIndex(params[arg_sender]); + CHECK_CONNECTED(pSender, arg_sender); + + return CSGameRules()->m_VoiceGameMgr.m_pHelper->GetCanHearPlayer(pListener, pSender); +} + AMX_NATIVE_INFO Misc_Natives_RG[] = { { "rg_set_animation", rg_set_animation }, @@ -2298,6 +2378,10 @@ AMX_NATIVE_INFO Misc_Natives_RG[] = { "rg_check_win_conditions", rg_check_win_conditions }, { "rg_initialize_player_counts", rg_initialize_player_counts }, + { "rg_reset_can_hear_player", rg_reset_can_hear_player }, + { "rg_set_can_hear_player", rg_set_can_hear_player }, + { "rg_get_can_hear_player", rg_get_can_hear_player }, + { nullptr, nullptr } };