Implemented IsPlayerAlive native.
--HG-- extra : convert_revision : svn%3A39bc706e-5318-0410-9160-8a85361fbb7c/trunk%401245
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
@@ -45,6 +45,7 @@
|
||||
#include <IEngineTrace.h>
|
||||
#include <IEngineSound.h>
|
||||
#include <ivoiceserver.h>
|
||||
#include <iplayerinfo.h>
|
||||
#include <convar.h>
|
||||
|
||||
/**
|
||||
@@ -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;
|
||||
|
||||
@@ -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},
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user