Jump to content

Chat command


xyz

Recommended Posts

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

Link to comment
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) 

Link to comment

@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.

Link to comment

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...