Thanks Lod and others
I got it to work with a modified sample of the c++ variant. This code will return a float where 0.0 is furthest away and 1.0 is closests to our aimline. If the player is not in the radius (distance) this function will return 0.0. Now all there is to do is to make a traceline check and people can begin to drain life
Code:
public Float:Find_Angle(Core,Target,Float:dist)
{
new Float:vec2LOS[2]
new Float:flDot
new Float:CoreOrigin[3]
new Float:TargetOrigin[3]
new Float:CoreAngles[3]
pev(Core,pev_origin,CoreOrigin)
pev(Target,pev_origin,TargetOrigin)
if (get_distance_f(CoreOrigin,TargetOrigin) > dist)
return 0.0
pev(Core,pev_angles, CoreAngles)
for ( new i = 0; i < 2; i++ )
vec2LOS[i] = TargetOrigin[i] - CoreOrigin[i]
new Float:veclength = Vec2DLength(vec2LOS)
//Normalize V2LOS
if (veclength <= 0.0)
{
vec2LOS[x] = 0.0
vec2LOS[y] = 0.0
}
else
{
new Float:flLen = 1.0 / veclength;
vec2LOS[x] = vec2LOS[x]*flLen
vec2LOS[y] = vec2LOS[y]*flLen
}
//Do a makevector to make v_forward right
engfunc(EngFunc_MakeVectors,CoreAngles)
new Float:v_forward[3]
new Float:v_forward2D[2]
get_global_vector(GL_v_forward, v_forward)
v_forward2D[x] = v_forward[x]
v_forward2D[y] = v_forward[y]
//flDot = DotProduct (vec2LOS , gpGlobals->v_forward.Make2D() );
flDot = vec2LOS[x]*v_forward2D[x]+vec2LOS[y]*v_forward2D[y]
//0.5 = 90'
if ( flDot > 0.5 )
{
return flDot
}
return 0.0
}