To create a chat command, simply run this function on startup:
customCommandHooks.registerCommand(cmd, callback)
cmdis the word after/which you want to trigger your command (e.g. "help" for/help)
callbackis a function which will be ran when someone sends a message starting "/cmd"
Callback will receive as its arguments a player's pid and a table of all command parts (their message is split into parts by spaces, after removing the leading '/', same as in the old commandHandler.lua).
You can limit which players can run the command with the following functions:
customCommandHooks.setRankRequirement(cmd, rank)
whererankis the same as inPlayers[pid].data.settings.staffRankcustomCommandHooks.removeRankRequirement(cmd)customCommandHooks.setNameRequirement(cmd, names)
wherenamesis a table of playeraccountNamescustomCommandHooks.addNameRequirement(cmd, name)
wherenameis a player'saccountNamecustomCommandHooks.removeNameRequirement(cmd)
You can also perform more advanced checks inside the callback by calling Players[pid]:IsAdmin() and other similar functions.
customCommandHooks.registerCommand("test", function(pid, cmd)
tes3mp.SendMessage(pid, "You can execute a normal command!\n", false)
end)
customCommandHooks.registerCommand("ranktest", function(pid, cmd)
tes3mp.SendMessage(pid, "You can execute a rankchecked command!\n", false)
end)
customCommandHooks.setRankRequirement("ranktest", 2) -- must be an Admin
customCommandHooks.registerCommand("nametest", function(pid, cmd)
tes3mp.SendMessage(pid, "You can execute a namechecked command!\n", false)
end)
customCommandHooks.setNameRequirement("nametest", {"Admin", "Kneg", "Jiub"})