Better approach than using timersSolved
Hey there, nice plugin!

May I suggest using a different approach for cooldowns? Yours currently only decrements the cooldown timer while the player is logged in and has to maintain timers for every player logged into the server.

I modified the plugin on my server by bypassing the LetsClock() method entirely and modified the SpawnMyMincopterChatCommand() method like this:

        [ChatCommand("minicopter")]
        private void SpawnMyMinicopterChatCommand(BasePlayer player, string command, string[] args)
        {
            var t = new TimeSpan();
            t = DateTime.UtcNow - new DateTime(1970, 1, 1);
            int secondsSinceEpoch = (int)t.TotalSeconds;
 
            bool isspawner = permission.UserHasPermission(player.UserIDString, MinicopterSpawn);
            if (isspawner == false)
            {
                Player.Message(player, lang.GetMessage("NoPermMsg", this, player.UserIDString), Prefix, SteamIDIcon);
                return;
            }
            if (storedData.playerminiID.ContainsKey(player.userID) == true)
            {
                Player.Message(player, lang.GetMessage("AlreadyMsg", this, player.UserIDString), Prefix, SteamIDIcon);
                return;
            }
            bool hascooldown = permission.UserHasPermission(player.UserIDString, MinicopterCooldown);
            float minleft = 0;
            if (hascooldown == true)
            {
                if (storedData.playercounter.ContainsKey(player.userID) == false)
                {
                        storedData.playercounter.Add(player.userID, secondsSinceEpoch);
                }
                else
                {
                    float count = new float();
                    storedData.playercounter.TryGetValue(player.userID, out count);
                    minleft = cooldownmin - ((secondsSinceEpoch - count) / 60);
                    if (debug) Puts($"Player DID NOT reach cooldown return.");
                    Player.Message(player, $"{lang.GetMessage("CooldownMsg", this, player.UserIDString)} ({minleft} min)", Prefix, SteamIDIcon);
                    return;
                }
            }
            else
            {
                if (storedData.playercounter.ContainsKey(player.userID))
                {
                    storedData.playercounter.Remove(player.userID);
                }
            }
            SpawnMyMinicopter(player);
        }
 


Merged post

I also added the System include to allow the use of DateTime (using System;)

Merged post

Oof, I can't edit but the code above has a flaw.  Try this instead.


        [ChatCommand("minicopter")]
        private void SpawnMyMinicopterChatCommand(BasePlayer player, string command, string[] args)
        {
            var t = new TimeSpan();
            t = DateTime.UtcNow - new DateTime(1970, 1, 1);
            int secondsSinceEpoch = (int)t.TotalSeconds;
 
            bool isspawner = permission.UserHasPermission(player.UserIDString, MinicopterSpawn);
            if (isspawner == false)
            {
                Player.Message(player, lang.GetMessage("NoPermMsg", this, player.UserIDString), Prefix, SteamIDIcon);
                return;
            }
            if (storedData.playerminiID.ContainsKey(player.userID) == true)
            {
                Player.Message(player, lang.GetMessage("AlreadyMsg", this, player.UserIDString), Prefix, SteamIDIcon);
                return;
            }
            bool hascooldown = permission.UserHasPermission(player.UserIDString, MinicopterCooldown);
            float minleft = 0;
            if (hascooldown == true)
            {
                if (storedData.playercounter.ContainsKey(player.userID) == false)
                {
                        storedData.playercounter.Add(player.userID, secondsSinceEpoch);
                }
                else
                {
                    float count = new float();
                    storedData.playercounter.TryGetValue(player.userID, out count);
                    minleft = cooldownmin - ((secondsSinceEpoch - count) / 60);
                    if (debug) Puts($"Player DID NOT reach cooldown return.");
                    if (minleft >= 0.0)
                    {
                        Player.Message(player, $"{lang.GetMessage("CooldownMsg", this, player.UserIDString)} ({minleft} min)", Prefix, SteamIDIcon);
                        return;
                    }
                    else
                    {
                        storedData.playercounter.Remove(player.userID);
                    }
                }
            }
            else
            {
                if (storedData.playercounter.ContainsKey(player.userID))
                {
                    storedData.playercounter.Remove(player.userID);
                }
            }
            SpawnMyMinicopter(player);
        }
 
Hey ! Thanks for your suggestion !
keep on coding !
This has been implemented in 0.0.4, hopefully correctly.
Locked automatically