I know that you can use [ChatCommand("thing")], but how can you make a Console Command?
Solved Creating a console command?
Discussion in 'Rust Development' started by Ballsack_, Aug 17, 2018.
-
Code:
[ConsoleCommand("thing")] void ThingCommand(ConsoleSystem.Arg arg) {}
-
Code:[ChatCommand("sclclear")] private void ClearSCLData(BasePlayer player, string cmd, string[] args) { if (!permission.UserHasPermission(player.UserIDString, permissionClear)) { player.ChatMessage(Lang("ErrorNoPermission", player.UserIDString)); return; } else { storedData.SuspectLogs.Clear(); } }
Code:[ChatCommand("sclclear")] private void ClearSCLData(BasePlayer player, string cmd, string[] args) { if (!permission.UserHasPermission(player.UserIDString, permissionClear)) { player.ChatMessage(Lang("ErrorNoPermission", player.UserIDString)); return; } else { storedData.SuspectLogs.Clear(); } }
-
This is the command:
Code:[ConsoleCommand("sclclear")] void SCLClearConsole(ConsoleSystem.Arg arg) { storedData.SuspectLogs.Clear(); PrintToConsole("Clearing all suspect logs..."); }
Code:Failed to call hook 'SCLClearConsole' on plugin 'SuspiciousCombatlogs v0.1.0' (NullReferenceException: Object reference not set to an instance of an object) at Oxide.Plugins.SuspiciousCombatlogs.SCLClearConsole (ConsoleSystem+Arg arg) [0x00000] in <b8c1294f51c440e48f055c3eed4e5bd8>:0 at Oxide.Plugins.SuspiciousCombatlogs.DirectCallHook (System.String name, System.Object& ret, System.Object[] args) [0x00317] in <b8c1294f51c440e48f055c3eed4e5bd8>:0 at Oxide.Plugins.CSharpPlugin.InvokeMethod (Oxide.Core.Plugins.HookMethod method, System.Object[] args) [0x00079] in <e5ac390771dc411395a594de571775c7>:0 at Oxide.Core.Plugins.CSPlugin.OnCallHook (System.String name, System.Object[] args) [0x000d8] in <fc2b4388d9974d719a0972b08cea0f17>:0 at Oxide.Core.Plugins.Plugin.CallHook (System.String hook, System.Object[] args) [0x00060] in <fc2b4388d9974d719a0972b08cea0f17>:0
-
Wulf Community Admin
-
I think the hardest part will be taking this chat command from CombatLogsDb by mzrb
Code:[ChatCommand("combatlog")] private void ChatCombatLog(BasePlayer player, string cmd, string[] args) { if (!permission.UserHasPermission(player.UserIDString, permissionUse)) { player.ChatMessage(Lang("ErrorNoPermission", player.UserIDString)); return; } if (args.Length == 0) { player.ChatMessage(Lang("ErrorNameRequired", player.UserIDString)); return; } var adminInput = args[0].ToLower(); var playerFound = new List<BasePlayer>(); foreach (var t in BasePlayer.activePlayerList) { if (t.UserIDString == adminInput) { playerFound.Clear(); playerFound.Add(t); break; } else if (t.displayName.ToLower() == adminInput) { playerFound.Clear(); playerFound.Add(t); break; } if (t.displayName.ToLower().Contains(adminInput)) { playerFound.Add(t); } } if (playerFound.Count == 0) { player.ChatMessage(Lang("NoPlayersFound", player.UserIDString, adminInput)); return; } else if (playerFound.Count > 1) { string msg = Lang("MultiplePlayersFound", player.UserIDString, adminInput) + ": \n"; foreach (var p in playerFound) msg += $"- {p.displayName} \n"; player.ChatMessage(msg); return; } var suspect = playerFound[0]; int rows = args.Length > 1 ? int.Parse(args[1]) : 20; var suspectLog = suspect.stats.combat.Get(rows); suspectLog = suspectLog.Replace("you", suspect.displayName); string[] numbers = Regex.Split(suspectLog, @"\D+"); foreach (string value in numbers) { if (!string.IsNullOrEmpty(value)) { uint i = uint.Parse(value); if (i < 1000) continue; if (!storedData.Players.ContainsKey(i)) continue; suspectLog = suspectLog.Replace(i.ToString(), GetNameFromId(storedData.Players[i].ToString())); } } player.ConsoleMessage("\n"); player.ChatMessage(Lang("CheckingCombatLogFor", player.UserIDString, suspect.displayName)); player.ConsoleMessage(suspectLog); player.ConsoleMessage("\n"); player.ChatMessage(Lang("CheckConsoleForData", player.UserIDString, suspect.displayName)); storedData.SuspectLogs.Add(player.userID, suspectLog); SaveData(); }
Also, even when the dictionary WASN'T null, the clear command would output the message "Clearing the suspect logs..." but when I went to the file location the json file was still full with whatever was in it. Same was the case when the server was wiped (though a method was made to clear the dictionary on wipe.
in short, a whole lot of oopsie going on here. -
Code:var player = arg.Player(); // Player is null from the ConsoleSystem.Arg - this means the command was ran via console/rcon, etc. if(player == null) { // Returning so the rest of the code is not ran beneath this return; }
-
Thank you, sir!