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
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 08-29-2013 , 13:24   Re: [CS] Find entity if it is within the radius and apply damage
Reply With Quote #6

vexd_pfntouch, pfn_touch, FM_Touch are bad to use.
You could greatly optimize your code using register_touch.
Also, consider find_ent_sphere so you can retrieve entity list within the wanted sphere :

PHP Code:
new const MONSTER_CLASS[] = "func_wall";

public 
plugin_init()
{
    
register_touch("m203_nade""*""M203_Nade_Touch");
}

public 
M203_Nade_Touch(nadeidOther)
{
    new 
walls[64], monsterFloat:takedamageFloat:distFloat:origin[3], Float:monsterAbsMax[3], Float:monsterAbsMin[3], Float:monsterOrigin[3];
    new 
wallsnum find_sphere_class(nadeMONSTER_CLASSdmgradiuswallssizeof(walls));

    
entity_get_vector(nadeEV_VEC_originorigin);

    for(--
wallsnumwallsnum>=0wallsnum--)
    {
        
monster wallswallsnum ];
        if( 
IsEntMonster(monsterfalse) )
        {
            
entity_get_float(monsterEV_FL_takedamagetakedamage);
            if( 
takedamage != DAMAGE_NO )
            {
                
entity_get_vector(monsterEV_VEC_absminmonsterAbsMin);
                
entity_get_vector(monsterEV_VEC_absmaxmonsterAbsMin);
                
xs_vec_sub(monsterAbsMaxmonsterAbsMinmonsterOrigin);

                
dist get_distance_f(originmonsterOrigin);

                
// if (dist <= dmgradius) // not needed because we use find_sphere_class

                
dRatio dmgradius dist
                damage 
maxdamage floatrounddRatio maxdamage )
                    
                
//...do damage
            
}
        }
    }

    new 
players[32], pnumid;
    
find_sphere_class(nade"player"dmgradiusplayerssizeof(players));

    for(--
pnumpnum >= 0pnum--)
    {
        
id players[pnum];
        if( 
is_user_alive(id) && !get_user_godmode(id) )
        {
            
dist entity_range(nadeid);
            
// do damage, screenshake etc..
        
}
    }

    
remove_entity(nade);
    return 
PLUGIN_HANDLED;
}

bool:IsEntMonster(entbool:bCheckClassName)
{
    if( 
bCheckClassName )
    {
        static class[];
        
entity_get_string(entEV_SZ_classname, class, charsmax(class));
        if( !
equal(class, MONSTER_CLASS) )
        {
            return 
false;
        }
    }

    return !!(
entity_get_int(entEV_INT_flags) & FL_MONSTER);

__________________
- tired and retired -

- my plugins -
ConnorMcLeod 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