So you need to freeze the player and trigger a timer that will unfreeze them in 5 seconds correct?
Try breaking down your objective, ask yourself questions and try to answer them, do some research, stop being lazy and ask direct questions.
Код:
* [QUESTION]: When should I freeze the player?
> [ANSWER]: I should freeze the player when they enter a checkpoint.
* [QUESTION]: How do I detect if a player enters a checkpoint?
> [ANSWER]: There is a native callback for that, OnPlayerEnterCheckpoint
this callback is triggered whenever a player enters a checkpoint, meaning, all the code you want to execute when a player enters a checkpoint should be written inside this callback.
PHP код:
public OnPlayerEnterCheckpoint(playerid)
{
//Code here
return 1;
}
Код:
* [QUESTION]: Ok, now that entering a checkpoint is detected, how do I freeze them?
> [ANSWER]: There is a native function for that too, TogglePlayerControllable
* [QUESTION]: Alright, so where should I put that function?
> [ANSWER]: Did you forget? all the code that you want to be executed when the player enters to a checkpoint should be written in the callback above.
PHP код:
public OnPlayerEnterCheckpoint(playerid)
{
TogglePlayerControllable(playerid, false); //setting 0 here works too.
return 1;
}
Код:
* [QUESTION]: So now that I froze the player, how to auto unfreeze them after 5 seconds?
> [ANSWER] Here were timers come into play, timers are basically functions that trigger an action after a certain time. in order to start a timer, use the function SetTimerEx.
PHP код:
public OnPlayerEnterCheckpoint(playerid)
{
TogglePlayerControllable(playerid, false); //setting 0 here works too.
SetTimerEx("Timer_Unfreeze", 5000, false, "i", playerid);
return 1;
}
that may sound compilated at first glance, but trust me it's not
Код:
"Timer_Unfreeze" - This is the function we want to trigger when the timer ends
5000 - this indicates when the timer will end on milliseconds, in this case, the timer will stop after 5 seconds, 5 * 1000
false - This tells the timer whether it should play repeatedly (will start all over again once it finishes) or not, false means it won't be repeated, and vice versa.
"i" - the data type that we will pass to the function Timer_Unfreeze, in this case, a number, must always be between quotation marks.
playerid - The value we want to pass to the function Timer_Unfreeze, in this case, the player's ID (0, 1, 23...)
Now that we created the timer and set it to stop after 5 seconds, we need to create the function Timer_Unfreeze that would be called then.
PHP код:
public OnPlayerEnterCheckpoint(playerid)
{
TogglePlayerControllable(playerid, false); //setting 0 here works too.
SetTimerEx("Timer_Unfreeze", 5000, false, "i", playerid);
return 1;
}
forward Timer_Unfreeze(playerid);
public Timer_Unfreeze(playerid)
{
//Code here.
}
Yes, it's mandatory that you forward it, notice that the Timer_Unfreeze function has the same parameter we passed at SetTimerEx("Timer_Unfreeze", 5000, false,
"i", playerid);, it doesn't have to be called playerid too, as long as it has the same datatype.
Now, inside the Timer_Unfreeze function, you should Unfreeze the player,
Код:
* [QUESTION]: But how to do that? is it similar to how we froze him in the first place?
> [ANSWER]: Yes it is, we just have to change the false to true, (or 0 to 1)
PHP код:
public OnPlayerEnterCheckpoint(playerid)
{
TogglePlayerControllable(playerid, false); //setting 0 here works too.
SetTimerEx("Timer_Unfreeze", 5000, false, "i", playerid);
return 1;
}
forward Timer_Unfreeze(playerid);
public Timer_Unfreeze(playerid)
{
TogglePlayerControllable(playerid, true); //setting 1 here works too.
}
There you have it, try working out on your algorithms this way, and hopefully you'll get there.
bu the way, this will freeze players whenever they enter a checkpoint, it will work on all the checkpoints, in case you want to specify this action to only a certain checkpoint, you should verify the checkpoint the player entered first before doing all of that under
OnPlayerEnterCheckpoint.