Checking for timer at 0
#1

If i use this

SetTimer("PressJump", 15000, 0);

what "if" statement do i use to check if that timer is at "0"??
Reply
#2

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.
Reply
#3

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
Reply
#4

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.
Reply
#5

he did answer your question, your SetTimer will trigger the function PressJump when it reaches 0 you need to place your code in there
Reply
#6

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...
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)