xyz Posted March 16, 2016 Posted March 16, 2016 How does chatting via a command work? Like function chat(player, message) if isObjectInACLGroup("user."..getAccountName(getPlayerAccount(player)), aclGetGroup("Admin")) then outputChatBox end end addCommandHandler("chat", chat) This is supposed to be an admin chat, what do i do next? It's supposed to output the text for all the admins
1LoL1 Posted March 16, 2016 Posted March 16, 2016 addCommandHandler("chat", function (thePlayer, ... ) if isPlayerMuted (thePlayer) then outputChatBox("You are muted!!!", thePlayer, 255, 0, 0) return end local message = table.concat ({ ... },"") for i, player in ipairs(getElementsByType("player")) do if isObjectInACLGroup("user."..getAccountName(getPlayerAccount(player)),aclGetGroup("Admin")) then outputChatBox("AdminChat: "..string.gsub(getPlayerName(thePlayer), "#%x%x%x%x%x%x", "")..": ".. message, player, 255, 255, 255, true ) end end else outputChatBox("You don't have Admin Rights !!!", thePlayer, 255, 0, 0, true ) end end)
pro-mos Posted March 17, 2016 Posted March 17, 2016 can someone explain to me line #7, as i see it very often and i don't know how it works local message = table.concat ({ ... },"")
Mr_Moose Posted March 17, 2016 Posted March 17, 2016 @pro-mos, It should be like the example below to be correct: local message = table.concat ({ ... }," ") The variable ... is actually an array of remaining arguments allowing you to enter a full string of text (including spaces which wouldn't work if a normal variable where used). The function for the command handler should look like this: function (plr, cmd, ...) local message = table.concat ({ ... }," ") -- Do something with the message end Where the first argument is the player executing the command, second the command itself (useful if you have multiple command handlers to the same function and want to treat them differently) and last but not least ... an array of all remaining words/arguments (the message) entered with the command.
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now