[HELP]How to make a timer.works as per cmd
#1

Hi , I made a race cmd using zcmd..

And I want a timer like if someone starts the /race the tele must be on oy for 30 seconds that the cmd must be false until the race ends.. give me explanation , and I learn it , Thanks.
Reply
#2

pawn Код:
new bool:MyBoolean; // Declare "MyBoolean" as a boolean
CMD:race(playerid, params[])
{
    MyBoolean = false; // Sets "MyBoolean" to false
    SetTimer("MyPublic", 30000, false);
    // "MyPublic" is the public we call when the timer ends
    // "30000" is the time before the timer ends in milliseconds, 1 second = 1000 ms
    // "false" a boolean to toggle if the timer should repeat itself, or not, for this it shouldn't repeat, just play once
}
Pretty simple, now the callback is just as simple:
pawn Код:
forward MyPublic(); // Forwards "MyPublic" as a public function
public MyPublic() // Creates "MyPublic" as a public function, which the timer will call when it ends
{
    MyBoolean = true; // Sets "MyBoolean" to true
}
Reply
#3

Why we use a call back and why we set Myboolen true there? Can you explain that more briefly?
Reply
#4

Well the timer has to execute some kind of code when it finishes, and as described on the wiki, timers can only call public functions.

And as you said it should be set to false untill the race ends (the 30 seconds) so after that, i set it to true.
You can ofcourse just do whatever you want in the public function, that's just an example with a boolean, it's set to false for 30 seconds when you used the command.

Then the timer calls the public function, which sets the boolean to true, untill you use the command again.
Reply
#5

Quote:
Originally Posted by fuckingcruse
Посмотреть сообщение
Why we use a call back and why we set Myboolen true there? Can you explain that more briefly?
The boolean is just an example and regarding to the other question, that's just how the syntax is, it calls the public function once the timer is executed to perform actions.
Reply
#6

Dude , you misunderstood me., when someone type /race , all thw players who type /race will be spawned , I made that , but they can only type /race under the 30 seconds , and after the race is finished again they can type /race .. you thought that after the /race after 30 seconds they can type /race again..
Reply
#7

So you want players to only be able to use /race in the 30 seconds?
Well how would you start the 30 seconds then, if the /race does so?
I can't really understand you.
Reply
#8

Let's talk in PM..
Reply
#9

If you give us the /race command, I will try to adjust it to your question.
Otherwise, you should use foreach command after the race is finished to reset all race players race command variables for ex:
pawn Код:
cmd:race(playerid, params[])
{
     if(InRace[playerid]) return SendClientMessage(playerid, COLOR_WHITE, "You are racing, wait untill its finished");
     InRace[playerid] = 1;
}
when race is finished:
Код:
foreach(Player, playerid)
{
     InRace[playerid] = 0;
}
If you them to be able to use /race only for first 30 seconds, then make 2 command
1) startrace (or any other way to start a race, a timer maybe)
2) joinrace
while start race will make timer for 30 seconds to be able to join races. if the global timer ended, return the variable who let people join the race to 0;

Thats how i understand the problem you are having, If you want further help send the commnad /race.
Reply
#10

Quote:
Originally Posted by fuckingcruse
Посмотреть сообщение
Dude , you misunderstood me., when someone type /race , all thw players who type /race will be spawned , I made that , but they can only type /race under the 30 seconds , and after the race is finished again they can type /race .. you thought that after the /race after 30 seconds they can type /race again..
Well, I do as follows and it works well. All you need is to define two booleans and a simple timer.

Код:
new bool:racestart = false;  // if true blocks /race for everybody
new bool:timerset = false;  // needed for starting timer only once

forward RaceTimer();

public RaceTimer()
{
	racestart = true;
	timerset = false;
}
In your command start testing the booleans:

Код:
CMD:race(playerid, params[])
{
	// test if is valid playerid & params
	//...
	if (racestart) SendClientMessage(playerid,-1,"Sorry, race's started!");
	if (!timerset)
	{
		SetTimer("RaceTimer",30000,false);
		timerset = true;
	}
	// the rest of your command here
	//...
	return 1;
}
When your race ends don't forget to reset racestart:

Код:
racestart = false;
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)