SA-MP Forums Archive
Lag help - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Lag help (/showthread.php?tid=609606)



Lag help - Fantje - 14.06.2016

Heey guys,

I made a server and I get huge lag when I am near another player. Everyone has the same problem. I think it's something causing in my script...

I tried on different hosts and all got the problem.

Please help!


Re: Lag help - xTURBOx - 14.06.2016

Maybe your gamemode is un-optimized ?


Re: Lag help - Vince - 14.06.2016

Run profiler plugin. Also check for large chunks of code in OnPlayerUpdate.


Re: Lag help - Fantje - 14.06.2016

Thanks guys:

Here my onplayerupdate:
PHP код:
public OnPlayerUpdate(playerid)
{
    new 
str[256];
    
format(str,sizeof(str),"~r~Kills: ~w~%d ~g~Deaths: ~w~%d",User[playerid][kills],User[playerid][deaths], User[playerid][score]);
    
TextDrawSetString(Text:Stats[playerid],str);
    new 
string[256];
    
format(string,sizeof(string),"~g~Score: ~w~%d ~g~Class: ~w~%d",User[playerid][score],gPlayerClass[playerid]);
    
TextDrawSetString(Text:Stats2[playerid],string);
    new 
st[256];
    new 
Float:ratio;
    if(
User[playerid][deaths] <= 0ratio 0.0;
    else 
ratio floatdiv(User[playerid][kills], User[playerid][deaths]);
    
format(st,sizeof(st),"~g~K/D: ~w~%0.2f",ratio);
    
TextDrawSetString(Text:Stats3[playerid],st);
    
GetPlayerRank(playerid);
    return 
1;




Re: Lag help - Stinged - 14.06.2016

Well first thing is, optimize your code. Especially your arrays.
3 different arrays with 256 cells? Couldn't you reformat the same one?

And why do you do that under OnPlayerUpdate?
Just update the textdraw whenever something needs updating.
(For example, use OnPlayerDeath to update your kills and deaths etc..)
OnPlayerUpdate runs multiple times a second.


Re: Lag help - Vince - 14.06.2016

Nothing too extensive, but still completely unnecessary considering that all these things are controlled by the server. OnPlayerUpdate is meant to capture events that are controlled by the client and for which no specific callback exists. It is not a general purpose timer.

Kills/Deaths related textdraw should be moved to OnPlayerDeath. Score textdraw should be moved to wherever the score is updated.


Re: Lag help - Fantje - 14.06.2016

Thanks guys!