SA-MP Forums Archive
Timers - 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 (/showthread.php?tid=72771)



Timers - streetzuk - 10.04.2009

Hey everyone.

I have searched for similar problems to which i am having but can not get any useful information from them.

All the timers i do are not repeated so they do their job once and thats it. But the problem i am having is when they do something like send a client message, it will send it 10-15 times instead of once.

This is causing lag and i am not happy with the system im making because of this.

Here is an example timer:
Code:
public PowerOverride()
{
	for(new i = 0; i < MAX_PLAYERS; i ++) {
	if(gTeam[i] == TEAM_TERRORIST && PlantingC4[i] == 1) {

             CreateExplosion(928.0627, 2523.3984, 10.8203, 2, 10.0); // Explosion 1
		CreateExplosion(934.5035, 2522.9822, 13.2188, 2, 10.0); // Explosion 2
		CreateExplosion(939.7049, 2524.6848, 10.8203, 2, 10.0); // Explosion 3
		CreateExplosion(945.2598, 2521.1301, 14.4470, 2, 10.0); // Explosion 4
		CreateExplosion(925.4567, 2519.6956, 10.8203, 2, 10.0); // Explosion 5
		SendClientMessage(i, COLOR_INFO_BLUE, "Test1");
		SetTimer("PowerDown", 2000, false);
	}
	}
	
	return 1;
}



Re: Timers - Weirdosport - 10.04.2009

Try using 0 instead of false.

BLAH ignore that, it's because you're sending the timer as many times as you have Terrorists! And you're sending as many SendClientMessage as there are TEAM_TERRORIST's


Re: Timers - streetzuk - 10.04.2009

I have tried editing a few lines out. According to the wiki what i have done is fine, however the explosions and client messages still display more than once.

Code:
public PS_Explosion()
{
	for(new i; i<MAX_PLAYERS; i++) {
    CreateExplosion(928.0627, 2523.3984, 10.8203, 2, 10.0); // Explosion 1
		CreateExplosion(934.5035, 2522.9822, 13.2188, 2, 10.0); // Explosion 2
		CreateExplosion(939.7049, 2524.6848, 10.8203, 2, 10.0); // Explosion 3
		CreateExplosion(945.2598, 2521.1301, 14.4470, 2, 10.0); // Explosion 4
		CreateExplosion(925.4567, 2519.6956, 10.8203, 2, 10.0); // Explosion 5
		SendClientMessage(i, COLOR_INFO_BLUE, "Boom Test");
		SetTimer("PS_Disarmed", 2000, false);
	}
}
If any one has a solution to this problem, it will be appreciated.

Thank you.


Re: Timers - Robbin237 - 11.04.2009

What you are doing, is making a loop, and making it run while its below the maximum players.
Each time at the end of the loop it will send the client message.


Try this code:

Code:
public PS_Explosion()
{
	for(new i; i<MAX_PLAYERS; i++) {
       CreateExplosion(928.0627, 2523.3984, 10.8203, 2, 10.0); // Explosion 1
		CreateExplosion(934.5035, 2522.9822, 13.2188, 2, 10.0); // Explosion 2
		CreateExplosion(939.7049, 2524.6848, 10.8203, 2, 10.0); // Explosion 3
		CreateExplosion(945.2598, 2521.1301, 14.4470, 2, 10.0); // Explosion 4
		CreateExplosion(925.4567, 2519.6956, 10.8203, 2, 10.0); // Explosion 5
		SetTimer("PS_Disarmed", 2000, false);
	}
	SendClientMessage(i, COLOR_INFO_BLUE, "Boom Test");
}
Your code:
Code:
public PS_Explosion()
{
	for(new i; i<MAX_PLAYERS; i++) {
       CreateExplosion(928.0627, 2523.3984, 10.8203, 2, 10.0); // Explosion 1
		CreateExplosion(934.5035, 2522.9822, 13.2188, 2, 10.0); // Explosion 2
		CreateExplosion(939.7049, 2524.6848, 10.8203, 2, 10.0); // Explosion 3
		CreateExplosion(945.2598, 2521.1301, 14.4470, 2, 10.0); // Explosion 4
		CreateExplosion(925.4567, 2519.6956, 10.8203, 2, 10.0); // Explosion 5
		SendClientMessage(i, COLOR_INFO_BLUE, "Boom Test");
		SetTimer("PS_Disarmed", 2000, false);
	}
}



Re: Timers - ICECOLDKILLAK8 - 11.04.2009

pawn Code:
public PS_Explosion()
{
     for(new i; i < MAX_PLAYERS; i++)
     {
       if(IsPlayerConnected(i))
       {
           CreateExplosion(928.0627, 2523.3984, 10.8203, 2, 10.0); // Explosion 1
           CreateExplosion(934.5035, 2522.9822, 13.2188, 2, 10.0); // Explosion 2
           CreateExplosion(939.7049, 2524.6848, 10.8203, 2, 10.0); // Explosion 3
           CreateExplosion(945.2598, 2521.1301, 14.4470, 2, 10.0); // Explosion 4
           CreateExplosion(925.4567, 2519.6956, 10.8203, 2, 10.0); // Explosion 5
          SendClientMessage(i, COLOR_INFO_BLUE, "Boom Test");
       }
     }
     SetTimer("PS_Disarmed", 2000, false);
}
And Robbin237 learn how to script


Re: Timers - Nubotron - 11.04.2009

Why do you call <MAX_PLAYERS> times SetTimer("PS_Disarmed", 2000, false) ? ;s


Re: Timers - ICECOLDKILLAK8 - 11.04.2009

What is your PS_Disarmed code?


Re: Timers - streetzuk - 11.04.2009

Code:
public PS_Disarmed()
{
	for(new i; i<MAX_PLAYERS; i++) {
		SendClientMessage(i, COLOR_INFO_BLUE, "The deffence systems are temporarily damaged.");
		MoveObject(28, 997.145020, 2461.025391, 11.509213, 0.5);
		MoveObject(29, 997.147400, 2480.988281, 11.507965, 0.5);
		PS_Variable [i] =1;
		SetTimer("PS_Armed", 300000, false);
	}
}
Still seems to set the explosions off many times and the client messages still spam and eventually crash the server.


Re: Timers - ICECOLDKILLAK8 - 11.04.2009

Just use this instead of a loop
pawn Code:
SendClientMessageToAll(...);
CreateExplosion(...);
SetTimer(...);
OtherFunctions(...);



Re: Timers - Nubotron - 11.04.2009

Do you know what is a for loop?