big functions on OnPlayerUpdate might lag?
#1

big functions like this on OnPlayerUpdate might lag the server?
PHP код:
new Float:playerarmour;
    
GetPlayerArmour(playerid,playerarmour);
    if(
playerarmour>98){
    
format(String,sizeof(String),"[GameGuard] {ff7777}%s has been ip banned, reason: Cheat Detected (#Code 47)",GetName(playerid));
    
MSGTA(C_RED,String);
    
TogglePlayerControllable(playerid,0);
    new 
Year2,Month2,Day2,Hour2,Minute2,Second2;
    
gettime(Hour2,Minute2,Second2);
    
getdate(Day2,Month2,Year2);
    
format(String,sizeof(String),"{ff0000}You've banned from the server!\n{FFFFFF}Admin: GameGuard\nReason: %s\nTime: %i:%i:%i\nDate: %i/%i/%i",String2,Hour2,Minute2,Second2,Year2,Month2,Day2);
    
DLG(param[0],999,DIALOG_STYLE_MSGBOX,"{ff0000}IP Ban",String,"Close","");
    
GetPlayerIp(playerid,PIP,sizeof(PIP));
    
format(BanipDB[playerid][IPAddress],16,PIP);
    
format(BanipDB[playerid][Admin],MAX_PLAYER_NAME,"GameGuard");
    
format(BanipDB[playerid][Reason],256,"Armour Hack");
    
BanipDB[playerid][Second]=Second2;
    
BanipDB[playerid][Minute]=Minute2;
    
BanipDB[playerid][Hour]=Hour2;
    
BanipDB[playerid][Day]=Day2;
    
BanipDB[playerid][Month]=Month2;
    
BanipDB[playerid][Year]=Year2;
    
SaveBanipFile(playerid);
    
GameTextForPlayer(playerid"~R~Banned"999990);
    
KickPlayer(playerid);} 
Reply
#2

Might NOT lag with few players on the server, but will surely be worse with more players,
Using a one second(even if less) timer should be better, cause onplayerupdate gets called alot per second(for a non afk player).
Reply
#3

Ty man (+rep)
Reply
#4

OnPlayerUpdate might get called around 50-60 or even MORE in one second, putting heavy CPU actions might lag your server so be careful when using it!

Use global/local timers instead (SetTimer/SetTimerEx [for specific player]).

I hope I helped any feedback is appreciated!
Reply
#5

You're basically making a new variable almost 50 times a second, I suggest you read the posts above^^

Also, doesn't that player armour thingy spam the chat once detected?
Reply
#6

OnPlayerUpdate shouldn't be used if you care for the server performance.
Use timers instead.

EDIT: Stanford said the same.
Reply
#7

Quote:
Originally Posted by Stanford
Посмотреть сообщение
OnPlayerUpdate might get called around 50-60 or even MORE in one second, putting heavy CPU actions might lag your server so be careful when using it!

Use global/local timers instead (SetTimer/SetTimerEx [for specific player]).

I hope I helped any feedback is appreciated!
Yeah I did, Thanks mate (+REP)

Quote:
Originally Posted by JaydenJason
Посмотреть сообщение
You're basically making a new variable almost 50 times a second, I suggest you read the posts above^^

Also, doesn't that player armour thingy spam the chat once detected?
Well yeah, I read his post above, and ye i thought about it so I thought about changing his HP/AP before it'd send the message to normal HP/AP. anyways i'd use it ever 3 seconds so no needed to change his HP, Thanks mate (+rep)
Reply
#8

The only thing you shouldn't do in OnPlayerUpdate is accessing the disk, because that is very slow and usually not necessary. There's some kind of stigma around using OnPlayerUpdate but if you use it wisely there is no reason why you shouldn't. You should mainly use this callback to catch a player's state change that does not have its own dedicated callback, for example OnPlayerHealthChange, OnPlayerArmorChange, OnPlayerWeaponChange, etc.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)