diff --git a/extensions/sdktools/extension.cpp b/extensions/sdktools/extension.cpp index 03fbbee0..ea11b22c 100644 --- a/extensions/sdktools/extension.cpp +++ b/extensions/sdktools/extension.cpp @@ -52,6 +52,7 @@ IBinTools *g_pBinTools = NULL; IGameConfig *g_pGameConf = NULL; IGameHelpers *g_pGameHelpers = NULL; IServerGameClients *serverClients = NULL; +IPlayerInfoManager *playerinfomngr = NULL; HandleType_t g_CallHandle = 0; HandleType_t g_TraceHandle = 0; IVoiceServer *voiceserver = NULL; @@ -132,6 +133,7 @@ bool SDKTools::SDK_OnMetamodLoad(ISmmAPI *ismm, char *error, size_t maxlen, bool GET_V_IFACE_ANY(engineFactory, pluginhelpers, IServerPluginHelpers, INTERFACEVERSION_ISERVERPLUGINHELPERS); GET_V_IFACE_ANY(serverFactory, serverClients, IServerGameClients, INTERFACEVERSION_SERVERGAMECLIENTS); GET_V_IFACE_ANY(engineFactory, voiceserver, IVoiceServer, INTERFACEVERSION_VOICESERVER); + GET_V_IFACE_ANY(serverFactory, playerinfomngr, IPlayerInfoManager, INTERFACEVERSION_PLAYERINFOMANAGER); return true; } diff --git a/extensions/sdktools/extension.h b/extensions/sdktools/extension.h index 43438806..88b51567 100644 --- a/extensions/sdktools/extension.h +++ b/extensions/sdktools/extension.h @@ -45,6 +45,7 @@ #include #include #include +#include #include /** @@ -90,6 +91,7 @@ extern INetworkStringTableContainer *netstringtables; extern IServerPluginHelpers *pluginhelpers; extern IServerGameClients *serverClients; extern IVoiceServer *voiceserver; +extern IPlayerInfoManager *playerinfomngr; /* Interfaces from SourceMod */ extern IBinTools *g_pBinTools; extern IGameConfig *g_pGameConf; diff --git a/extensions/sdktools/vnatives.cpp b/extensions/sdktools/vnatives.cpp index 9176656f..13e3e277 100644 --- a/extensions/sdktools/vnatives.cpp +++ b/extensions/sdktools/vnatives.cpp @@ -564,6 +564,40 @@ static cell_t GetClientEyeAngles(IPluginContext *pContext, const cell_t *params) return 1; } +static cell_t IsPlayerAlive(IPluginContext *pContext, const cell_t *params) +{ + IGamePlayer *player = playerhelpers->GetGamePlayer(params[1]); + if (player == NULL) + { + return pContext->ThrowNativeError("Invalid client index %d", params[1]); + } else if (!player->IsInGame()) + { + return pContext->ThrowNativeError("Client %d is not in game", params[1]); + } + + edict_t *pEdict = player->GetEdict(); + CBaseEntity *pEntity = pEdict->GetUnknown()->GetBaseEntity(); + + static int lifeState_off = 0; + static bool lifeState_setup = false; + + if (!lifeState_setup) + { + lifeState_setup = true; + g_pGameConf->GetOffset("m_lifeState", &lifeState_off); + } + + if (!lifeState_off) + { + IPlayerInfo *info = playerinfomngr->GetPlayerInfo(pEdict); + if (info) + { + return info->IsDead() ? 0 : 1; + } + } + return (*((uint8_t *)pEntity + lifeState_off) == LIFE_ALIVE) ? 1: 0; +} + sp_nativeinfo_t g_Natives[] = { {"ExtinguishPlayer", ExtinguishPlayer}, @@ -581,6 +615,6 @@ sp_nativeinfo_t g_Natives[] = {"SlapPlayer", SlapPlayer}, {"GetClientEyePosition", GetClientEyePosition}, {"GetClientEyeAngles", GetClientEyeAngles}, + {"IsPlayerAlive", IsPlayerAlive}, {NULL, NULL}, }; - diff --git a/gamedata/sdktools.games.txt b/gamedata/sdktools.games.txt index ea67a80d..81cc68f9 100644 --- a/gamedata/sdktools.games.txt +++ b/gamedata/sdktools.games.txt @@ -18,6 +18,11 @@ "class" "CBasePlayer" "prop" "m_iHealth" } + "m_lifeState" + { + "class" "CBasePlayer" + "prop" "m_lifeState" + } } } diff --git a/plugins/include/sdktools_functions.inc b/plugins/include/sdktools_functions.inc index 716eb9b0..6f2b8c55 100644 --- a/plugins/include/sdktools_functions.inc +++ b/plugins/include/sdktools_functions.inc @@ -114,6 +114,15 @@ native SlapPlayer(client, health=5, bool:sound=true); */ native GetClientEyeAngles(client, Float:ang[3]); +/** + * Returns if the client is alive or dead. + * + * @param client Player's index. + * @return True if the client is dead, false otherwise. + * @error Invalid client index, client not in game, or no mod support. + */ +native bool:IsPlayerAlive(client); + /** * @deprecated */