Posts: 709
Threads: 54
Joined: Jul 2010
Reputation:
0
OK, i need Help, Can i Set 1 Timer, on a cmd, Then The SAME timer That i set be used again?
Posts: 2,502
Threads: 26
Joined: Apr 2007
Reputation:
0
I'm not sure what you mean, do you mean the timer to repeat? Simply specify that you want it to repeat in the parameters of the function if that's the case, otherwise please give some more detail.
Posts: 1,733
Threads: 20
Joined: Nov 2010
Reputation:
0
You mean that you create one timer-function and that you can create multiple instances of it?
If that's the case, then yes, you can create one function that runs the code for the timer and create multiple instances for it using SetTimer or SetTimerEx.
That's how speedometers work for example.
For every player, there is a timer running in the background that updates the speedometer for each player.
But there is only one function declared, like:
Public Speedometer_Update(playerid)
{
// code to update speedometer here
}
This function can be used for each player.
Posts: 709
Threads: 54
Joined: Jul 2010
Reputation:
0
Ok, Say i have a /die Command, i Set a timer for it,
I wanna Use this Same Timer for a other Command, Is that possiable?
Posts: 2,502
Threads: 26
Joined: Apr 2007
Reputation:
0
Yes, why wouldn't it be? I assume you've tried it already and there were problems, so what kind of problems did you encounter?
Posts: 709
Threads: 54
Joined: Jul 2010
Reputation:
0
Will It Work?, im not ready to test, i just wanna know if it will work.
Posts: 1,733
Threads: 20
Joined: Nov 2010
Reputation:
0
If you set a timer in the /die command, you'll use something like this:
SetTimerEx("KillPlayer", 500, false, "i", playerid);
Then there should be a function:
Public KillPlayer(playerid)
{
// Kill the player here by code
}
The above timer (SetTimerEx("KillPlayer", ...) executes this function "KillPlayer" with "playerid" as integer parameter ("i").
The function is executed half a second after the /die command is entered into the chatbox.
When you would set the exact same timer to let a player jump (using /jump command), it would execute the "KillPlayer" function, which would be wrong of course.
So you'll need to do
SetTimerEx("JumpPlayer", 500, false, "i", playerid);
for your jump-command, which executes this function:
Public JumpPlayer(playerid)
{
// Code to jump
}
A timer is basically a function that's delayed in execution.
You can't make a function do 2 different things based on the command that's executed, unless you code it like that using a switch-case statement.