SA-MP Forums Archive
Timers Making Server 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)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Timers Making Server Lag (/showthread.php?tid=152037)



Timers Making Server Lag - RichyB - 02.06.2010

Hey,
I was playing around with a Homes System and everytime I started the server, I would lag alot.
It once froze my computer to where I had to Press the Restart button.

Its because of a Timer, but I have know reason why.
Can someone help me.

This is all to do with the Timer!

At top of Gamemode.

new Timer[1];

On Gamemodeinit

Timer[0] = SetTimerEx("ReadPlayerHouseData", 1000, true, "%i", i);

And ReadPlayerHouseData

public ReadPlayerHouseData(playerid)
{
new string[256], house[64];
for(new h = 0; h <= MAX_HOUSES; h++){
format(house, sizeof(house), "/Houses/%d.dini.save", h);
if(dini_Exists(house)){
if(HouseInfo[h][hSellable] == 1){
if(PlayerToPoint(PTP_RADIUS, playerid, HouseInfo[h][hExitX], HouseInfo[h][hExitY], HouseInfo[h][hExitZ])) {
format(string, sizeof(string), "~g~ Mafia HQ Available ~n~~w~Owner:~y~ %s~n~~w~Level:~r~ %d~n~~w~Sell Price:~r~ %d~n~~w~Rent Cost:~r~ %d", HouseInfo[h][hName], HouseInfo[h][hLevel], HouseInfo[h][hSell], HouseInfo[h][hRent]);
GameTextForPlayer(playerid,string, 1500, 3);
}
} else if(HouseInfo[h][hSellable] == 0){
if(PlayerToPoint(PTP_RADIUS, playerid, HouseInfo[h][hExitX], HouseInfo[h][hExitY], HouseInfo[h][hExitZ])) {
if(HouseInfo[h][hName] == TERMIN@TOR)
{
format(string, sizeof(string), "~w~The Black Mafia HQ ~n~~w~Level:~r~ %d~n~~w~Rent Cost:~r~ %d", HouseInfo[h][hLevel], HouseInfo[h][hRent]);
GameTextForPlayer(playerid,string, 1500, 3);
}
format(string, sizeof(string), "~w~Owner:~y~ %s~n~~w~Level:~r~ %d~n~~w~Rent Cost:~r~ %d", HouseInfo[h][hName], HouseInfo[h][hLevel], HouseInfo[h][hRent]);
GameTextForPlayer(playerid,string, 1500, 3);
} } } }
}

It really laggy when I try it, any ideas?

Any Errors in the SetTimerEx?


Re: Timers Making Server Lag - DJDhan - 02.06.2010

Well, if there were any errors, it wouldn't compile would it? :P
By the way, Updating the house system every 1 second is definately going to make you lag if you have a lot of houses. Try a bigger interval, or even better, don't use a timer at all. If the ReadPlayerHouseData only shows info about the house icon a player is in currently, call ReadPlayerHouseData then. Why use a timer?