I need to find if "func_wall" entities with FL_MONSTER flag are close enough to deal damage to and then apply damage to them if they are.
The same way as it does for client-/players with adjustable damage depending on the distance from the explosion.
But I am out of ideas how to get it to work.
Also, "m203_nade" is supposed to only hurt FL_MONSTER's if it is visible for the m203_nade (not the player/owner of it) to not hurt them through walls.
Code:
public vexd_pfntouch(pToucher, pTouched)
{
new szClassName[32]
if ( pToucher > 0)
{
entity_get_string(pToucher, EV_SZ_classname, szClassName, 31)
}
if(equal(szClassName, "m203_nade"))
{
if(!pTouched && 0)
return
new dmgradius = get_cvar_num("amx_m203rad")
new maxdamage = get_cvar_num("amx_m203dmg")
new Float:fl_vExplodeAt[3]
entity_get_vector(pToucher, EV_VEC_origin, fl_vExplodeAt)
new vExplodeAt[3]
vExplodeAt[0] = floatround(fl_vExplodeAt[0])
vExplodeAt[1] = floatround(fl_vExplodeAt[1])
vExplodeAt[2] = floatround(fl_vExplodeAt[2])
new owner = entity_get_edict(pToucher, EV_ENT_owner)
new origin[3], dist, damage, Float:dRatio, Float:takedamage
// Players
for (new i = 1; i <= 32; i++)
{ // Players id
pev(i, pev_takedamage, takedamage)
if(takedamage > DAMAGE_NO)
{
get_user_origin(i,origin)
dist = get_distance(origin,vExplodeAt)
if (dist <= dmgradius)
{
dRatio = floatdiv(float(dist),float(dmgradius))
damage = maxdamage - floatround(floatmul(float(maxdamage),dRatio))
if(is_user_alive(i))
{
ScreenShake(i)
if(i == owner) // Owner of the nade
{
do_damage(i, damage) // Ow! Too close
set_velocity_from_origin(i, fl_vExplodeAt, get_cvar_float("amx_m203conc")*damage) // knockback
}
else if(i != owner && ExecuteHam( Ham_FVisible, i, pToucher ))
// TEST: Do it hit through the wall?
// without Ham_FVisible it does. with Ham_FVisible, nothing. Even if the owner and nade is fully visible for the teammate.
server_print("Teammate!")
}
}
}
}
// Monsters
new ent = -1
while((ent = find_ent_by_class(ent, "func_wall")))
{
pev(ent, pev_takedamage, takedamage)
if( takedamage > DAMAGE_NO && pev(ent, pev_flags) & FL_MONSTER )
{
entity_get_vector(ent, EV_VEC_origin, origin)
// Need to find if the FL_MONSTER is in the radius to deal damage to
// dist = get_distance(origin, vExplodeAt) --- do not work
// dist = entity_range(origin, vExplodeAt) --- do not work either
if (dist <= dmgradius)
{
dRatio = floatdiv(float(dist),float(dmgradius))
damage = maxdamage - floatround(floatmul(float(maxdamage),dRatio))
//...do damage
}
}
}
remove_entity(pToucher)
}
}
do_damage(victim, damage)
{
new Float:takedamage
pev(victim, pev_takedamage, takedamage)
new Float:fl_dmg = float(damage)
fakedamage(victim, "grenade", fl_dmg, DMG_BLAST)
}