diff --git a/modules/cstrike/cstrike/CstrikeNatives.cpp b/modules/cstrike/cstrike/CstrikeNatives.cpp index 171a417b..fd43cb86 100644 --- a/modules/cstrike/cstrike/CstrikeNatives.cpp +++ b/modules/cstrike/cstrike/CstrikeNatives.cpp @@ -127,11 +127,7 @@ static cell AMX_NATIVE_CALL cs_get_hostage_id(AMX *amx, cell *params) CHECK_NONPLAYER(index); edict_t *pHostage = INDEXENT(index); - if (strcmp(STRING(pHostage->v.classname), "hostage_entity") != 0) - { - MF_LogError(amx, AMX_ERR_NATIVE, "Entity %d (\"%s\") is not a hostage", index, STRING(pHostage->v.classname)); - return 0; - } + CHECK_HOSTAGE(pHostage); return get_pdata(pHostage, m_iHostageIndex); } @@ -860,11 +856,7 @@ static cell AMX_NATIVE_CALL cs_get_hostage_follow(AMX *amx, cell *params) CHECK_NONPLAYER(index); edict_t* pHostage = INDEXENT(index); - if (strcmp(STRING(pHostage->v.classname), "hostage_entity") != 0) - { - MF_LogError(amx, AMX_ERR_NATIVE, "Entity %d (\"%s\") is not a hostage", index, STRING(pHostage->v.classname)); - return 0; - } + CHECK_HOSTAGE(pHostage); edict_t *pEntity = get_pdata(pHostage, m_hTargetEnt).Get(); @@ -887,11 +879,7 @@ static cell AMX_NATIVE_CALL cs_set_hostage_follow(AMX *amx, cell *params) CHECK_ENTITY(target); } - if (strcmp(STRING(pHostage->v.classname), "hostage_entity") != 0) - { - MF_LogError(amx, AMX_ERR_NATIVE, "Entity %d (\"%s\") is not a hostage", index, STRING(pHostage->v.classname)); - return 0; - } + CHECK_HOSTAGE(pHostage); get_pdata(pHostage, m_hTargetEnt).Set(target ? GETEDICT(target) : nullptr); @@ -1383,11 +1371,7 @@ static cell AMX_NATIVE_CALL cs_get_hostage_lastuse(AMX *amx, cell *params) CHECK_NONPLAYER(index); edict_t *pHostage = INDEXENT(index); - if (strcmp(STRING(pHostage->v.classname), "hostage_entity") != 0) - { - MF_LogError(amx, AMX_ERR_NATIVE, "Entity %d (\"%s\") is not a hostage", index, STRING(pHostage->v.classname)); - return 0; - } + CHECK_HOSTAGE(pHostage); return amx_ftoc(get_pdata(pHostage, m_flPathAcquired)); } @@ -1402,11 +1386,7 @@ static cell AMX_NATIVE_CALL cs_set_hostage_lastuse(AMX *amx, cell *params) CHECK_NONPLAYER(index); edict_t *pHostage = INDEXENT(index); - if (strcmp(STRING(pHostage->v.classname), "hostage_entity") != 0) - { - MF_LogError(amx, AMX_ERR_NATIVE, "Entity %d (\"%s\") is not a hostage", index, STRING(pHostage->v.classname)); - return 0; - } + CHECK_HOSTAGE(pHostage); set_pdata(pHostage, m_flPathAcquired, amx_ctof(params[2])); @@ -1423,11 +1403,7 @@ static cell AMX_NATIVE_CALL cs_get_hostage_nextuse(AMX* amx, cell* params) CHECK_NONPLAYER(index); edict_t *pHostage = INDEXENT(index); - if (strcmp(STRING(pHostage->v.classname), "hostage_entity") != 0) - { - MF_LogError(amx, AMX_ERR_NATIVE, "Entity %d (\"%s\") is not a hostage", index, STRING(pHostage->v.classname)); - return 0; - } + CHECK_HOSTAGE(pHostage); return amx_ftoc(get_pdata(pHostage, m_flNextChange)); } @@ -1442,11 +1418,7 @@ static cell AMX_NATIVE_CALL cs_set_hostage_nextuse(AMX* amx, cell* params) CHECK_NONPLAYER(index); edict_t *pHostage = INDEXENT(index); - if (strcmp(STRING(pHostage->v.classname), "hostage_entity") != 0) - { - MF_LogError(amx, AMX_ERR_NATIVE, "Entity %d (\"%s\") is not a hostage", index, STRING(pHostage->v.classname)); - return 0; - } + CHECK_HOSTAGE(pHostage); set_pdata(pHostage, m_flNextChange, amx_ctof(params[2])); diff --git a/modules/cstrike/cstrike/CstrikeUtils.h b/modules/cstrike/cstrike/CstrikeUtils.h index 18ae43f7..7275cf3e 100644 --- a/modules/cstrike/cstrike/CstrikeUtils.h +++ b/modules/cstrike/cstrike/CstrikeUtils.h @@ -63,6 +63,13 @@ bool UTIL_CheckForPublic(const char *publicname); } \ } +#define CHECK_HOSTAGE(x) \ + if (strcmp(STRING(x->v.classname), "hostage_entity") != 0 && strcmp(STRING(x->v.classname), "monster_scientist") != 0) \ + { \ + MF_LogError(amx, AMX_ERR_NATIVE, "Entity %d (\"%s\") is not a hostage", index, STRING(x->v.classname)); \ + return 0; \ + } + #define GETEDICT(n) \ ((n >= 1 && n <= gpGlobals->maxClients) ? MF_GetPlayerEdict(n) : INDEXENT(n))