Raised This Month: $51 Target: $400
 12% 

Causing lag (Unkn Reason) Possibly bomb code


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Doc-Holiday
AlliedModders Donor
Join Date: Jul 2007
Old 12-27-2011 , 14:40   Causing lag (Unkn Reason) Possibly bomb code
Reply With Quote #1

So using my battle field plugin when i plant/defuse/explode the bomb it lags. and then it resumes where it left off.

Below is all the code involved with the bomb planting.

PHP Code:
public ePlanted()
{
    if(!
g_Cvar2[CVAR_ENABLED])
        return 
PLUGIN_HANDLED;
        
    for(new 
1<= g_iMaxPlayers; ++i)
    {
        if(!
IsPlayer(i))
            return 
PLUGIN_HANDLED;
        
        if(
is_user_alive(i) && get_user_team(i) == 1)
        {
            
is_alive[i] = true;
            
g_XP[i][XP][g_XP[i][Class]] += get_pcvar_num(g_Cvar2[CVAR_PLANTBONUS]);
            
set_hudmessage(0255500.500.3312.02.0);
            
ShowSyncHudMsg(igHudSyncXp"+ %d"get_pcvar_num(g_Cvar2[CVAR_PLANTBONUS]));
        }
        
bBombPlanted true;
        
CheckLevel(i);
    }
    return 
PLUGIN_CONTINUE;
}

public 
eDefused()
{
    if(!
g_Cvar2[CVAR_ENABLED])
        return 
PLUGIN_HANDLED;
        
    for(new 
1<= g_iMaxPlayers; ++i)
    {
        if(!
IsPlayer(i))
            return 
PLUGIN_HANDLED;
            
        if(
is_user_alive(i) && get_user_team(i) == 2)
        {
            
g_XP[i][XP][g_XP[i][Class]] +=  get_pcvar_num(g_Cvar2[CVAR_DEFUSEBONUS]);
            
is_alive[i] = false;
            
ShowSyncHudMsg(igHudSyncXp"+ %d"get_pcvar_num(g_Cvar2[CVAR_DEFUSEBONUS]));
        }
        
CheckLevel(i);
    }
    return 
PLUGIN_CONTINUE;
}

public 
eExplosion()
{
    if(!
g_Cvar2[CVAR_ENABLED])
        return 
PLUGIN_HANDLED;
        
    for(new 
1<= g_iMaxPlayers; ++i)
    {
        if(!
IsPlayer(i))
            return 
PLUGIN_HANDLED;
        
        if(
is_alive[i] && get_user_team(i) == 1)
        {
            
g_XP[i][XP][g_XP[i][Class]] +=  get_pcvar_num(g_Cvar2[CVAR_EXPBONUS]);
            
is_alive[i] = false;
            
ShowSyncHudMsg(igHudSyncXp"+ %d"get_pcvar_num(g_Cvar2[CVAR_EXPBONUS]));
        }
        
CheckLevel(i);
    }
    return 
PLUGIN_CONTINUE;
}

