Created
April 24, 2019 17:35
-
-
Save romgerman/6b8184ec30dce88e981f718a6baa5070 to your computer and use it in GitHub Desktop.
Untested cmd cooldown class for Rust (game)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static class CmdCooldown { | |
public static Dictionary<string, Dictionary<IPlayer, TimeSpan>> Players = new Dictionary<string, Dictionary<IPlayer, TimeSpan>>(); | |
public static bool CanUse(IPlayer player, TimeSpan cooldown, [CallerMemberName] string name = null) | |
{ | |
if (!Players.ContainsKey(name)) | |
{ | |
Players.Add(name, new Dictionary<IPlayer, TimeSpan>()); | |
return true; | |
} | |
if (!Players[name].ContainsKey(player)) | |
{ | |
Players[name].Add(player, DateTime.Now.TimeOfDay); | |
return true; | |
} | |
return Players[name][player] >= cooldown; | |
} | |
} | |
[Command("test")] | |
private void TestCommand(IPlayer player, string command, string[] args) | |
{ | |
if (!CmdCooldown.CanUse(player, TimeSpan.FromMinutes(10))) | |
return; | |
player.Reply("Test successful!"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment