When an admin uses any commands such as /godmode, /give, /fly, etc to announce they have activated it or deactivated it, So the community can see if an admin is abusing his powers for example in the ingame chat:
British89 has activated godmode
British89 has deactivated godmode
British89 has activated fly
British89 has given [name] [amount] [item]
and so on.
Thanks.
Solved Announce admin command usage
Discussion in 'Plugin Requests' started by British89, Oct 27, 2015.
-
Wulf Community Admin
Command Logger for Reign of Kings | Oxide
It wouldn't take much to modify to broadcast it to chat. -
Thanks, Is it ok for me to tinker with someone else work then?
-
Wulf Community Admin
-
Here you go British.
Original Code:
Code:private void OnPlayerCommand(Player player, string command, string[] args) { if (!CommandLogEnabled) return; Log("commands", $"{player.Name} ran the command /{command} {args.JoinToString(" ")}"); }
Code:private void OnPlayerCommand(Player player, string command, string[] args) { if (!CommandLogEnabled) return; Log("commands", $"{player.Name} ran the command /{command} {args.JoinToString(" ")}"); // Array of commands to announce string[] notifyList = new string[] { "godmode", "fly", "give", "giveall", "heal", "hydrate", "nourish", "stophunger", "stopthirst" }; //If the command run is in the above array, Notify server. foreach (string x in notifyList) { if (x.Contains(command)) { PrintToChat($"[[64CEE1]Server[-]] {player.Name} just ran /{command} {args.JoinToString(" ")}"); } } }
-
Thank you very much SweetLouHD, much appreciated.
[DOUBLEPOST=1446073008][/DOUBLEPOST]It works great, It does have its faults though, It will announce the first command, the 2nd announce will announce twice, then 3 times, then 4 and so on -
[DOUBLEPOST=1446113161][/DOUBLEPOST]Actually I take that back. The give command would fire twice because "give" is also in "giveall". we just need to end the function when the first instance is found so we add a return; after the PrintToChat. Also changed the if statement to check for the exact word not part of a word. (x.Contains(command) vs x == command)
Updated Code:
Code:private void OnPlayerCommand(Player player, string command, string[] args) { if (!CommandLogEnabled) return; Log("commands", $"{player.Name} ran the command /{command} {args.JoinToString(" ")}"); // Array of commands to announce string[] notifyList = new string[] { "godmode", "fly", "give", "giveall", "heal", "hydrate", "nourish", "stophunger", "stopthirst" }; //If the command run is in the above array, Notify server. foreach (string x in notifyList) { if (x == command.ToLower()) { PrintToChat($"[[64CEE1]Server[-]] {player.Name} just ran /{command} {args.JoinToString(" ")}"); return; } } }
Last edited by a moderator: Oct 29, 2015 -
Thanks again SweetLouHD.
-
Welcome