Code:
static cell AMX_NATIVE_CALL VelocityByAim(AMX *amx, cell *params)
{
int iEnt = params[1];
int iVelocity = params[2];
cell *vRet = get_amxaddr(amx, params[3]);
Vector vVector = Vector(0, 0, 0);
edict_t *pEnt = NULL;
if (iEnt < 0 || iEnt > gpGlobals->maxEntities)
{
LogError(amx, AMX_ERR_NATIVE, "Entity out of range (%d)", iEnt);
return 0;
}
else
{
if (iEnt > 0 && iEnt <= gpGlobals->maxClients)
{
if (!GET_PLAYER_POINTER_I(iEnt)->ingame)
{
LogError(amx, AMX_ERR_NATIVE, "Invalid player %d (not ingame)", iEnt);
return 0;
}
pEnt = GET_PLAYER_POINTER_I(iEnt)->pEdict;
} else {
pEnt = INDEXENT(iEnt);
}
}
if (!pEnt)
{
LogError(amx, AMX_ERR_NATIVE, "Invalid entity %d (nullent)", iEnt);
return 0;
}
MAKE_VECTORS(pEnt->v.v_angle);
vVector = gpGlobals->v_forward * iVelocity;
vRet[0] = FloatToCell(vVector.x);
vRet[1] = FloatToCell(vVector.y);
vRet[2] = FloatToCell(vVector.z);
return 1;
}
I tried to do a modified version which supports these directions:
PHP Code:
#include <engine>
#include <fakemeta>
#include <xs>
enum Direction
{
DIRECTION_UP = 0,
DIRECTION_RIGHT,
DIRECTION_FORWARD,
DIRECTION_DOWN,
DIRECTION_LEFT,
DIRECTION_BACKWARD
}
stock velocity_by_direction(iEnt, Direction:iWhere = DIRECTION_FORWARD /* the default one */, Float:flVelocity, Float:flRetVector[3])
{
new Float:flBuffer[3]
entity_get_vector(iEnt, EV_VEC_v_angle, flBuffer)
engfunc(EngFunc_MakeVectors, flBuffer)
switch(iWhere)
{
case DIRECTION_UP, DIRECTION_DOWN: get_global_vector(GL_v_up, flBuffer)
case DIRECTION_RIGHT, DIRECTION_LEFT: get_global_vector(GL_v_right, flBuffer)
case DIRECTION_FORWARD, DIRECTION_BACKWARD: get_global_vector(GL_v_forward, flBuffer)
}
xs_vec_mul_scalar(flBuffer, _:iWhere <= 2 ? flVelocity : -flVelocity, flBuffer)
xs_vec_copy(flBuffer, flRetVector)
return 1
}
__________________