Engine: Add safe get_global_edict2() and entity_get_edict2()
This commit is contained in:
parent
d69fddf8b4
commit
add4867d21
|
@ -1057,7 +1057,7 @@ static cell AMX_NATIVE_CALL entity_set_string(AMX *amx, cell *params)
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static cell AMX_NATIVE_CALL entity_get_edict(AMX *amx, cell *params)
|
static cell AMX_NATIVE_CALL entity_get_edict2(AMX *amx, cell *params)
|
||||||
{
|
{
|
||||||
int iEnt = params[1];
|
int iEnt = params[1];
|
||||||
int idx = params[2];
|
int idx = params[2];
|
||||||
|
@ -1103,16 +1103,26 @@ static cell AMX_NATIVE_CALL entity_get_edict(AMX *amx, cell *params)
|
||||||
pRet = pEnt->v.euser4;
|
pRet = pEnt->v.euser4;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
return 0;
|
return -1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (FNullEnt(pRet))
|
if (FNullEnt(pRet))
|
||||||
return 0;
|
return -1;
|
||||||
|
|
||||||
return ENTINDEX(pRet);
|
return ENTINDEX(pRet);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static cell AMX_NATIVE_CALL entity_get_edict(AMX *amx, cell *params)
|
||||||
|
{
|
||||||
|
cell res = entity_get_edict2(amx, params);
|
||||||
|
|
||||||
|
if (res == -1)
|
||||||
|
res = 0;
|
||||||
|
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
static cell AMX_NATIVE_CALL entity_set_edict(AMX *amx, cell *params)
|
static cell AMX_NATIVE_CALL entity_set_edict(AMX *amx, cell *params)
|
||||||
{
|
{
|
||||||
int iEnt = params[1];
|
int iEnt = params[1];
|
||||||
|
@ -1602,6 +1612,7 @@ AMX_NATIVE_INFO ent_Natives[] = {
|
||||||
{"entity_get_string", entity_get_string},
|
{"entity_get_string", entity_get_string},
|
||||||
{"entity_set_string", entity_set_string},
|
{"entity_set_string", entity_set_string},
|
||||||
{"entity_get_edict", entity_get_edict},
|
{"entity_get_edict", entity_get_edict},
|
||||||
|
{"entity_get_edict2", entity_get_edict2},
|
||||||
{"entity_set_edict", entity_set_edict},
|
{"entity_set_edict", entity_set_edict},
|
||||||
{"entity_get_byte", entity_get_byte},
|
{"entity_get_byte", entity_get_byte},
|
||||||
{"entity_set_byte", entity_set_byte},
|
{"entity_set_byte", entity_set_byte},
|
||||||
|
|
|
@ -157,7 +157,7 @@ static cell AMX_NATIVE_CALL get_global_vector(AMX *amx, cell *params) // globals
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static cell AMX_NATIVE_CALL get_global_edict(AMX *amx, cell *params) // globals_get_edict(variable); = 1 param
|
static cell AMX_NATIVE_CALL get_global_edict2(AMX *amx, cell *params)
|
||||||
{
|
{
|
||||||
edict_t* pReturnEntity;
|
edict_t* pReturnEntity;
|
||||||
|
|
||||||
|
@ -167,14 +167,24 @@ static cell AMX_NATIVE_CALL get_global_edict(AMX *amx, cell *params) // globals_
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
MF_LogError(amx, AMX_ERR_NATIVE, "Undefined global_edict index %d", params[1]);
|
MF_LogError(amx, AMX_ERR_NATIVE, "Undefined global_edict index %d", params[1]);
|
||||||
return 0;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Will crash if ENTINDEX() is called on bad pointer?
|
// Will crash if ENTINDEX() is called on bad pointer?
|
||||||
if(!FNullEnt(pReturnEntity))
|
if(!FNullEnt(pReturnEntity))
|
||||||
return ENTINDEX(pReturnEntity);
|
return ENTINDEX(pReturnEntity);
|
||||||
|
|
||||||
return 0;
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
static cell AMX_NATIVE_CALL get_global_edict(AMX *amx, cell *params) // globals_get_edict(variable); = 1 param
|
||||||
|
{
|
||||||
|
cell res = get_global_edict2(amx, params);
|
||||||
|
|
||||||
|
if (res == -1)
|
||||||
|
res = 0;
|
||||||
|
|
||||||
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
AMX_NATIVE_INFO global_Natives[] = {
|
AMX_NATIVE_INFO global_Natives[] = {
|
||||||
|
@ -182,6 +192,7 @@ AMX_NATIVE_INFO global_Natives[] = {
|
||||||
{"get_global_int", get_global_int},
|
{"get_global_int", get_global_int},
|
||||||
{"get_global_string", get_global_string},
|
{"get_global_string", get_global_string},
|
||||||
{"get_global_edict", get_global_edict},
|
{"get_global_edict", get_global_edict},
|
||||||
|
{"get_global_edict2", get_global_edict2},
|
||||||
{"get_global_vector", get_global_vector},
|
{"get_global_vector", get_global_vector},
|
||||||
{NULL, NULL},
|
{NULL, NULL},
|
||||||
///////////////////
|
///////////////////
|
||||||
|
|
|
@ -306,6 +306,21 @@ native get_global_vector(variable, Float:vector[3]);
|
||||||
*/
|
*/
|
||||||
native get_global_edict(variable);
|
native get_global_edict(variable);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a edict type value from the server globals.
|
||||||
|
*
|
||||||
|
* @note For a list of valid edict type entries, see the GL_* constants in
|
||||||
|
* engine_const.inc under the "Edict" section.
|
||||||
|
* @note This native returns -1 as a safe error value if the edict retrieved is
|
||||||
|
* an invalid entity. Otherwise it is identical to get_global_edict().
|
||||||
|
*
|
||||||
|
* @param variable Entry to retrieve from
|
||||||
|
*
|
||||||
|
* @return Value of specified entry
|
||||||
|
* @error If an invalid entry is provided, an error will be thrown.
|
||||||
|
*/
|
||||||
|
native get_global_edict2(variable);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the size of the entity bounding box, as described by the minimum and
|
* Sets the size of the entity bounding box, as described by the minimum and
|
||||||
* maximum vectors relative to the origin.
|
* maximum vectors relative to the origin.
|
||||||
|
@ -476,6 +491,26 @@ native entity_set_vector(iIndex, iKey, const Float:vNewVector[3]);
|
||||||
*/
|
*/
|
||||||
native entity_get_edict(iIndex, iKey);
|
native entity_get_edict(iIndex, iKey);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns an edict type value from an entities entvar struct.
|
||||||
|
*
|
||||||
|
* @note For a list of valid edict type entries, see the EV_ENT_* constants in
|
||||||
|
* engine_const.inc
|
||||||
|
* @note This native returns -1 as a safe error value if the edict retrieved
|
||||||
|
* from the entvar is an invalid entity. Otherwise it is identical to
|
||||||
|
* entity_get_edict().
|
||||||
|
*
|
||||||
|
* @param iIndex Entity index
|
||||||
|
* @param iKey Entry to retrieve from
|
||||||
|
*
|
||||||
|
* @return Entity index in specified entry, -1 if the edict in the
|
||||||
|
* entvar is not a valid entity or an invalid entry was
|
||||||
|
* specified
|
||||||
|
* @error If an invalid entity index is provided, an error will be
|
||||||
|
* thrown.
|
||||||
|
*/
|
||||||
|
native entity_get_edict2(iIndex, iKey);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets an edict type value in an entities entvar struct.
|
* Sets an edict type value in an entities entvar struct.
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in New Issue
Block a user