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:
David Anderson
2007-03-02 01:56:56 +00:00
parent a0ae2a5b16
commit bbb373297f
2 changed files with 83 additions and 7 deletions
+60 -6
View File
@@ -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},