From e1eac93aabb9aba503d307ef617e82ac1370561c Mon Sep 17 00:00:00 2001 From: s1lent Date: Tue, 13 Jun 2017 19:10:04 +0700 Subject: [PATCH] Add native GetGrenadeType --- .../extra/amxmodx/scripting/include/reapi.inc | 11 +++++- .../scripting/include/reapi_addons.inc | 2 + .../scripting/include/reapi_engine.inc | 2 +- reapi/src/natives/natives_common.cpp | 38 +++++++++++++++++++ reapi/src/type_conversion.h | 9 +++++ 5 files changed, 60 insertions(+), 2 deletions(-) diff --git a/reapi/extra/amxmodx/scripting/include/reapi.inc b/reapi/extra/amxmodx/scripting/include/reapi.inc index b3297a6..44e925c 100644 --- a/reapi/extra/amxmodx/scripting/include/reapi.inc +++ b/reapi/extra/amxmodx/scripting/include/reapi.inc @@ -152,6 +152,15 @@ native SetHookChainArg(number, AType:type, any:...); */ native bool:FClassnameIs(const entityIndex, const className[]); +/* +* To get WeaponIdType from grenade entity +* +* @param entity Grenade entity +* +* @return return enum's of WeaponIdType +*/ +native WeaponIdType:GetGrenadeType(const entityIndex); + /* * Check if the entity is valid. * @@ -214,4 +223,4 @@ public __reapi_version_check(const majorVersion, const minorVersion) set_fail_state(temp); return; } -} \ No newline at end of file +} diff --git a/reapi/extra/amxmodx/scripting/include/reapi_addons.inc b/reapi/extra/amxmodx/scripting/include/reapi_addons.inc index 7d9ffe9..e4dde5c 100644 --- a/reapi/extra/amxmodx/scripting/include/reapi_addons.inc +++ b/reapi/extra/amxmodx/scripting/include/reapi_addons.inc @@ -19,6 +19,8 @@ enum client_auth_type CA_TYPE_SSE3, }; +#define is_user_steam(%0) (REU_GetAuthtype(%0) == CA_TYPE_STEAM) + /* * Checks whether the player is talking at the moment. * diff --git a/reapi/extra/amxmodx/scripting/include/reapi_engine.inc b/reapi/extra/amxmodx/scripting/include/reapi_engine.inc index 4c874e9..803bf30 100644 --- a/reapi/extra/amxmodx/scripting/include/reapi_engine.inc +++ b/reapi/extra/amxmodx/scripting/include/reapi_engine.inc @@ -87,4 +87,4 @@ native bool:rh_emit_sound2(const entity, const recipient, const channel, const s * * @noreturn */ -native rh_update_user_info(playerEntIndex); \ No newline at end of file +native rh_update_user_info(playerEntIndex); diff --git a/reapi/src/natives/natives_common.cpp b/reapi/src/natives/natives_common.cpp index 917f5fd..27da50a 100644 --- a/reapi/src/natives/natives_common.cpp +++ b/reapi/src/natives/natives_common.cpp @@ -25,9 +25,47 @@ cell AMX_NATIVE_CALL amx_FClassnameIs(AMX *amx, cell *params) return FALSE; } +/* +* To get WeaponIdType from grenade entity +* +* @param entity Grenade entity +* +* @return return enum's of WeaponIdType +* +* native WeaponIdType:GetGrenadeType(const entityIndex); +*/ +cell AMX_NATIVE_CALL amx_GetGrenadeType(AMX *amx, cell *params) +{ + enum args_e { arg_count, arg_index }; + + CHECK_ISENTITY(arg_index); + + edict_t *pEdict = edictByIndex(params[arg_index]); + if (!pEdict || !FClassnameIs(pEdict, "grenade")) { + return WEAPON_NONE; + } + + CGrenade *pGrenade = getPrivate(pEdict); + if (!pGrenade) { + return WEAPON_NONE; + } + + if (pGrenade->m_bIsC4) { + return WEAPON_C4; + } + + static unsigned short usCreateExplosion = 0; + if (!usCreateExplosion) { + usCreateExplosion = PRECACHE_EVENT(1, "events/createexplo.sc"); + } + + return (pGrenade->m_usEvent == usCreateExplosion) ? WEAPON_HEGRENADE : WEAPON_SMOKEGRENADE; +} + AMX_NATIVE_INFO Natives_Common[] = { { "FClassnameIs", amx_FClassnameIs }, + { "GetGrenadeType", amx_GetGrenadeType }, { nullptr, nullptr } }; diff --git a/reapi/src/type_conversion.h b/reapi/src/type_conversion.h index 5ec8993..7d9eb87 100644 --- a/reapi/src/type_conversion.h +++ b/reapi/src/type_conversion.h @@ -49,6 +49,15 @@ inline T* getPrivate(int index) return pdata; } +template +inline T* getPrivate(edict_t *pEdict) +{ + T* pdata = nullptr; + if (likely(pEdict != nullptr)) + pdata = (T *)pEdict->pvPrivateData; + return pdata; +} + inline entvars_t* PEV(int index) { entvars_t* pvars = nullptr;