I'm making a private plugin and wondering how to use a timer, I'm trying to use it for a warp countdown, and then a cancel command to stop it. How would i do that?
Using a timer as a countdown?Solved
Take a look at the Timer docs if you haven't already.
https://umod.org/documentation/api/timers
Assuming each player will have a separate active warp timer, you can save each player's timer in a dictionary (as a field of the plugin instance), so that you can find the timer later when the player runs the command to cancel.
https://umod.org/documentation/api/timers
Assuming each player will have a separate active warp timer, you can save each player's timer in a dictionary (as a field of the plugin instance), so that you can find the timer later when the player runs the command to cancel.
oh cheers i found that and was wonding how to use it.
A rough, untested example:
int countdown = 10;
timer.Repeat(1f, countdown, () =>
{
server.Broadcast($"Teleporting in... {countdown} seconds");
if (countdown == 0)
{
server.Command("tpcancel");
}
countdown--;
}); Wulf
A rough, untested example:
Error while compiling: Rustov.cs(45,38): error CS1503: Argument `#2' cannot convert `float' expression to type `int'
Thats the error i get with it.
Updated my example for the plugin I am writing for you. :P
cheers
Locked automatically