From d6af4d293979fe09b5f79a3020e42cba511bf66c Mon Sep 17 00:00:00 2001 From: FEDERICOMB <41979395+FEDERICOMB96@users.noreply.github.com> Date: Thu, 2 Sep 2021 12:55:40 -0300 Subject: [PATCH] Add a new natives `rg_spawn_head_gib` and `rg_spawn_random_gibs` (#200) * Add a new natives rg_spawn_head_gib and rg_spawn_random_gibs Add a new natives rg_spawn_head_gib and rg_spawn_random_gibs. rg_spawn_head_gib when called it will spawn a head gib. rg_spawn_random_gibs when called it will spawn random gibs. * Minor fix * remove CAmxArgs * newline fix in reapi_gamedll.inc Co-authored-by: Sergey Shorokhov --- .../scripting/include/reapi_gamedll.inc | 20 ++++++ reapi/include/cssdk/dlls/regamedll_api.h | 2 + reapi/src/natives/natives_misc.cpp | 63 +++++++++++++++++++ 3 files changed, 85 insertions(+) diff --git a/reapi/extra/amxmodx/scripting/include/reapi_gamedll.inc b/reapi/extra/amxmodx/scripting/include/reapi_gamedll.inc index 6248283..f6a581d 100644 --- a/reapi/extra/amxmodx/scripting/include/reapi_gamedll.inc +++ b/reapi/extra/amxmodx/scripting/include/reapi_gamedll.inc @@ -934,3 +934,23 @@ native rg_set_can_hear_player(const listener, const sender, const bool:can_hear) * @return boolean */ native bool:rg_get_can_hear_player(const listener, const sender); + +/* +* Spawn a head gib +* +* @param index Entity id +* +* @return Index of head gib entity or AMX_NULLENT (-1) otherwise +*/ +native rg_spawn_head_gib(const index); + +/* +* Spawn random gibs +* +* @param index Entity id +* @param cGibs Count gibs +* @param bHuman Set gibs of a human or alien +* +* @noreturn +*/ +native rg_spawn_random_gibs(const index, const cGibs, const bool:bHuman = true); diff --git a/reapi/include/cssdk/dlls/regamedll_api.h b/reapi/include/cssdk/dlls/regamedll_api.h index 541b918..53a6d66 100644 --- a/reapi/include/cssdk/dlls/regamedll_api.h +++ b/reapi/include/cssdk/dlls/regamedll_api.h @@ -669,6 +669,8 @@ struct ReGameFuncs_t { int (*Cmd_Argc)(); const char *(*Cmd_Argv)(int i); class CGrenade *(*PlantBomb)(entvars_t *pevOwner, Vector &vecStart, Vector &vecVelocity); + class CGib *(*SpawnHeadGib)(entvars_t *pevVictim); + void (*SpawnRandomGibs)(entvars_t *pevVictim, int cGibs, int human); }; class IReGameApi { diff --git a/reapi/src/natives/natives_misc.cpp b/reapi/src/natives/natives_misc.cpp index a626a22..2961081 100644 --- a/reapi/src/natives/natives_misc.cpp +++ b/reapi/src/natives/natives_misc.cpp @@ -2366,6 +2366,66 @@ cell AMX_NATIVE_CALL rg_get_can_hear_player(AMX* amx, cell* params) return CSGameRules()->m_VoiceGameMgr.m_pHelper->GetCanHearPlayer(pListener, pSender); } +/* +* Spawn a head gib +* +* @param index Entity id +* +* @return Index of head gib entity or AMX_NULLENT (-1) otherwise +* +* native rg_spawn_head_gib(const index); +*/ +cell AMX_NATIVE_CALL rg_spawn_head_gib(AMX* amx, cell* params) +{ + enum args_e { arg_count, arg_index }; + + CHECK_ISENTITY(arg_index); + + CBaseEntity *pEntity = getPrivate(params[arg_index]); + if (unlikely(pEntity == nullptr)) { + AMXX_LogError(amx, AMX_ERR_NATIVE, "%s: invalid or uninitialized entity", __FUNCTION__); + return FALSE; + } + + entvars_t *pevEntity = pEntity->pev; + CGib *pHeadGib = g_ReGameFuncs->SpawnHeadGib(pevEntity); + + // Sanity check anyway + if (pHeadGib) + return indexOfPDataAmx(pHeadGib); + + return AMX_NULLENT; +} + +/* +* Spawn random gibs +* +* @param index Entity id +* @param cGibs Count gibs +* @param bHuman Set gibs of a human or alien +* +* @noreturn +* +* native rg_spawn_random_gibs(const index, const cGibs, const bool:bHuman = true); +*/ +cell AMX_NATIVE_CALL rg_spawn_random_gibs(AMX* amx, cell* params) +{ + enum args_e { arg_count, arg_index, arg_gibs, arg_human }; + + CHECK_ISENTITY(arg_index); + + CBaseEntity *pEntity = getPrivate(params[arg_index]); + if (unlikely(pEntity == nullptr)) { + AMXX_LogError(amx, AMX_ERR_NATIVE, "%s: invalid or uninitialized entity", __FUNCTION__); + return FALSE; + } + + entvars_t *pevEntity = pEntity->pev; + + g_ReGameFuncs->SpawnRandomGibs(pevEntity, params[arg_gibs], params[arg_human]); + return TRUE; +} + AMX_NATIVE_INFO Misc_Natives_RG[] = { { "rg_set_animation", rg_set_animation }, @@ -2456,6 +2516,9 @@ AMX_NATIVE_INFO Misc_Natives_RG[] = { "rg_set_can_hear_player", rg_set_can_hear_player }, { "rg_get_can_hear_player", rg_get_can_hear_player }, + { "rg_spawn_head_gib", rg_spawn_head_gib }, + { "rg_spawn_random_gibs", rg_spawn_random_gibs }, + { nullptr, nullptr } };