Jump to content
RAGE Multiplayer Community

Command cooldowns


fl1k
 Share

Recommended Posts

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...