SA-MP Forums Archive
Does Defining MAX_PLAYERS low lag? - 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: Does Defining MAX_PLAYERS low lag? (/showthread.php?tid=348737)



Does Defining MAX_PLAYERS low lag? - ricardo178 - 06.06.2012

Well while testing the GM i am making, i see the chat and all lags a bit. Might it be caused becayse i have many functions searching on MAX_PLAYERS and i don't have it defined to a max?

Or could it be the timers?

Every timers i have are:

pawn Код:
new TIMER_pOnlineTime[MAX_PLAYERS];
new TIMER_Fuel[MAX_PLAYERS];
new TIMER_KM[MAX_PLAYERS];
new TIMER_Oil[MAX_PLAYERS];
new TIMER_Pneus[MAX_PLAYERS];
new TIMER_UpdateCar[MAX_PLAYERS];
new TIMER_UnJail[MAX_PLAYERS];

Under OnPlayerStateChange i have this, after checking if player is inside a vehicle..

TIMER_Fuel[playerid] = SetTimerEx("CFuel", 60000, true, "i", playerid);
TIMER_KM[playerid] = SetTimerEx("CKM", 30000, true, "i", playerid);
TIMER_Oil[playerid] = SetTimerEx("COil", 30000, true, "i", playerid);
TIMER_Pneus[playerid] = SetTimerEx("CPneus", 30000, true, "i", playerid);
TIMER_UpdateCar[playerid] = SetTimerEx("UpdateCar", 500, true, "i", playerid);
Than i have some 15 or 20 functions searching on MAX_PLAYERS but are rarely called.. It's like /ask to send messages to admins, and these things.

If it was an hosted server with lot of players it would be a reason to lag, but, test server where the max that join is me and my friend when i need to test things with 2 people, it turns weird for me.


AW: Does Defining MAX_PLAYERS low lag? - Extremo - 06.06.2012

I don't know if it's still the case but one reason for the lag could be that you do things with not connected players. I did that mistake once, don't remember exactly what I did but I forgot to check if the player is connected which made my server lag heavily. Not sure if that's the case anymore though. Just a suggestion.

I have my doubts that your couple commands and your timers would really lag your server that much. Maybe you have a while loop that lasts for a pretty long while? Or even a for loop?

Just ideas though.

EDIT: I just realized you have three timers supposely working on the same milisecond. I think you should have a look at YSI from ****** and a deeper look at y_iterate. Since all of these timers execute on the same milisecond I can actually imagine the collision of these causing the server to hang for a moment awaiting for all three functions to finish. I don't know if this lag would be significant I am afraid but it could be a cause.

EDIT2: Infact, lets just test it? Try and add about a 100 miliseconds to one of the timers and remove a 100 miliseconds from another. So that none of the timers are on the same milisecond. 100 is probably a little much but its worth it to be sure. See if it lags or if it has stopped, if it did stop then you should have a look at y_iterate.


Re: Does Defining MAX_PLAYERS low lag? - ricardo178 - 06.06.2012

I never check if player is connected... It was bugging together with sscanf.


AW: Does Defining MAX_PLAYERS low lag? - Extremo - 06.06.2012

Oh right, if you use sscanf you don't actually have to check if the player is connected.

Though what I was saying is not commands like:

Код:
/kick PlayerID
but rather code that for example sets the positions of players even if they are not connected and such. I did that once a long time ago and it lagged my server a lot. Probably by now is fixed though.


Re: Does Defining MAX_PLAYERS low lag? - MadeMan - 06.06.2012

Quote:
Originally Posted by ricardo178
Посмотреть сообщение
Or could it be the timers?

Every timers i have are:

pawn Код:
Under OnPlayerStateChange i have this, after checking if player is inside a vehicle..

TIMER_Fuel[playerid] = SetTimerEx("CFuel", 60000, true, "i", playerid);
TIMER_KM[playerid] = SetTimerEx("CKM", 30000, true, "i", playerid);
TIMER_Oil[playerid] = SetTimerEx("COil", 30000, true, "i", playerid);
TIMER_Pneus[playerid] = SetTimerEx("CPneus", 30000, true, "i", playerid);
TIMER_UpdateCar[playerid] = SetTimerEx("UpdateCar", 500, true, "i", playerid);
When do you kill the timers? (KillTimer)


Re: Does Defining MAX_PLAYERS low lag? - ricardo178 - 06.06.2012

I kill them on player exit vehicle...

pawn Код:
public OnPlayerExitVehicle(playerid, vehicleid)
{
    KillTimer(TIMER_Fuel[playerid]);
    KillTimer(TIMER_KM[playerid]);
    KillTimer(TIMER_Oil[playerid]);
    KillTimer(TIMER_Pneus[playerid]);
    return 1;
}
All them are vehicle related..


AW: Does Defining MAX_PLAYERS low lag? - Extremo - 06.06.2012

You're never killing this one

pawn Код:
TIMER_UpdateCar[playerid] = SetTimerEx("UpdateCar", 500, true, "i", playerid);



Re: Does Defining MAX_PLAYERS low lag? - ricardo178 - 06.06.2012

Shit, that's probably it... Thank you man.


Re: Does Defining MAX_PLAYERS low lag? - milanosie - 06.06.2012

It does not bug with sscanf,
Your just using it BEFORE you define id in sscanf.


use IsPlayerConnected AFTER sscanf


Re: Does Defining MAX_PLAYERS low lag? - Jonny5 - 06.06.2012

i would also combine these 3 timers as they run at the same interval

pawn Код:
TIMER_KM[playerid] = SetTimerEx("CKM", 30000, true, "i", playerid);
TIMER_Oil[playerid] = SetTimerEx("COil", 30000, true, "i", playerid);
TIMER_Pneus[playerid] = SetTimerEx("CPneus", 30000, true, "i", playerid);