public 
eTargetSaved()
{
    if(!
g_Cvar2[CVAR_ENABLED])
        return 
PLUGIN_HANDLED;
        
    for(new 
1<= g_iMaxPlayers; ++i)
    {
        if(!
IsPlayer(i))
            return 
PLUGIN_HANDLED;
            
        if(
is_user_alive(i) && get_user_team(i) == 2)
        {
            
g_XP[i][XP][g_XP[i][Class]] +=  get_pcvar_num(g_Cvar2[CVAR_TARGSAVBONUS]);
            
ShowSyncHudMsg(igHudSyncXp"+ %d"get_pcvar_num(g_Cvar2[CVAR_TARGSAVBONUS]));
        }
        
CheckLevel(i);
    }
    return 
PLUGIN_CONTINUE;

Doc-Holiday is offline
Sylwester
Veteran Member
Join Date: Oct 2006
Location: Poland
Old 12-27-2011 , 16:16   Re: Causing lag (Unkn Reason) Possibly bomb code
Reply With Quote #2

I grant you an award for the most inefficient way of saving data of the year:
PHP Code:
public ePlanted(){  //, eDefused(), eExplosion(), eTargetSaved()
    
for(new 1<= g_iMaxPlayers; ++i){
        
//...
        
CheckLevel(i); // <---- THIS
    
}


public 
CheckLevel(id){
    
//...
    
SaveData(id); // <------ THIS
}

public 
SaveDataid ){
    if(
sqlv_connect(g_hVault)){
        new 
iPosszSave[(XPDATA 10) + 1];
        for (new 
XPDATA i++){
            
iPos += formatex(szSave[iPos] ,charsmax(szSave) , "%10d" g_XP[id][i]);
            
sqlv_set_data(g_hVaultg_szAuthID[id], szSave); // < ------ THIS
            //seriously, why is sqlv_set_data in this loop?
        
}
        
sqlv_disconnect(g_hVault);
    }
    
//...

If you don't understand, then (for example on 32 players server) in each of those functions (ePlanted, eDefused, eExplosion, eTargetSaved) you send 320 (non-threaded) queries to sql database...
__________________
Impossible is Nothing
Sylwester is offline
Doc-Holiday
AlliedModders Donor
Join Date: Jul 2007
Old 12-27-2011 , 16:51   Re: Causing lag (Unkn Reason) Possibly bomb code
Reply With Quote #3

Quote:
Originally Posted by Sylwester View Post
I grant you an award for the most inefficient way of saving data of the year:
PHP Code:
public ePlanted(){  //, eDefused(), eExplosion(), eTargetSaved()
    
for(new 1<= g_iMaxPlayers; ++i){
        
//...
        
CheckLevel(i); // <---- THIS
    
}


public 
CheckLevel(id){
    
//...
    
SaveData(id); // <------ THIS
}

public 
SaveDataid ){
    if(
sqlv_connect(g_hVault)){
        new 
iPosszSave[(XPDATA 10) + 1];
        for (new 
XPDATA i++){
            
iPos += formatex(szSave[iPos] ,charsmax(szSave) , "%10d" g_XP[id][i]);
            
sqlv_set_data(g_hVaultg_szAuthID[id], szSave); // < ------ THIS
            //seriously, why is sqlv_set_data in this loop?
        
}
        
sqlv_disconnect(g_hVault);
    }
    
//...

If you don't understand, then (for example on 32 players server) in each of those functions (ePlanted, eDefused, eExplosion, eTargetSaved) you send 320 (non-threaded) queries to sql database...
That would explain the lag haha... I dont know anything about sql or vault for that matter. The saving stuff is from bugzy and my original xp mod.

PHP Code:
public SaveDataid )
    {
        if(
sqlv_connect(g_hVault))
        {
            new 
iPosszSave[(XPDATA 10) + 1];
            
            for (new 
XPDATA i++)
            {
                
iPos += formatex(szSave[iPos] ,charsmax(szSave) , "%10d" g_XP[id][i]);
            }
            
sqlv_set_data(g_hVaultg_szAuthID[id], szSave);
            
            
sqlv_disconnect(g_hVault);
        }
        else
        {
            
set_fail_state("Error Connecting to SQLVault");
        }
    } 
Removed it from the loop and it seems to be working fine now. Thank you.

Last edited by Doc-Holiday; 12-27-2011 at 16:58.
Doc-Holiday is offline
Emp`
AMX Mod X Plugin Approver
Join Date: Aug 2005
Location: Decapod 10
Old 12-27-2011 , 16:58   Re: Causing lag (Unkn Reason) Possibly bomb code
Reply With Quote #4

First thing you should do is only CheckLevel when someone's xp is changed. That will reduce about half of the saving.

If you need to use sql saving, then you should change to Threaded Queries. This will allow your sql queries to be run in the background and not freeze the server waiting for responses from all your queries.

If you do not need to use sql, I would suggest you change to a non-sql vault; it will highly reduce the time to save data.
Emp` is offline
Send a message via AIM to Emp` Send a message via MSN to Emp` Send a message via Yahoo to Emp` Send a message via Skype™ to Emp`
Doc-Holiday
AlliedModders Donor
Join Date: Jul 2007
Old 12-27-2011 , 17:03   Re: Causing lag (Unkn Reason) Possibly bomb code
Reply With Quote #5

Quote:
Originally Posted by Emp` View Post
First thing you should do is only CheckLevel when someone's xp is changed. That will reduce about half of the saving.

If you need to use sql saving, then you should change to Threaded Queries. This will allow your sql queries to be run in the background and not freeze the server waiting for responses from all your queries.

If you do not need to use sql, I would suggest you change to a non-sql vault; it will highly reduce the time to save data.
Only reason I used SQL is due to the fact that nvault seems to save in error. and then crashes the server.

and eventually i wanna try working with web ranking.

Last edited by Doc-Holiday; 12-27-2011 at 17:10.
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 02:15.


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