added amb844 - get_pdata_ent

This commit is contained in:
David Anderson 2007-10-22 19:52:06 +00:00
parent ca3d15c27e
commit b7f8503655
2 changed files with 51 additions and 1 deletions

View File

@ -143,12 +143,48 @@ static cell AMX_NATIVE_CALL set_pdata_string(AMX *amx, cell *params)
return 1; return 1;
} }
AMX_NATIVE_INFO pdata_natives[] = { static cell AMX_NATIVE_CALL get_pdata_ent(AMX *amx, cell *params)
{
int index=params[1];
int iOffset=params[2];
CHECK_ENTITY(index);
#ifdef __linux__
iOffset += params[3];
#endif
edict_t *pEdict = *(edict_t **)((char *)(INDEXENT2(index)->pvPrivateData) + iOffset);
if (pEdict == NULL)
{
return -1;
}
edict_t *pWorld = INDEXENT(0);
int ent = pEdict - pWorld;
if (ent < 0 || ent > gpGlobals->maxEntities)
{
return -2;
}
if (pEdict->free || pEdict->pvPrivateData == NULL)
{
return -1;
}
return ent;
}
AMX_NATIVE_INFO pdata_natives[] =
{
{ "get_pdata_int", get_pdata_int }, { "get_pdata_int", get_pdata_int },
{ "set_pdata_int", set_pdata_int }, { "set_pdata_int", set_pdata_int },
{ "get_pdata_float", get_pdata_float }, { "get_pdata_float", get_pdata_float },
{ "set_pdata_float", set_pdata_float }, { "set_pdata_float", set_pdata_float },
{ "set_pdata_string", set_pdata_string }, { "set_pdata_string", set_pdata_string },
{ "get_pdata_string", get_pdata_string }, { "get_pdata_string", get_pdata_string },
{ "get_pdata_ent", get_pdata_ent },
{ NULL, NULL } { NULL, NULL }
}; };

View File

@ -110,6 +110,20 @@ native Float:get_pdata_float(_index,_Offset,_linuxdiff=5);
/* Sets a float from private data. _linuxdiff is added into the _Offset if it's used on a linux server. */ /* Sets a float from private data. _linuxdiff is added into the _Offset if it's used on a linux server. */
native set_pdata_float(_index,_Offset,Float:_Value,_linuxdiff=5); native set_pdata_float(_index,_Offset,Float:_Value,_linuxdiff=5);
/**
* Tries to retrieve an edict (entity encapsulation) pointer from an entity's private data.
*
* This function is byte-addressable. Unlike get_pdata_int() which searches in byte increments of 4,
* get_pdata_end searches in increments of 1.
*
* @param _index Entity index.
* @param _offset Offset to search.
* @param _linuxdiff Linux difference.
* @return -2 if an invalid entity was found.
* -1 if an empty entity was found.
* Otherwise, an entity index is returned.
*/
native get_pdata_ent(_index, _offset, _linuxdiff=20);
/* Registers a forward. /* Registers a forward.
* Returns an id you can pass to unregister_forward * Returns an id you can pass to unregister_forward