SA-MP Forums Archive
Code causes lagg. - 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: Code causes lagg. (/showthread.php?tid=183411)



Code causes lagg. - Danny - 15.10.2010

Hello,
It's been a while ago since ive created this time-script, but today i really noticed that it gives some annoying lagg sometimes. I have set the timer to 2000 milliseconds. This is my code:

Код:
public Worldtime() {
	if(Minutes < 60) {
	    Minutes += 1;
	    SyncPlayerTime();
 	} else {
		if(Hours < 23) {
  			Hours += 1;
  			Minutes = 0;
  			SetWorldTime(Hours);
			SyncPlayerTime();
		} else {
	    	Hours = 0;
	    	Minutes = 0;
	    	SetWorldTime(Hours);
	    	SyncPlayerTime();
	    }
	}
}

public SyncPlayerTime() {
	for(new i=0; i<MAX_PLAYERS; i++) {
 		if(IsPlayerConnected(i)) {
 	  		SetPlayerTime(i,Hours,Minutes);
		}
	}
}
Does anyone see whats the laggy part, and how can i change it to minimalize/remove the lagg?

Greetz,
Danny


Re: Code causes lagg. - Mike Garber - 15.10.2010

And are you running Worldtime as a timer? If so, show me your SetTimer code.


Re: Code causes lagg. - Relixious - 15.10.2010

Eugh i cannot ready your code it's too busy, i'm sorry, please use correct identation next time:

Код:
public Worldtime()
{
    if(Minutes < 60)
    {
        Minutes += 1;
        SyncPlayerTime();
    }
    else
    {
        if(Hours < 23)
        {
            Hours += 1;
            Minutes = 0;
            SetWorldTime(Hours);
            SyncPlayerTime();
        } 
        else 
        {
            Hours = 0;
            Minutes = 0;
            SetWorldTime(Hours);
            SyncPlayerTime();
        }
    }
}

public SyncPlayerTime()
{
    for(new i=0; i<MAX_PLAYERS; i++)
    {
        if(IsPlayerConnected(i))
            SetPlayerTime(i,Hours,Minutes);
    }
}
Can you check if the lags begins to show up every 60 seconds?


Re: Code causes lagg. - Danny - 16.10.2010

@Mike:

Its underneath OnGameModeInIt:

Код:
SetTimer("Worldtime",MINUTE_INTERVAL,1);
The minute interval is 2000 millisecs aka 2 mins

@Relixious:
Sorry, i indentify my code on that way to reduce the file size (at least im trying to do that )
And the lagg is contant, it doesent show up every 2 mins.


Re: Code causes lagg. - Danny - 20.10.2010

Bump, still not solved.


Re: Code causes lagg. - legodude - 20.10.2010

the minute interval is 2000 millisecs aka 2 mins

2000 millisecs is 2 secs...
120000 is 2 mins

or do the define like 2*1000*60


Re: Code causes lagg. - DeathOnaStick - 20.10.2010

Quote:
Originally Posted by legodude
Посмотреть сообщение
the minute interval is 2000 millisecs aka 2 mins

2000 millisecs is 2 secs...
120000 is 2 mins

or do the define like 2*1000*60
I'd do it like this:

pawn Код:
#define MINUTE_INTERVAL 2
SetTimer("Worldtime",((MINUTE_INTERVAL*1000)*60),1); //2ms * 1000 = 2s | 2s * 60 = 2min



Re: Code causes lagg. - nemesis- - 20.10.2010

Quote:
Originally Posted by -Danny-
Посмотреть сообщение
@Mike:

Its underneath OnGameModeInIt:

Код:
SetTimer("Worldtime",MINUTE_INTERVAL,1);
The minute interval is 2000 millisecs aka 2 mins

@Relixious:
Sorry, i indentify my code on that way to reduce the file size (at least im trying to do that )
And the lagg is contant, it doesent show up every 2 mins.
Reducing the size of your .pwn does not reduce the size of your .amx - unless of course we're talking more efficient code.