what is the correct way to change the args to ulong in ulong ID2 = args? im lost for a few hours on this.Code:[ChatCommand("npctp_add")] void cmdNpcAdD(BasePlayer player, ulong args) { var n = npcData.NpcTP; double timeStamp = GrabCurrentTime(); ulong ID2 = player.userID; if (!n.ContainsKey(ID2)) n.Add(ID2, new NPCInfo((long)timeStamp)); SaveNpcTpData(); }
Converting arg from string to ulong?
Discussion in 'Rust Discussion' started by Ts3hosting, Jan 27, 2017.
-
Wulf Community Admin
You are not using valid arguments for the chat command. It is BasePlayer player, string command, and string[] args. You do not convert them in there, you convert them inside your hook as necessary using things such as (long), Convert.ToUInt64, ulong.Parse, ulong.TryParse, etc.
The args is a string[] array, which means it contains multiple strings. If you are unfamiliar with this aspect of C#, I'd recommend taking a look at https://www.dotnetperls.com/array. -
Code:
[ChatCommand("npctp_add")] void cmdNpcAdD(BasePlayer player, string command, string[] args) { var n = npcData.NpcTP; string ID2 = ""; ID2 = Convert.ToUInt32(args); double timeStamp = GrabCurrentTime(); if (!n.ContainsKey(ID2)) n.Add(ID2, new NPCInfo((long)timeStamp)); SaveNpcTpData(); }
-
Wulf Community Admin
-
Code:
[ChatCommand("npctp_add")] void cmdNpcAdD(BasePlayer player, string command, string[] args) { var n = npcData.NpcTP; string IDNPC = ""; double timeStamp = GrabCurrentTime(); IDNPC = string.Join(" ", args); ulong IDNPC1 = Convert.ToUInt64(IDNPC); if (!n.ContainsKey(IDNPC1)) n.Add(IDNPC1, new NPCInfo((long)timeStamp)); SaveNpcTpData(); }
-
Wulf Community Admin
-