I have these two functions, but not sure if this would be an efficient way:
Code:
if(fm_get_user_aiming_ent(id, "func_breakable") == ent)
{
// player is aiming at ent
}
// ....
fm_get_user_aiming_ent(index, const sClassName[])
{
new Float:vOrigin[3];
fm_get_aim_origin(index, vOrigin);
new ent, sTempClass[32], iLen = sizeof(sTempClass) - 1;
do
{
pev(ent, pev_classname, sTempClass, iLen);
if(equali(sClassName, sTempClass) && fm_is_ent_visible(index, ent))
{
return ent;
}
}
while((ent = engfunc(EngFunc_FindEntityInSphere, index, vOrigin, 10.0)))
return 0;
}
// fakemeta_util.inc
stock fm_get_aim_origin(index, Float:origin[3]) {
new Float:start[3], Float:view_ofs[3]
pev(index, pev_origin, start)
pev(index, pev_view_ofs, view_ofs)
xs_vec_add(start, view_ofs, start)
new Float:dest[3]
pev(index, pev_v_angle, dest)
engfunc(EngFunc_MakeVectors, dest)
global_get(glb_v_forward, dest)
xs_vec_mul_scalar(dest, 9999.0, dest)
xs_vec_add(start, dest, dest)
engfunc(EngFunc_TraceLine, start, dest, 0, index, 0)
get_tr2(0, TR_vecEndPos, origin)
return 1
}
// fakemeta_util.inc
stock bool:fm_is_ent_visible(index, entity, ignoremonsters = 0) {
new Float:start[3], Float:dest[3]
pev(index, pev_origin, start)
pev(index, pev_view_ofs, dest)
xs_vec_add(start, dest, start)
pev(entity, pev_origin, dest)
engfunc(EngFunc_TraceLine, start, dest, ignoremonsters, index, 0)
new Float:fraction
get_tr2(0, TR_flFraction, fraction)
if (fraction == 1.0 || get_tr2(0, TR_pHit) == entity)
return true
return false
}
1. I'm not sure if this would work properly
2. I'm not sure if this is the best way to do this