Raised This Month: $ Target: $400
 0% 

To many if statments?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Doc-Holiday
AlliedModders Donor
Join Date: Jul 2007
Old 10-30-2011 , 16:18   To many if statments?
Reply With Quote #1

I have a question for you awesome scripters

With the below code im noticing lag when i kill some one on my team or thother...

Is that caused by to many if statements?

PHP Code:
public fwdPlayerDeath(iVictimiAttackeriShouldGib)
{
    if(!
get_pcvar_num(g_Cvar2[CVAR_ENABLED]) || is_user_bot(iAttacker))
        return 
HAM_IGNORED;
    
    if(
get_pcvar_num(g_Cvar2[CVAR_DEATHMATCH]) && !bBombPlanted)
    {
        
set_task(get_pcvar_float(g_Cvar2[CVAR_RESPAWNTIME]), "RespawnPlayer"iVictim);
        
set_task(0.01"RespawnHud"iVictim);
    }
    
    
set_pev(iVictimpev_iuser10);
    
    if(
get_pcvar_num(g_Cvar2[CVAR_SOUNDTOGGLE]))
    {
        
emit_sound(iVictimCHAN_VOICEg_Death_Sounds[random(sizeof(g_Death_Sounds))], VOL_NORMATTN_NORM0PITCH_NORM);
    }
    
    
StopBleeding(iVictim);
    
g_kills[iVictim] = 0;
    
g_HS[iVictim] = 0;
    
    if(!
IsPlayer(iAttacker))
        return 
HAM_IGNORED;
        
    new 
weapon get_user_weapon(iAttacker);
    new 
HitGroup get_pdata_int(iVictimm_LastHitGroup5);
    new 
iClass g_XP[iAttacker][Class];
    new 
iTotalKillerXP;
    
    if(
get_pcvar_num(g_Cvar2CVAR_TK ]) && cs_get_user_team(iVictim) == cs_get_user_team(iAttacker))
    {
        
g_XP[iAttacker][XP][iClass] -= get_pcvar_num(g_Cvar2[CVAR_TKXP]);
        
set_hudmessage(0255500.500.3312.02.0);
        
ShowSyncHudMsg(iAttackergHudSyncXp"- %d"get_pcvar_num(g_Cvar2[CVAR_TKXP]));
    }
    else if(
cs_get_user_team(iAttacker) != cs_get_user_team(iVictim))
    {
        
//Adds Kill XP
        
iTotalKillerXP += get_pcvar_num(g_Cvar2[CVAR_KILLXP]);
        ++
g_kills[iAttacker];
        
        
//Adds Knife Bonus
        
if(weapon == CSW_KNIFE)
        {
            
iTotalKillerXP += get_pcvar_num(g_Cvar2[CVAR_KNIFEBONUS]);
        }
        
        if(
HitGroup == HIT_HEAD)
        {
            
iTotalKillerXP += get_pcvar_num(g_Cvar2[CVAR_HSBONUS]);
            ++
g_HS[iAttacker];
        }
        
        
//Adds Kill Streak Bonus
        
if(g_kills[iAttacker] == get_pcvar_num(g_Cvar2[CVAR_KILLSTREAK]))
        {
            
iTotalKillerXP += get_pcvar_num(g_Cvar2[CVAR_KILLSTREAKBONUS]);
            
g_kills[iAttacker] = 0;
        }
        
        
//Adds Headshot Streak
        
if(g_HS[iAttacker] == get_pcvar_num(g_Cvar2[CVAR_HSSTREAK]))
        {
            
iTotalKillerXP += get_pcvar_num(g_Cvar2[CVAR_HSSTREAKBONUS]);
            
g_HS[iAttacker] = 0;
        }
        
        
g_XP[iAttacker][XP][iClass] += iTotalKillerXP;
        
set_hudmessage(0255500.500.3312.02.0);
        
ShowSyncHudMsg(iAttackergHudSyncXp"+ %d"iTotalKillerXP);
        
iTotalKillerXP 0;
    }
    
    
CheckLevel(iAttacker);
    return 
HAM_IGNORED;



EDIT... now its not lagging on player death but crashing on map change due to nvault... GOD I HATE THIS CRAP....

Last edited by Doc-Holiday; 10-30-2011 at 16:34.
Doc-Holiday is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 10-30-2011 , 16:57   Re: To many if statments?
Reply With Quote #2

Are you closing vault at plugin_end()? Its not necessarily if statements that are the problem, its what is done in and after the if statement that will cause lag.
__________________
Bugsy is offline
Doc-Holiday
AlliedModders Donor
Join Date: Jul 2007
Old 10-31-2011 , 02:42   Re: To many if statments?
Reply With Quote #3

Quote:
Originally Posted by Bugsy View Post
Are you closing vault at plugin_end()? Its not necessarily if statements that are the problem, its what is done in and after the if statement that will cause lag.

The lag was fixed not exactly sure wtf that was about...

And yes the vault closes at end. The code is very long i can attacth it if you want but its 2k+ lines
Doc-Holiday is offline
Reply



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 14:23.


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