1. You really should use Visual Studio, it will help make your coding look so much cleaner and point out a lot of small mistakes that can be done when writing. Particularly will help when you set up all your references.
    Would be useful to read through other plugins to see how they are laid out too. Generally the more recent ones are good and Wulf's are usually well written like Godmode.
     
  2. it appears when you reconnect the cooldown has gone, so i guess it needs a datafile
    [DOUBLEPOST=1498394363][/DOUBLEPOST]
    i have asked, i have offered money to get get i need but it seems that its a cooldown then its a problem with finding players as you have to type the whole name. and then what i have disconnect and the cooldown is reset.
     
  3. You shouldn't need a datafile for this. Only time you need that is when you need information of a player when they are offline or to keep data through restarts.
     
    Last edited by a moderator: Jun 25, 2017
  4. Actually your code is a bit wrong
    Code:
            [ChatCommand("nuke")]
            void chatNuke(BasePlayer player, string command, string[] args) {
                if (permission.UserHasPermission(player.UserIDString, "nukeplayer.use"))
                {
                    if (!Cooldowns.Contains(player.userID))
                        //Check if the player is listed in the HashSet "Cooldowns", if not continue
                    {
                        Cooldowns.Add(player.userID);
                            //Add the player to the Cooldowns HashSet so they cannot run the command again until removed
                        timer.Once(configFile.Cooldown, () => Cooldowns.Remove(player.userID));
                            //Create and start a timer for 10 seconds, when it expires remove the player from the Cooldowns HashSet
                    }
                    else
                        SendReply(player, "Cooldown in effect.");
                            //If the player is in the Cooldowns HashSet send this chat message to them
                }
                else
                {
                    var foundPlayer = rust.FindPlayer(args[0]);
                    if (foundPlayer == null)
                    {
                        PrintToChat(player, $"We couldn't find a player named {args[0]}");
                        return;
                    }
                    else
                    {
                        DoNuke(foundPlayer);
                    }
                }
            }
    In this you are checking if the player get the perm to launch a nuke, if he has you are checking for hashset, if they are not you are putting him in the hashset and nothing else.
    If the player didn't get perm, you are checking for name then doing nuke.
    You should put the nuke thing into the perm check.
     
  5. ok... copy that and it dont work..
    [DOUBLEPOST=1498412993][/DOUBLEPOST]added


    DoNuke(foundPlayer);
    SendReply(player, "nuked.");
    }
    }
    }

    and its not getting to this at ll after the command has been used.
     
  6. I didn't edited your code, i just pointed to you what was wrong by posting your code above.
     
  7. This is my personal method, as DateTime/TimeSpan variables work very well. Basically, I have a TimeSpan declared at the top, TimeSpans are the result of subtracting 2 date times. So, I log the time the player uses the command, then I check if their next time of use minus their last time is greater than the TimeSpan, if so I allow them to use the command.
    Code:
            private TimeSpan cooldown = new TimeSpan(0, 1, 0);
            private Dictionary<BasePlayer, DateTime> useTimes = new Dictionary<BasePlayer, DateTime>();        [ChatCommand("test")]
            private void TestCommand(BasePlayer player, string command, string[] args)
            {
                if (useTimes.ContainsKey(player))
                {
                    if (DateTime.UtcNow - useTimes[player] > cooldown)
                    {
                        PrintToChat(player, "Your cooldown expired, you may use this command.");
                        useTimes[player] = DateTime.UtcNow;
                        return;
                    }
                 
                    PrintToChat(player, $"Error, that command is on cooldown for {useTimes[player]}.");
                    return;
                }            useTimes.Add(player, DateTime.UtcNow);
                PrintToChat(player, "You have been added to the <i>useTimes</i> list, you will be able to use this command again in one hour.");
             
                // Chat command after this
            }
    Note, for longer cooldowns you may need a data file, that will make it so cooldowns persist when the plugin is reloaded.
     
    Last edited by a moderator: Jun 26, 2017
  8. Well this is what was ment to be but now it cant find players

    Code:
    Failed to call hook 'chatNuke' on plugin 'NukePlayer v1.0.0' (IndexOutOfRangeException: Array index is out of range.)
      at Oxide.Plugins.NukePlayer.chatNuke (.BasePlayer player, System.String command, System.String[] args) [0x00000] in <filename unknown>:0
      at Oxide.Plugins.NukePlayer.DirectCallHook (System.String name, System.Object& ret, System.Object[] args) [0x00000] in <filename unknown>:0
      at Oxide.Plugins.CSharpPlugin.InvokeMethod (HookMethod method, System.Object[] args) [0x00000] in <filename unknown>:0
      at Oxide.Core.Plugins.CSPlugin.OnCallHook (System.String name, System.Object[] args) [0x00000] in <filename unknown>:0
      at Oxide.Core.Plugins.Plugin.CallHook (System.String hook, System.Object[] args) [0x00000] in <filename unknown>:0
    Failed to call hook 'chatNuke' on plugin 'NukePlayer v1.0.0' (IndexOutOfRangeException: Array index is out of range.)
      at Oxide.Plugins.NukePlayer.chatNuke (.BasePlayer player, System.String command, System.String[] args) [0x00000] in <filename unknown>:0
      at Oxide.Plugins.NukePlayer.DirectCallHook (System.String name, System.Object& ret, System.Object[] args) [0x00000] in <filename unknown>:0
      at Oxide.Plugins.CSharpPlugin.InvokeMethod (HookMethod method, System.Object[] args) [0x00000] in <filename unknown>:0
      at Oxide.Core.Plugins.CSPlugin.OnCallHook (System.String name, System.Object[] args) [0x00000] in <filename unknown>:0
      at Oxide.Core.Plugins.Plugin.CallHook (System.String hook, System.Object[] args) [0x00000] in <filename unknown>:0 
    Code:
            [ChatCommand("nuke")]
            void chatNuke(BasePlayer player, string command, string[] args)
            {
                if (permission.UserHasPermission(player.UserIDString, "nukeplayer.use"))
                {
                    if (!Cooldowns.Contains(player.userID))
                    //Check if the player is listed in the HashSet "Cooldowns", if not continue
                    {
                        Cooldowns.Add(player.userID);
                        //Add the player to the Cooldowns HashSet so they cannot run the command again until removed
                        timer.Once(configFile.Cooldown, () => Cooldowns.Remove(player.userID));
                        //Create and start a timer for 10 seconds, when it expires remove the player from the Cooldowns HashSet
                    }
                    var foundPlayer = rust.FindPlayer(args[0]);
                    if (foundPlayer == null)
                    {PrintToChat(player, $"We couldn't find a player named {args[0]}");
                        return;
                    }
                    else
                    {
                        DoNuke(foundPlayer);
                        SendReply(player, "nuked.");
                    }
                }
                else
                {
                    SendReply(player, "Cooldown in effect.");
                    //If the player is in the Cooldowns HashSet send this chat message to them
                }
            }
     
  9. You've been presented with many methods, all of which are valid takes on the question. I suggest you read the posts carefully and look at it, also code with an IDE!
     
  10. yes and the problem i have is stacking the else, because if i put another } it falls outside that expression.

    upload_2017-6-26_20-49-49.png
    [DOUBLEPOST=1498467453][/DOUBLEPOST]
    i want 24 hour cooldowns.
     
  11. No need, just use return.
     
  12. return; still throws it outside the expression.
     
  13. Instead of the two else statements, you can use else if but that's not really the correct situation.
     
  14. Array index is out of range.
    That line mean you are trying to use an index that you don't set specially at line args[0], You are trying to use the first arg sent by command but if you do only /nuke, there is no arg and that will display the error
    The code on the picture is wrong the other one before is right
     
  15. yes it is right, it works but the cooldown side doesn't work because the command has already been done and has skipped the cooldown check...

    secondly the partial /nuke <player> didnt work so i had to find another way, but you are right in it is working but only a round about way.
     
  16. If I were you, I'd use my method. That way you don't have any timers, and rather the format that you're meant to work with time in. You can even display a formatted DateTime string with little to no effort.
     
  17. blah, i give up.
     
  18. And... there you have it, deviated from everyone elses examples.

    TODO:

    Make data rather than hash due to server restarts every 6 hours, hash will be lost.

    Code:
            #region Core
            [ChatCommand("nuke")]
            void chatNuke(BasePlayer player, string command, string[] args)
            {
                if (permission.UserHasPermission(player.UserIDString, "nukeplayer.use"))
                {
                    if (!Cooldowns.Contains(player.userID))
                    {
                        Cooldowns.Add(player.userID);
                        timer.Once(configFile.Cooldown, () => Cooldowns.Remove(player.userID));
                    }
                    else
                    {
                        SendReply(player, "Preparing Nuke Systems 24 Hour Cooldown");
                        return;
                    }
                    var targetPlayer = covalence.Players.FindPlayer(args[0]);
                    if (targetPlayer != null && targetPlayer.IsConnected)
                    {
                        var target = targetPlayer?.Object as BasePlayer;
                        if (target != null)
                        {
                            DoNuke(target);
                        }
                    }
                }
            }
     
  19. I like yours, would make sense to compare datetimes when the command is run rather than having timers running in the background - better performance. Would be able to present the time left on the cooldown too.