added a few new entity natives

--HG--
extra : convert_revision : svn%3A39bc706e-5318-0410-9160-8a85361fbb7c/trunk%40561
This commit is contained in:
David Anderson 2007-03-02 01:21:43 +00:00
parent 16eab8a091
commit a0ae2a5b16
2 changed files with 192 additions and 4 deletions

145
core/smn_entities.cpp Normal file
View File

@ -0,0 +1,145 @@
/**
* ===============================================================
* SourceMod (C)2004-2007 AlliedModders LLC. All rights reserved.
* ===============================================================
*
* This file is not open source and may not be copied without explicit
* written permission of AlliedModders LLC. This file may not be redistributed
* in whole or significant part.
* For information, see LICENSE.txt or http://www.sourcemod.net/license.php
*
* Version: $Id$
*/
#include "sm_globals.h"
#include "sourcemod.h"
#include "sourcemm_api.h"
inline edict_t *GetEdict(cell_t num)
{
edict_t *pEdict = engine->PEntityOfEntIndex(num);
if (!pEdict || pEdict->IsFree())
{
return NULL;
}
return pEdict;
}
static cell_t GetMaxEntities(IPluginContext *pContext, const cell_t *params)
{
return gpGlobals->maxEntities;
}
static cell_t CreateEdict(IPluginContext *pContext, const cell_t *params)
{
edict_t *pEdict = engine->CreateEdict();
if (!pEdict)
{
return 0;
}
return engine->IndexOfEdict(pEdict);
}
static cell_t RemoveEdict(IPluginContext *pContext, const cell_t *params)
{
edict_t *pEdict = engine->PEntityOfEntIndex(params[1]);
if (!pEdict)
{
return pContext->ThrowNativeError("Edict %d is not a valid edict", params[1]);
}
engine->RemoveEdict(pEdict);
return 1;
}
static cell_t IsValidEdict(IPluginContext *pContext, const cell_t *params)
{
edict_t *pEdict = engine->PEntityOfEntIndex(params[1]);
if (!pEdict)
{
return 0;
}
/* Shouldn't be necessary... not sure though */
return pEdict->IsFree() ? 0 : 1;
}
static cell_t IsValidEntity(IPluginContext *pContext, const cell_t *params)
{
edict_t *pEdict = engine->PEntityOfEntIndex(params[1]);
if (!pEdict || pEdict->IsFree())
{
return 0;
}
IServerUnknown *pUnknown = pEdict->GetUnknown();
if (!pUnknown)
{
return 0;
}
CBaseEntity *pEntity = pUnknown->GetBaseEntity();
return (pEntity != NULL) ? 1 : 0;
}
static cell_t IsEntNetworkable(IPluginContext *pContext, const cell_t *params)
{
edict_t *pEdict = engine->PEntityOfEntIndex(params[1]);
if (!pEdict || pEdict->IsFree())
{
return 0;
}
return (pEdict->GetNetworkable() != NULL) ? 1 : 0;
}
static cell_t GetEntityCount(IPluginContext *pContext, const cell_t *params)
{
return engine->GetEntityCount();
}
static cell_t GetEdictFlags(IPluginContext *pContext, const cell_t *params)
{
edict_t *pEdict = GetEdict(params[1]);
if (!pEdict)
{
return pContext->ThrowNativeError("Invalid edict (%d)", params[1]);
}
return pEdict->m_fStateFlags;
}
static cell_t SetEdictFlags(IPluginContext *pContext, const cell_t *params)
{
edict_t *pEdict = GetEdict(params[1]);
if (!pEdict)
{
return pContext->ThrowNativeError("Invalid edict (%d)", params[1]);
}
pEdict->m_fStateFlags = params[2];
return 1;
}
REGISTER_NATIVES(entityNatives)
{
{"CreateEdict", CreateEdict},
{"GetEdictFlags", GetEdictFlags},
{"GetEntityCount", GetEntityCount},
{"GetMaxEntities", GetMaxEntities},
{"IsEntNetworkable", IsEntNetworkable},
{"IsValidEdict", IsValidEdict},
{"IsValidEntity", IsValidEntity},
{"RemoveEdict", RemoveEdict},
{"SetEdictFlags", SetEdictFlags},
};

View File

@ -18,6 +18,22 @@
#endif
#define _entity_included
/**
* For more information on these, see the HL2SDK (public/edict.h)
*/
#define FL_EDICT_CHANGED (1<<0) /**< Game DLL sets this when the entity state changes
Mutually exclusive with FL_EDICT_PARTIAL_CHANGE. */
#define FL_EDICT_FREE (1<<1) /**< this edict if free for reuse */
#define FL_EDICT_FULL (1<<2) /**< this is a full server entity */
#define FL_EDICT_FULLCHECK (0<<0) /**< call ShouldTransmit() each time, this is a fake flag */
#define FL_EDICT_ALWAYS (1<<3) /**< always transmit this entity */
#define FL_EDICT_DONTSEND (1<<4) /**< don't transmit this entity */
#define FL_EDICT_PVSCHECK (1<<5) /**< always transmit entity, but cull against PVS */
#define FL_EDICT_PENDING_DORMANT_CHECK (1<<6)
#define FL_EDICT_DIRTY_PVS_INFORMATION (1<<7)
#define FL_FULL_EDICT_CHANGED (1<<8)
/**
* Returns the maximum number of entities.
*
@ -36,7 +52,7 @@ native GetEntityCount();
* Returns whether or not an entity is valid. Returns false
* if there is no matching CBaseEntity for this edict index.
*
* @param edict Index of the entity.
* @param edict Index of the entity/edict.
* @return True if valid, false otherwise.
*/
native bool:IsValidEntity(edict);
@ -49,18 +65,45 @@ native bool:IsValidEntity(edict);
*/
native bool:IsValidEdict(edict);
/**
* Returns whether or not an entity is a valid networkable edict.
*
* @param edict Index of the edict.
* @return True if networkable, false if invalid or not networkable.
*/
native bool:IsEntNetworkable(edict);
/**
* Creates a new edict (the basis of a networkable entity)
*
* @return Index of the entity, 0 on failure.
* @return Index of the edict, 0 on failure.
*/
native CreateEdict();
/**
* Removes an edict from the world.
*
* @param edict Index of the entity.
* @param edict Index of the edict.
* @noreturn
* @error Invalid entity index.
* @error Invalid edict index.
*/
native RemoveEdict(edict);
/**
* Returns the flags on an edict. These are not the same as entity flags.
*
* @param edict Index of the entity.
* @return Edict flags.
* @error Invalid edict index.
*/
native GetEdictFlags(edict);
/**
* Sets the flags on an edict. These are not the same as entity flags.
*
* @param edict Index of the entity.
* @param flags Flags to set.
* @noreturn
* @error Invalid edict index.
*/
native SetEdictFlags(edict, flags);