AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   To many if statments? (https://forums.alliedmods.net/showthread.php?t=170950)

Doc-Holiday 10-30-2011 16:18

To many if statments?
 
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....

Bugsy 10-30-2011 16:57

Re: To many if statments?
 
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.

Doc-Holiday 10-31-2011 02:42

Re: To many if statments?
 
Quote:

Originally Posted by Bugsy (Post 1586711)
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


All times are GMT -4. The time now is 14:22.

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