Skip to content

Commit

Permalink
API: Implement RG_CSGameRules_SendDeathMessage hook and `rg_send_…
Browse files Browse the repository at this point in the history
…death_message` native (#305)

* `API`: Implement `RG_CSGameRules_SendDeathMessage` hook
* implement `rg_send_death_message` native
* Add new flag rarity of kill in-air
  • Loading branch information
FEDERICOMB96 authored May 9, 2024
1 parent 1dcc1ca commit d984502
Show file tree
Hide file tree
Showing 9 changed files with 127 additions and 2 deletions.
34 changes: 33 additions & 1 deletion reapi/extra/amxmodx/scripting/include/cssdk_const.inc
Original file line number Diff line number Diff line change
Expand Up @@ -1550,4 +1550,36 @@ enum
GR_ENEMY,
GR_ALLY,
GR_NEUTRAL,
};
};

// Flags for specifying extra info about player death
enum DeathMessageFlags
{
// float[3]
// Position where the victim was killed by the enemy
PLAYERDEATH_POSITION = 0x001,

// byte
// Index of the assistant who helped the attacker kill the victim
PLAYERDEATH_ASSISTANT = 0x002,

// short
// Bitsum classification for the rarity of the kill
// See enum KillRarity for details
PLAYERDEATH_KILLRARITY = 0x004
};

// Classifying various player kill methods in the game
enum KillRarity
{
KILLRARITY_HEADSHOT = 0x001, // Headshot
KILLRARITY_KILLER_BLIND = 0x002, // Killer was blind
KILLRARITY_NOSCOPE = 0x004, // No-scope sniper rifle kill
KILLRARITY_PENETRATED = 0x008, // Penetrated kill (through walls)
KILLRARITY_THRUSMOKE = 0x010, // Smoke grenade penetration kill (bullets went through smoke)
KILLRARITY_ASSISTEDFLASH = 0x020, // Assister helped with a flash
KILLRARITY_DOMINATION_BEGAN = 0x040, // Killer player began dominating the victim (NOTE: this flag is set once)
KILLRARITY_DOMINATION = 0x080, // Continues domination by the killer
KILLRARITY_REVENGE = 0x100, // Revenge by the killer
KILLRARITY_INAIR = 0x200 // Killer was in the air (skill to deal with high inaccuracy)
};
18 changes: 17 additions & 1 deletion reapi/extra/amxmodx/scripting/include/reapi_gamedll.inc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
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 using the CHalfLifeMultiplay::SendDeathMessage function.
*
* @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);
8 changes: 8 additions & 0 deletions reapi/extra/amxmodx/scripting/include/reapi_gamedll_const.inc
Original file line number Diff line number Diff line change
Expand Up @@ -1252,6 +1252,14 @@ enum GamedllFunc_CSGameRules
* Params: (const pPlayer, const pWeapon)
*/
RG_CSGameRules_PlayerGotWeapon,

/*
* Description: Called when a player is killed, sends death messages to all players, including info about the killer, victim, weapon used,
* extra death flags, death position, assistant, and kill rarity
* Return type: void
* Params: (const pKiller, const pVictim, const pAssister, const pevInflictor, const killerWeaponName[], const DeathMessageFlags:iDeathMessageFlags, const KillRarity:iRarityOfKill)
*/
RG_CSGameRules_SendDeathMessage,
};

/**
Expand Down
2 changes: 2 additions & 0 deletions reapi/include/cssdk/dlls/gamerules.h
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand Down
10 changes: 10 additions & 0 deletions reapi/src/hook_callback.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1740,6 +1740,16 @@ void CBasePlayer_RemoveAllItems(IReGameHook_CBasePlayer_RemoveAllItems *chain, C
callVoidForward(RG_CBasePlayer_RemoveAllItems, original, indexOfEdict(pthis->pev), removeSuit);
}

void CSGameRules_SendDeathMessage(IReGameHook_CSGameRules_SendDeathMessage *chain, CBaseEntity *pKiller, CBasePlayer *pVictim, CBasePlayer *pAssister, entvars_t *pevInflictor, const char *killerWeaponName, int iDeathMessageFlags, int iRarityOfKill)
{
auto original = [chain](int _pKiller, int _pVictim, int _pAssister, int _pevInflictor, const char *_killerWeaponName, int _iDeathMessageFlags, int _iRarityOfKill)
{
chain->callNext(getPrivate<CBaseEntity>(_pKiller), getPrivate<CBasePlayer>(_pVictim), getPrivate<CBasePlayer>(_pAssister), PEV(_pevInflictor), _killerWeaponName, _iDeathMessageFlags, _iRarityOfKill);
};

callVoidForward(RG_CSGameRules_SendDeathMessage, original, indexOfPDataAmx(pKiller), indexOfEdict(pVictim->pev), indexOfPDataAmx(pAssister), indexOfEdictAmx(pevInflictor), killerWeaponName, iDeathMessageFlags, iRarityOfKill);
}

/*
* VTC functions
*/
Expand Down
1 change: 1 addition & 0 deletions reapi/src/hook_callback.h
Original file line number Diff line number Diff line change
Expand Up @@ -561,6 +561,7 @@ void CBasePlayerWeapon_SendWeaponAnim(IReGameHook_CBasePlayerWeapon_SendWeaponAn
void CBasePlayer_PlayerDeathThink(IReGameHook_CBasePlayer_PlayerDeathThink *chain, CBasePlayer *pthis);
void CBasePlayer_Observer_Think(IReGameHook_CBasePlayer_Observer_Think *chain, CBasePlayer *pthis);
void CBasePlayer_RemoveAllItems(IReGameHook_CBasePlayer_RemoveAllItems *chain, CBasePlayer *pthis, BOOL removeSuit);
void CSGameRules_SendDeathMessage(IReGameHook_CSGameRules_SendDeathMessage *chain, CBaseEntity *pKiller, CBasePlayer *pVictim, CBasePlayer *pAssister, entvars_t *pevInflictor, const char *killerWeaponName, int iDeathMessageFlags, int iRarityOfKill);

/*
* VTC functions
Expand Down
1 change: 1 addition & 0 deletions reapi/src/hook_list.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,7 @@ hook_t hooklist_gamerules[] = {
DLL(CSGameRules_TeamFull),
DLL(CSGameRules_TeamStacked),
DLL(CSGameRules_PlayerGotWeapon),
DLL(CSGameRules_SendDeathMessage),
};

hook_t hooklist_grenade[] = {
Expand Down
1 change: 1 addition & 0 deletions reapi/src/hook_list.h
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,7 @@ enum GamedllFunc_CSGameRules
RG_CSGameRules_TeamFull,
RG_CSGameRules_TeamStacked,
RG_CSGameRules_PlayerGotWeapon,
RG_CSGameRules_SendDeathMessage,

// [...]
};
Expand Down
54 changes: 54 additions & 0 deletions reapi/src/natives/natives_misc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 using the CHalfLifeMultiplay::SendDeathMessage function.
*
* @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 },
Expand Down Expand Up @@ -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 }
};

Expand Down

0 comments on commit d984502

Please sign in to comment.