Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a new natives rg_spawn_head_gib and rg_spawn_random_gibs #200

Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions reapi/extra/amxmodx/scripting/include/reapi_gamedll.inc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
2 changes: 2 additions & 0 deletions reapi/include/cssdk/dlls/regamedll_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -626,6 +626,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 {
Expand Down
65 changes: 65 additions & 0 deletions reapi/src/natives/natives_misc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2365,6 +2365,68 @@ 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 };
CAmxArgs args(amx, params);

CHECK_ISENTITY(arg_index);

CBaseEntity *pEntity = getPrivate<CBaseEntity>(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 };
CAmxArgs args(amx, params);

CHECK_ISENTITY(arg_index);

CBaseEntity *pEntity = getPrivate<CBaseEntity>(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 },
Expand Down Expand Up @@ -2455,6 +2517,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 }
};

Expand Down