Too much CPU usage
#1

Hello there ServerFFS keeps sending me e-mails that I am using too much CPU,
They told me it has something to do with this part of my script:

Code:
public OnPlayerUpdate(playerid)
{
if(IsPlayerConnected(playerid))
{
if(AccountInfo[playerid][aLogged] == 1)
{
new string3[128];
new playername3[MAX_PLAYER_NAME];
GetPlayerName(playerid, playername3, sizeof(playername3));
format(string3, sizeof(string3), ACCOUNTS_FOLDER, playername3);
new ip[20];
GetPlayerIp(playerid,ip,sizeof(ip));
new File: hFile = fopen(string3, io_write);
new PlayerScore, PlayerMoney;
PlayerMoney = GetPlayerMoney(playerid);
PlayerScore = GetPlayerScore(playerid);
AccountInfo[playerid][aScore] = PlayerScore;
AccountInfo[playerid][aMoney] = PlayerMoney;
if (hFile)
{
new var[128];
format(var, 128, "Password=%s\n", AccountInfo[playerid][aPassword]);fwrite(hFile, var);
format(var, 128, "IP=%s\n",ip);fwrite(hFile, var);
format(var, 128, "Level=%i\n", AccountInfo[playerid][aLevel]);fwrite(hFile, var);
format(var, 128, "Score=%i\n", PlayerScore);fwrite(hFile, var);
format(var, 128, "Money=%d\n", PlayerMoney);fwrite(hFile, var);
format(var, 128, "Airstrike=%i\n", airstrike[playerid]);fwrite(hFile, var);
format(var, 128, "Landmines=%i\n", LandMines[playerid]);fwrite(hFile, var);
format(var, 128, "Rank=%i\n", Rank[playerid]);fwrite(hFile, var);
fclose(hFile);
}
}
}
return 1;
}
Can anyone edit it that it does not use so much CPU?

Thanks!
Reply
#2

WOW, This thing is saves the player stats more than 3 times per second... i don't know exactly how much times OnPLayerUpdate is called in one second... just delete the saving thing use it on "OnPlayerDisconnect"
EDIT: or create a timer to save every 10 minutes...
Reply
#3

My scripter actually created this and he is on holiday for two weeks now,
Could you edit it.. so I can use it with like saving OnPlayerDisconnect
Reply
#4

Quote:
Originally Posted by Rickzor14
View Post
My scripter actually created this and he is on holiday for two weeks now,
Could you edit it.. so I can use it with like saving OnPlayerDisconnect
pawn Code:
public OnPlayerUpdate(playerid)
{
    return 1;
}
pawn Code:
public OnPlayerDisconnect(playerid)
{
if(AccountInfo[playerid][aLogged] == 1)
{
new string3[128];
new playername3[MAX_PLAYER_NAME];
GetPlayerName(playerid, playername3, sizeof(playername3));
format(string3, sizeof(string3), ACCOUNTS_FOLDER, playername3);
new ip[20];
GetPlayerIp(playerid,ip,sizeof(ip));
new File: hFile = fopen(string3, io_write);
new PlayerScore, PlayerMoney;
PlayerMoney = GetPlayerMoney(playerid);
PlayerScore = GetPlayerScore(playerid);
AccountInfo[playerid][aScore] = PlayerScore;
AccountInfo[playerid][aMoney] = PlayerMoney;
if (hFile)
{
new var[128];
format(var, 128, "Password=%s\n", AccountInfo[playerid][aPassword]);fwrite(hFile, var);
format(var, 128, "IP=%s\n",ip);fwrite(hFile, var);
format(var, 128, "Level=%i\n", AccountInfo[playerid][aLevel]);fwrite(hFile, var);
format(var, 128, "Score=%i\n", PlayerScore);fwrite(hFile, var);
format(var, 128, "Money=%d\n", PlayerMoney);fwrite(hFile, var);
format(var, 128, "Airstrike=%i\n", airstrike[playerid]);fwrite(hFile, var);
format(var, 128, "Landmines=%i\n", LandMines[playerid]);fwrite(hFile, var);
format(var, 128, "Rank=%i\n", Rank[playerid]);fwrite(hFile, var);
fclose(hFile);
}
}
return 1;
}
Reply
#5

Thats uh kinda not working..??

Do I have to change anything else in my GM? I just replaced your edit with my old thing
Reply
#6

no it should work...
Reply
#7

Add me on msn could be easier,
Rickvanderwel@live.nl
Reply
#8

never save player data in onplayerupdate. it's a criminal offense.
Reply
#9

First, remove that code in OnPlayerUpdate.

And add in OnPlayerDisconnect:

pawn Code:
public OnPlayerDisconnect( playerid, reason )
{
    if( AccountInfo[ playerid ][ aLogged ] == 1 )
    {
        new
            File[ 60 ],
            Name[ 24 ]
        ;
        GetPlayerName( playerid, Name, 24 );
        format( File, 60, ACCOUNTS_FOLDER, playername3);
        new
            File: hFile = fopen( File, io_write )
        ;
        if( hFile )
        {
            new
                Variable[ 65 ],
                IP[ 16 ]
            ;
            GetPlayerIp( playerid, IP, 16 );
            format( Variable, 65, "Password=%s\n", AccountInfo[ playerid ][ aPassword ] ), fwrite( File, Variable );
            format( Variable, 24, "IP=%s\n", IP ), fwrite( File, Variable );
            format( Variable, 12, "Level=%i\n", AccountInfo[ playerid ][ aLevel ] ), fwrite( File, Variable );
            format( Variable, 22, "Score=%i\n", GetPlayerScore( playerid ), fwrite( File, Variable );
            format( Variable, 22, "Money=%d\n", GetPlayerMoney( playerid ), fwrite( File, Variable );
            format( Variable, 26, "Airstrike=%i\n", airstrike[ playerid ] ), fwrite( File, Variable );
            format( Variable, 26, "Landmines=%i\n", LandMines[ playerid ] ), fwrite( File, Variable );
            format( Variable, 21, "Rank=%i\n", Rank[ playerid ] ), fwrite( File, Variable );
            fclose( File );
        }
    }
    return true;
}
Reply
#10

u hav a scripter?!?!?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)