1. I kept trying with this vote command i'm creating for my server and when i try to do /vote <ID> (example : /vote 383124) I keep getting Object reference not set to an instance of an object
    This is the code thats been going wrong(Btw i do have a list for all VoteIDS)
    Code:
                   [ChatCommand("sv")]
            private void StartVote(BasePlayer plr, string command, string[] args)
            {
                string voteinfo = args[0];
                int VoteNeeded = int.Parse(args[1]);
                System.Random rand = new System.Random();
                int rando = rand.Next(1, 100000);
                rust.RunServerCommand("say " + plr.displayName + " has started a vote for " + voteinfo + ", votes needed : " + VoteNeeded + ", ID : " + rando +"! Vote using /vote <ID>");
            }
     [ChatCommand("vote")]
            private void Vote(BasePlayer plr, string command, string[] args)
            {
                int ID = int.Parse(args[0]);
                if (!VoteIDS.Contains(ID))
                {
                    SendReply(plr, "That vote doesn't exist!");
                }
                else if (!Voted.ContainsKey(plr.userID))
                {
                    Voted.Add(plr.userID, ID);
                    SendReply(plr, "You voted for the vote : " + ID);
                }
                else
                {
                    SendReply(plr, "Something went wrong/You have already voted for this!");
                }
            }
     
  2. Wulf

    Wulf Community Admin

    You aren’t checking if the args has any length before using then, so that is likely your cause.
     
  3. Wait, is this what you mean?

    Code:
            [ChatCommand("vote")]
            private void Vote(BasePlayer plr, string command, string[] args)
            {
                if (args.Length == 0)
                {
                    SendReply(plr, "Invalid Arguments!");
                    return;
                }            int ID = int.Parse(args[0]);
                if (!VoteIDS.Contains(ID))
                {
                    SendReply(plr, "That vote doesn't exist!");
                }
                else if (!Voted.ContainsKey(plr.userID))
                {
                    Voted.Add(plr.userID, ID);
                    SendReply(plr, "You voted for the vote : " + ID);
                }
                else
                {
                    SendReply(plr, "Something went wrong/You have already voted for this!");
                }        }
     
  4. Code:
            [ChatCommand("vote")]
            private void Vote(BasePlayer plr, string command, string[] args)
            {
                if (args.Length > 0)
                {
                    SendReply(plr, "Invalid Arguments!");
                    return;
                }            if(args[0] != null) { int ID = int.Parse(args[0]); }
               
                if (!VoteIDS.Contains(ID))
                {
                    SendReply(plr, "That vote doesn't exist!");
                }
                else if (!Voted.ContainsKey(plr.userID))
                {
                    Voted.Add(plr.userID, ID);
                    SendReply(plr, "You voted for the vote : " + ID);
                }
                else
                {
                    SendReply(plr, "Something went wrong/You have already voted for this!");
                }        }
    
     
  5. I'm still getting this error, hm..

    Failed to call hook 'Vote' on plugin 'test v1.0.0' (NullReferenceException: Object reference not set to an instance of an object)
    at Oxide.Plugins.test.Vote (.BasePlayer plr, System.String command, System.String[] args) [0x00000] in <filename unknown>:0
    at Oxide.Plugins.test.DirectCallHook (System.String name, System.Object& ret, System.Object[] args) [0x00000] in <filename unknown>:0
    at Oxide.Plugins.CSharpPlugin.InvokeMethod (Oxide.Core.Plugins.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
     
  6. that means something is undefined, send full code
     
  7. Lol, what? If Length > 0 - return, but if no, we will take args[0]?
     
  8. Sorry, had to fix it.
     
    Last edited by a moderator: Feb 10, 2018
  9. Where is here vote function?
     
  10. I'm pretty sure vote list and dictionary need to be initialized... Like this
    Code:
    public List<int> VoteIDS = new List<int>();
     
  11. Fixed it! Thanks.
     
    Last edited by a moderator: Feb 10, 2018
  12. Code:
    [ChatCommand("vote")]
            private void Vote(BasePlayer plr, string command, string[] args)
            {
                if (args.Length != 1)
                {
                    SendReply(plr, "Invalid Arguments!");
                    return;
                }            int ID = Convert.ToInt32(args[0]);            if (!VoteIDS.Contains(ID))
                {
                    SendReply(plr, "That vote doesn't exist!");
                }
                else if (!Voted.ContainsKey(plr.userID))
                {
                    Voted.Add(plr.userID, ID);
                    SendReply(plr, "You voted for the vote : " + ID);
                }
                else
                {
                    SendReply(plr, "Something went wrong/You have already voted for this!");
                }        }
    
    So?
    [DOUBLEPOST=1518253691][/DOUBLEPOST]Ah, no. Got it
    public Dictionary<ulong, ulong> TpRequests;
    public Dictionary<BasePlayer, bool> CoolDown;
    public Dictionary<int, BasePlayer> CodesPlayersActivated = new Dictionary<int, BasePlayer>();
    public List<BasePlayer> VIPGuys;
    public List<ulong> RedeemedFirstKit;
    public List<int> VoteIDS;
    public Dictionary<ulong, int> Voted;
    public bool OnTimeout;
    You should add to them = new bla bla bla. Example:

    public Dictionary<BasePlayer, bool> CoolDown; - NOT RIGHT
    public Dictionary<BasePlayer, bool> CoolDown = new Dictionary<BasePlayer, bool>(); - RIGHT
     
  13. Thanks, im an idiot somedays lol.
    [DOUBLEPOST=1518253754][/DOUBLEPOST]
    Oh yea, i forgot that you had to do that. I always thought you could do it shorter, guess not lol.
     
  14. Also i will provide your code and give some advices.
    Code:
    // FIRST, how to set Easy timer
    SendReply(plr, "You're gonna die in 5 seconds. You have been posioned!");
    //plr.Command("kill"); Sometimes it will not work, use player.Kill();
    timer.Once(5, () => player.Kill());
    //SECOND
    //rust.RunServerCommand("say " + plr.displayName + " has started a vote for " + voteinfo + ", votes needed : " + VoteNeeded + ", ID : " + rando + "! Vote using /vote <ID>");
    Use Server.Broadcast($"Something like that");
    // THIRD Easy item give
    //rust.RunServerCommand("giveto " + plr.displayName + " wood 2000");
    //rust.RunServerCommand("giveto " + plr.displayName + " stones 5000");Item x = ItemManager.CreateByPartialName("wood", 2000);
    x.MoveToContainer(plr.Inventory.ContainerMain);
    
     
  15. Thanks.