forward Freeze(playerid);
public Freeze(playerid)
{
TogglePlayerControllable(playerid,1);
}
TogglePlayerControllable(playerid,0);
SetTimerEx("Freeze", 5000, false, "i", playerid);
Add this on top of your script
PHP код:
PHP код:
|
How to make it when a player enters a checkpoint to freeze it for 5 seconds, for example?
|
* [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.
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.
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.
public OnPlayerEnterCheckpoint(playerid)
{
TogglePlayerControllable(playerid, false); //setting 0 here works too.
SetTimerEx("Timer_Unfreeze", 5000, false, "i", playerid);
return 1;
}
"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...)
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.
}
* [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)
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.
}