fixed some bugs with edicts and players
added classname retrieval functions --HG-- extra : convert_revision : svn%3A39bc706e-5318-0410-9160-8a85361fbb7c/trunk%40562
This commit is contained in:
		
							parent
							
								
									a0ae2a5b16
								
							
						
					
					
						commit
						bbb373297f
					
				@ -14,6 +14,8 @@
 | 
			
		||||
#include "sm_globals.h"
 | 
			
		||||
#include "sourcemod.h"
 | 
			
		||||
#include "sourcemm_api.h"
 | 
			
		||||
#include "server_class.h"
 | 
			
		||||
#include "CPlayerManager.h"
 | 
			
		||||
 | 
			
		||||
inline edict_t *GetEdict(cell_t num)
 | 
			
		||||
{
 | 
			
		||||
@ -22,6 +24,14 @@ inline edict_t *GetEdict(cell_t num)
 | 
			
		||||
	{
 | 
			
		||||
		return NULL;
 | 
			
		||||
	}
 | 
			
		||||
	if (num > 0 && num < g_Players.GetMaxClients())
 | 
			
		||||
	{
 | 
			
		||||
		CPlayer *pPlayer = g_Players.GetPlayerByIndex(num);
 | 
			
		||||
		if (!pPlayer || !pPlayer->IsConnected())
 | 
			
		||||
		{
 | 
			
		||||
			return NULL;
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
	return pEdict;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -58,7 +68,7 @@ static cell_t RemoveEdict(IPluginContext *pContext, const cell_t *params)
 | 
			
		||||
 | 
			
		||||
static cell_t IsValidEdict(IPluginContext *pContext, const cell_t *params)
 | 
			
		||||
{
 | 
			
		||||
	edict_t *pEdict = engine->PEntityOfEntIndex(params[1]);
 | 
			
		||||
	edict_t *pEdict = GetEdict(params[1]);
 | 
			
		||||
 | 
			
		||||
	if (!pEdict)
 | 
			
		||||
	{
 | 
			
		||||
@ -71,9 +81,9 @@ static cell_t IsValidEdict(IPluginContext *pContext, const cell_t *params)
 | 
			
		||||
 | 
			
		||||
static cell_t IsValidEntity(IPluginContext *pContext, const cell_t *params)
 | 
			
		||||
{
 | 
			
		||||
	edict_t *pEdict = engine->PEntityOfEntIndex(params[1]);
 | 
			
		||||
	edict_t *pEdict = GetEdict(params[1]);
 | 
			
		||||
 | 
			
		||||
	if (!pEdict || pEdict->IsFree())
 | 
			
		||||
	if (!pEdict)
 | 
			
		||||
	{
 | 
			
		||||
		return 0;
 | 
			
		||||
	}
 | 
			
		||||
@ -90,9 +100,9 @@ static cell_t IsValidEntity(IPluginContext *pContext, const cell_t *params)
 | 
			
		||||
 | 
			
		||||
static cell_t IsEntNetworkable(IPluginContext *pContext, const cell_t *params)
 | 
			
		||||
{
 | 
			
		||||
	edict_t *pEdict = engine->PEntityOfEntIndex(params[1]);
 | 
			
		||||
	edict_t *pEdict = GetEdict(params[1]);
 | 
			
		||||
 | 
			
		||||
	if (!pEdict || pEdict->IsFree())
 | 
			
		||||
	if (!pEdict)
 | 
			
		||||
	{
 | 
			
		||||
		return 0;
 | 
			
		||||
	}
 | 
			
		||||
@ -131,11 +141,55 @@ static cell_t SetEdictFlags(IPluginContext *pContext, const cell_t *params)
 | 
			
		||||
	return 1;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static cell_t GetEdictClassname(IPluginContext *pContext, const cell_t *params)
 | 
			
		||||
{
 | 
			
		||||
	edict_t *pEdict = GetEdict(params[1]);
 | 
			
		||||
 | 
			
		||||
	if (!pEdict)
 | 
			
		||||
	{
 | 
			
		||||
		return pContext->ThrowNativeError("Invalid edict (%d)", params[1]);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	const char *cls = pEdict->GetClassName();
 | 
			
		||||
 | 
			
		||||
	if (!cls || cls[0] == '\0')
 | 
			
		||||
	{
 | 
			
		||||
		return 0;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	pContext->StringToLocal(params[2], params[3], cls);
 | 
			
		||||
 | 
			
		||||
	return 1;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static cell_t GetEntityNetClass(IPluginContext *pContext, const cell_t *params)
 | 
			
		||||
{
 | 
			
		||||
	edict_t *pEdict = GetEdict(params[1]);
 | 
			
		||||
 | 
			
		||||
	if (!pEdict)
 | 
			
		||||
	{
 | 
			
		||||
		return pContext->ThrowNativeError("Invalid edict (%d)", params[1]);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	IServerNetworkable *pNet = pEdict->GetNetworkable();
 | 
			
		||||
	if (!pNet)
 | 
			
		||||
	{
 | 
			
		||||
		return 0;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	ServerClass *pClass = pNet->GetServerClass();
 | 
			
		||||
 | 
			
		||||
	pContext->StringToLocal(params[2], params[3], pClass->GetName());
 | 
			
		||||
 | 
			
		||||
	return 1;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
REGISTER_NATIVES(entityNatives)
 | 
			
		||||
{
 | 
			
		||||
	{"CreateEdict",				CreateEdict},
 | 
			
		||||
	{"GetEdictClassname",		GetEdictClassname},
 | 
			
		||||
	{"GetEdictFlags",			GetEdictFlags},
 | 
			
		||||
	{"GetEntityCount",			GetEntityCount},
 | 
			
		||||
	{"GetEntityNetClass",		GetEntityNetClass},
 | 
			
		||||
	{"GetMaxEntities",			GetMaxEntities},
 | 
			
		||||
	{"IsEntNetworkable",		IsEntNetworkable},
 | 
			
		||||
	{"IsValidEdict",			IsValidEdict},
 | 
			
		||||
 | 
			
		||||
@ -107,3 +107,25 @@ native GetEdictFlags(edict);
 | 
			
		||||
 * @error				Invalid edict index.
 | 
			
		||||
 */
 | 
			
		||||
native SetEdictFlags(edict, flags);
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Retrieves an edict classname.
 | 
			
		||||
 *
 | 
			
		||||
 * @param edict			Index of the entity.
 | 
			
		||||
 * @param clsname		Buffer to store the classname.
 | 
			
		||||
 * @param maxlength		Maximum length of the buffer.
 | 
			
		||||
 * @return				True on success, false if there is no classname set.
 | 
			
		||||
 */
 | 
			
		||||
native bool:GetEdictClassname(edict, String:clsname[], maxlength);
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Retrieves an entity's networkable serverclass name.
 | 
			
		||||
 * This is not the same as the classname and is used for networkable state changes.
 | 
			
		||||
 *
 | 
			
		||||
 * @param edict			Index of the entity.
 | 
			
		||||
 * @param clsname		Buffer to store the serverclass name.
 | 
			
		||||
 * @param maxlength		Maximum lnegth of the buffer.
 | 
			
		||||
 * @return				True on success, false if the edict is not networkable.
 | 
			
		||||
 * @error				Invalid edict index.
 | 
			
		||||
 */
 | 
			
		||||
native bool:GetEntityNetClass(edict, String:clsname[], maxlength);
 | 
			
		||||
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user