Raised This Month: $ Target: $400
 0% 

[CS] Find entity if it is within the radius and apply damage


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Author Message
Rirre
Veteran Member
Join Date: Nov 2006
Old 08-27-2013 , 15:39   [CS] Find entity if it is within the radius and apply damage
Reply With Quote #1

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.
Tried Ham_FVisible but it doesn't seem to work :/
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) }

Last edited by Rirre; 08-28-2013 at 12:19.
Rirre is offline
 



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 18:57.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode