fl1k Posted August 23, 2021 Posted August 23, 2021 What's the correct way of doing them? I'm using C#.
sparx Posted August 30, 2021 Posted August 30, 2021 The best option will likely be to store the timestamp (Ideally UNIX Timestamps) of when the player issued the command, and calculate that against your cooldown amount for the specific command. Player issues the command for /heal - UNIX timestamp saved (1630347503) Command structure allocates a 10 second cooldown for the /heal command. User issues the command again - Check current UNIX timestamp (1630347717) and minus against the saved time (1630347503) 214 is the result which is > than 10 seconds, allow command execution. You could also potentially mess with timers, but having X amount of timers running simultaneously for X amount of players with X amount of commands can add a lot of bloat. Mathematical calculations are much faster. There are of course so many other ways you can do this, but this'll likely be the most simple to implement. Another point is, you don't always have to use UNIX. There are many DateTime calculators out there for C# if you wish to use those. You can also use co-routines in C#, but then again questions on performance needs to be weighed out.
fl1k Posted August 30, 2021 Author Posted August 30, 2021 4 hours ago, sparx said: The best option will likely be to store the timestamp (Ideally UNIX Timestamps) of when the player issued the command, and calculate that against your cooldown amount for the specific command. Player issues the command for /heal - UNIX timestamp saved (1630347503) Command structure allocates a 10 second cooldown for the /heal command. User issues the command again - Check current UNIX timestamp (1630347717) and minus against the saved time (1630347503) 214 is the result which is > than 10 seconds, allow command execution. You could also potentially mess with timers, but having X amount of timers running simultaneously for X amount of players with X amount of commands can add a lot of bloat. Mathematical calculations are much faster. There are of course so many other ways you can do this, but this'll likely be the most simple to implement. Another point is, you don't always have to use UNIX. There are many DateTime calculators out there for C# if you wish to use those. You can also use co-routines in C#, but then again questions on performance needs to be weighed out. Thank you. Solved
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now