From 4063428151e42adec57544744dc1a63a351f1e20 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Federico=20Mat=C3=ADas?= <41979395+FEDERICOMB96@users.noreply.github.com> Date: Thu, 8 Feb 2024 00:06:58 -0300 Subject: [PATCH] implement `rg_send_death_message` native --- .../scripting/include/reapi_gamedll.inc | 18 ++++++- reapi/include/cssdk/dlls/gamerules.h | 2 + reapi/src/natives/natives_misc.cpp | 54 +++++++++++++++++++ 3 files changed, 73 insertions(+), 1 deletion(-) diff --git a/reapi/extra/amxmodx/scripting/include/reapi_gamedll.inc b/reapi/extra/amxmodx/scripting/include/reapi_gamedll.inc index 454ff8ce..7e66a4ed 100644 --- a/reapi/extra/amxmodx/scripting/include/reapi_gamedll.inc +++ b/reapi/extra/amxmodx/scripting/include/reapi_gamedll.inc @@ -1204,4 +1204,20 @@ native rg_death_notice(const pVictim, const pKiller, const pevInflictor); * * @return Match player relationship, see GR_* constants in cssdk_const.inc */ -native rg_player_relationship(const player, const target); \ No newline at end of file +native rg_player_relationship(const player, const target); + +/* +* Sends death messages to all players, including info about the killer, victim, weapon used, +* extra death flags, death position, assistant, and kill rarity +* +* @param pKiller Killer index (if any). +* @param pVictim Victim index. +* @param pAssister Assisting player index (if any). +* @param pevInflictor Inflictor entity. 0 = world +* @param killerWeaponName The name of the weapon used by the killer. +* @param iDeathMessageFlags Flags indicating extra death message info, see DeathMessageFlags enum in cssdk_const.inc +* @param iRarityOfKill An bitsums representing the rarity classification of the kill, see KillRarity enum in cssdk_const.inc +* +* @noreturn +*/ +native rg_send_death_message(const pKiller, const pVictim, const pAssister, const pevInflictor, const killerWeaponName[], const DeathMessageFlags:iDeathMessageFlags, const KillRarity:iRarityOfKill); \ No newline at end of file diff --git a/reapi/include/cssdk/dlls/gamerules.h b/reapi/include/cssdk/dlls/gamerules.h index d0781beb..5bb125d0 100644 --- a/reapi/include/cssdk/dlls/gamerules.h +++ b/reapi/include/cssdk/dlls/gamerules.h @@ -553,6 +553,8 @@ class CHalfLifeMultiplay: public CGameRules virtual bool HasRoundTimeExpired() = 0; virtual bool IsBombPlanted() = 0; + virtual void SendDeathMessage(CBaseEntity *pKiller, CBasePlayer *pVictim, CBasePlayer *pAssister, entvars_t *pevInflictor, const char *killerWeaponName, int iDeathMessageFlags, int iRarityOfKill) = 0; + public: bool ShouldSkipShowMenu() const { return m_bSkipShowMenu; } void MarkShowMenuSkipped() { m_bSkipShowMenu = false; } diff --git a/reapi/src/natives/natives_misc.cpp b/reapi/src/natives/natives_misc.cpp index 609695c3..0e10c02c 100644 --- a/reapi/src/natives/natives_misc.cpp +++ b/reapi/src/natives/natives_misc.cpp @@ -3293,6 +3293,58 @@ cell AMX_NATIVE_CALL rg_player_relationship(AMX *amx, cell *params) return CSGameRules()->PlayerRelationship(pPlayer, pTarget); } +/* +* Sends death messages to all players, including info about the killer, victim, weapon used, +* extra death flags, death position, assistant, and kill rarity +* +* @param pKiller The entity who performed the kill (Note: The killer may be a non-player) +* @param pVictim The player who was killed +* @param pAssister The assisting player (if any) +* @param pevInflictor Inflictor entity. 0 = world +* @param killerWeaponName The name of the weapon used by the killer +* @param iDeathMessageFlags Flags indicating extra death message info +* @param iRarityOfKill An bitsums representing the rarity classification of the kill +* +* @noreturn +*/ +cell AMX_NATIVE_CALL rg_send_death_message(AMX *amx, cell *params) +{ + enum args_e { arg_count, arg_killer, arg_victim, arg_assister, arg_inflictor, arg_weaponname, arg_deathmsgflags, arg_rarityofkill }; + + CHECK_GAMERULES(); + + CHECK_ISPLAYER(arg_victim); + CBasePlayer *pVictim = UTIL_PlayerByIndex(params[arg_victim]); + CHECK_CONNECTED(pVictim, arg_victim); + + CBasePlayer *pKiller = nullptr; + CBasePlayer *pAssister = nullptr; + + // Check if the killer is a player + if (params[arg_killer]) + { + CHECK_ISPLAYER(arg_killer); + pKiller = UTIL_PlayerByIndex(params[arg_killer]); + CHECK_CONNECTED(pKiller, arg_killer); + } + + // Check if the assister is a player + if (params[arg_assister]) + { + CHECK_ISPLAYER(arg_assister); + pAssister = UTIL_PlayerByIndex(params[arg_assister]); + CHECK_CONNECTED(pAssister, arg_assister); + } + + CAmxArgs args(amx, params); + + char weaponStr[32]; + const char *weaponName = getAmxString(amx, params[arg_weaponname], weaponStr); + + CSGameRules()->SendDeathMessage(pKiller, pVictim, pAssister, args[arg_inflictor], weaponName, args[arg_deathmsgflags], args[arg_rarityofkill]); + return TRUE; +} + AMX_NATIVE_INFO Misc_Natives_RG[] = { { "rg_set_animation", rg_set_animation }, @@ -3406,6 +3458,8 @@ AMX_NATIVE_INFO Misc_Natives_RG[] = { "rg_death_notice", rg_death_notice }, { "rg_player_relationship", rg_player_relationship }, + { "rg_send_death_message", rg_send_death_message }, + { nullptr, nullptr } };