Checking for timer at 0 -
Joshb93 - 20.11.2011
If i use this
SetTimer("PressJump", 15000, 0);
what "if" statement do i use to check if that timer is at "0"??
Re: Checking for timer at 0 -
antonio112 - 20.11.2011
Well, you need a new function for that:
pawn Код:
SetTimer("PressJump", 15000, 0);
forward PressJump();
public PressJump()
{
print("Timer ended");
}
Or you can use
SetTimerEx for every player:
pawn Код:
SetTimerEx("PressJump", 15000, false, "i", playerid);
forward PressJump(playerid);
public PressJump(playerid)
{
SendClientMessage(playerid, -1, "The timer ended.");
}
So basically, whatever you want to happen when the timer ends, you put it in the "PressJump" function and that'll happen when the timer end occurs.
Re: Checking for timer at 0 -
Joshb93 - 20.11.2011
That did not answer my question, im asking what "if" statement could i use
such as
if(PressJump == 0) or something like that
Код:
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
if(newkeys & KEY_JUMP)
{
PlayerPressedJump[playerid] ++;
if(PlayerPressedJump[playerid] == 3) // change 5 to whatever number of jumps you want
{
ApplyAnimation(playerid, "PED", "BIKE_fall_off", 4.1, 0, 1, 1, 1, 0, 1);
SetTimerEx("PressJump", 15000, false, "i", playerid);
}
IF STATEMENT HERE
{
PlayerPressedJump[playerid] = 0; // Reset the variable
ClearAnimations(playerid);
}
}
}
return 1;
}
I want the if statement to check if the timer is 0 so it completes the following task
Re: Checking for timer at 0 - [L3th4l] - 20.11.2011
When the timer is over, it's basically 0.. Unless you want to create another variable to track the timer's seconds which is useless.
So, you will need something like this:
pawn Код:
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
if(newkeys & KEY_JUMP)
{
PlayerPressedJump[playerid] ++;
if(PlayerPressedJump[playerid] == 3) // change 5 to whatever number of jumps you want
{
ApplyAnimation(playerid, "PED", "BIKE_fall_off", 4.1, 0, 1, 1, 1, 0, 1);
SetTimerEx("PressJump", 15000, false, "i", playerid); // When the timer reaches 0, we move to the callback "PressJump"
}
}
return 1;
}
forward PressJump(playerid); // Timer is over.
public PressJump(playerid)
{
PlayerPressedJump[playerid] = 0; // Reset the variable
ClearAnimations(playerid);
return 1;
}
So basically, the "if" check is not necessary in this case.
Re: Checking for timer at 0 -
cessil - 20.11.2011
he did answer your question, your SetTimer will trigger the function PressJump when it reaches 0 you need to place your code in there
Re: Checking for timer at 0 -
antonio112 - 20.11.2011
I got your question now ... but like
[L3th4l] &
cessil already told you, I already answered your question. Why would you want to check if a timer is 0 ? What do you want to achive here? Maybe we can help you further more if you detail what you want to do...