extensions/sdktools/vnatives.cpp
changeset 1239 eed86aca8fae
parent 1233 e9cfc03b9bb8
child 1240 79eebacc9d02
     1.1 --- a/extensions/sdktools/vnatives.cpp	Wed Aug 01 06:30:38 2007 +0000
     1.2 +++ b/extensions/sdktools/vnatives.cpp	Wed Aug 01 06:55:55 2007 +0000
     1.3 @@ -564,6 +564,40 @@
     1.4  	return 1;
     1.5  }
     1.6  
     1.7 +static cell_t IsPlayerAlive(IPluginContext *pContext, const cell_t *params)
     1.8 +{
     1.9 +	IGamePlayer *player = playerhelpers->GetGamePlayer(params[1]);
    1.10 +	if (player == NULL)
    1.11 +	{
    1.12 +		return pContext->ThrowNativeError("Invalid client index %d", params[1]);
    1.13 +	} else if (!player->IsInGame())
    1.14 +	{
    1.15 +		return pContext->ThrowNativeError("Client %d is not in game", params[1]);
    1.16 +	}
    1.17 +
    1.18 +	edict_t *pEdict = player->GetEdict();
    1.19 +	CBaseEntity *pEntity = pEdict->GetUnknown()->GetBaseEntity();
    1.20 +
    1.21 +	static int lifeState_off = 0;
    1.22 +	static bool lifeState_setup = false;
    1.23 +
    1.24 +	if (!lifeState_setup)
    1.25 +	{
    1.26 +		lifeState_setup = true;
    1.27 +		g_pGameConf->GetOffset("m_lifeState", &lifeState_off);
    1.28 +	}
    1.29 +
    1.30 +	if (!lifeState_off)
    1.31 +	{
    1.32 +		IPlayerInfo *info = playerinfomngr->GetPlayerInfo(pEdict);
    1.33 +		if (info)
    1.34 +		{
    1.35 +			return info->IsDead() ? 0 : 1;
    1.36 +		}
    1.37 +	}
    1.38 +	return (*((uint8_t *)pEntity + lifeState_off) == LIFE_ALIVE) ? 1: 0;
    1.39 +}
    1.40 +
    1.41  sp_nativeinfo_t g_Natives[] = 
    1.42  {
    1.43  	{"ExtinguishPlayer",		ExtinguishPlayer},
    1.44 @@ -581,6 +615,6 @@
    1.45  	{"SlapPlayer",				SlapPlayer},
    1.46  	{"GetClientEyePosition",	GetClientEyePosition},
    1.47  	{"GetClientEyeAngles",		GetClientEyeAngles},
    1.48 +	{"IsPlayerAlive",			IsPlayerAlive},
    1.49  	{NULL,						NULL},
    1.50  };
    1.51 -