There's a lot of informations about how natives looks like inside github. The
engine.cpp is the one that you should search about.
Code:
static cell AMX_NATIVE_CALL entity_get_vector(AMX *amx, cell *params)
{
int iEnt = params[1];
int idx = params[2];
cell *vRet = MF_GetAmxAddr(amx, params[3]);
Vector vRetValue = Vector(0, 0, 0);
CHECK_ENTITY_SIMPLE(iEnt);
edict_t *pEnt = TypeConversion.id_to_edict(iEnt);
switch (idx)
{
case origin:
vRetValue = pEnt->v.origin;
break;
case oldorigin:
vRetValue = pEnt->v.oldorigin;
break;
case velocity:
vRetValue = pEnt->v.velocity;
break;
case basevelocity:
vRetValue = pEnt->v.basevelocity;
break;
case clbasevelocity:
vRetValue = pEnt->v.clbasevelocity;
break;
case movedir:
vRetValue = pEnt->v.movedir;
break;
case angles:
vRetValue = pEnt->v.angles;
break;
case avelocity:
vRetValue = pEnt->v.avelocity;
break;
case punchangle:
vRetValue = pEnt->v.punchangle;
break;
case v_angle:
vRetValue = pEnt->v.v_angle;
break;
case endpos:
vRetValue = pEnt->v.endpos;
break;
case startpos:
vRetValue = pEnt->v.startpos;
break;
case absmin:
vRetValue = pEnt->v.absmin;
break;
case absmax:
vRetValue = pEnt->v.absmax;
break;
case mins:
vRetValue = pEnt->v.mins;
break;
case maxs:
vRetValue = pEnt->v.maxs;
break;
case size:
vRetValue = pEnt->v.size;
break;
case rendercolor:
vRetValue = pEnt->v.rendercolor;
break;
case view_ofs:
vRetValue = pEnt->v.view_ofs;
break;
case vuser1:
vRetValue = pEnt->v.vuser1;
break;
case vuser2:
vRetValue = pEnt->v.vuser2;
break;
case vuser3:
vRetValue = pEnt->v.vuser3;
break;
case vuser4:
vRetValue = pEnt->v.vuser4;
break;
default:
return 0;
break;
}
vRet[0] = amx_ftoc(vRetValue.x);
vRet[1] = amx_ftoc(vRetValue.y);
vRet[2] = amx_ftoc(vRetValue.z);
return 1;
}
As you can see in the first case, it converts the pEnt to v.origin, the same thing that happens inside the
entity_range().
The
get_distance_f() is provided by
vector.cpp
Code:
static cell AMX_NATIVE_CALL get_distance_f(AMX *amx, cell *params)
{
cell *cpVec1 = get_amxaddr(amx, params[1]);
cell *cpVec2 = get_amxaddr(amx, params[2]);
Vector vec1 = Vector((float)amx_ctof(cpVec1[0]), (float)amx_ctof(cpVec1[1]), (float)amx_ctof(cpVec1[2]));
Vector vec2 = Vector((float)amx_ctof(cpVec2[0]), (float)amx_ctof(cpVec2[1]), (float)amx_ctof(cpVec2[2]));
REAL fDist = (REAL) (vec1 - vec2).Length();
return amx_ftoc(fDist);
}
And here, it does the same too: gets the difference between two points. Not sure about what
REAL does, maybe the same goal as the
abs().
-
The idea is to make the code the shortest possible, so it is easy to edit, fix or read. Keep in mind that
entity_get_vector() wasn't meant just for origin information, as you can see in the code inside engine.cpp. So if your goal was only to get the distance and nothing else, using
entity_range() is way faster. Different natives for different purposes.
__________________