Quote:
Originally Posted by RayZek95
And without that? I need to know what I'm doing, the way using vectors like the stock I posted
|
I'm a noob at scripting but I can help I guess.
Code:
stock GetUserEyePosition(iId, Float:vecReturn[3], Float:fNormalDist)
{
static Float:vecStart[3], Float:vecEnd[3]
entity_get_vector(iId, EV_VEC_origin, vecStart)
entity_get_vector(iId, EV_VEC_view_ofs, vecEnd)
xs_vec_add(vecStart, vecEnd, vecEnd)
entity_get_vector(iId, EV_VEC_v_angle, vecEnd)
engfunc(EngFunc_MakeVectors, vecEnd)
get_global_vector(GL_v_forward, vecEnd)
xs_vec_mul_scalar(vecEnd, 9999.9, vecEnd)
xs_vec_add(vecStart, vecEnd, vecEnd)
engfunc(EngFunc_TraceLine, vecStart, vecEnd, DONT_IGNORE_MONSTERS, iId, 0)
// Check if the trace hit the ground
if(get_tr2(0, TR_iHitgroup) == HITGROUP_GENERIC && get_tr2(0, TR_flFraction) < 1.0)
{
// Check if the trace hit the floor
if(get_tr2(0, TR_iHitgroup) & CONTENTS_SOLID)
{
// Get the trace end position
get_tr2(0, TR_vecEndPos, vecReturn)
// Set the origin of the entity to the trace end position with Z = 0
vecReturn[2] = 0.0
entity_set_vector(iId, EV_VEC_origin, vecReturn)
}
}
}
This function works by first checking if the trace hit the ground using the get_tr2(0, TR_iHitgroup) function, and the fraction of the trace using the get_tr2(0, TR_flFraction) function. If the trace hit the ground and the fraction is less than 1, it will check if the trace hit the floor using the get_tr2(0, TR_iHitgroup) & CONTENTS_SOLID where the CONTENTS_SOLID macro is a flag that represents the floor or solid ground. If the trace hit the floor, it will set the origin of the entity to the trace end position with Z = 0 using the entity_set_vector(iId, EV_VEC_origin, vecReturn) function.
__________________