Jump to content

My own chatbox input.


Stoney

Recommended Posts

So we have been using teams to allow staff to talk to each other using teamchat. Problem is that on 1.0 we will be using teams as they are actually meant to be used and as such staff won't all be in the same team. We already have a system for only talking to certain groups of people (members, staff etc). Only problem is that it uses a /command. It isn't very practical to have to type /staff message each time you want to say something to the staff. Basically what I want to know is how do I bind my own chatbox input to a key. Preferably I want a command like /staff that just brings up a chatbox input and when return is hit the message is redirected using the system we already have for this. That way people can /bind the command however they like.

I've scoured the wiki and forums with no success so I am grateful for any help you can provide.

Link to comment

I think(!) you can unbind the chat "function" from the T or Y key, whichever you want to "override", and then create another key bind for that key. If it were me, though, I'd use the event onPlayerChat, cancelEvent to prevent the original message showing, and outputBox to show it for players based on some condition or expression.

Link to comment

Clientside:

bindKey("p", "down", "chatbox", "Admin") -- Admin is chatinput begin.

Serverside:

function adminCommand(player, command, ...)
-- Add a check if he is a admin..
outputChatBox("Admin chat: "..getPlayerName(player)..": "..table.concat({...}," "), getRootElement(), 255, 0, 0, true)
end
addCommandHandler("Admin", adminCommand)

Link to comment
Thanks a lot Sebas, works great! Would be better with a command handler, but this is fine for now...

Robhol, the whole idea is to not override any keys, I would rather have a command so each player can /bind it as they like.

I don't get what the problem is. Make a command instead of binding a key... :roll:

Link to comment
bindKey("p", "down", "chatbox", "staffChat") 

As you see the handler function is something called "chatbox", some internal function that I can't find documentation on. It takes a variable, in this case "staffChat" which is a command handler. "chatbox" is triggered when you press the "p" button and it brings up the chatbox input field. When you hit return the "staffChat" handler is called with the chat input as variables word for word. So I use ... in the "staffChat" handler to grab the text.

To make a command handler to do this I need to be able to do:

addCommandHandler("staff", "chatbox", "staffChat") 

But as we all know addCommandHandler doesn't take variables for the command handler, they are taken from whatever you put after the /staff command. This is my problem.

Hope it makes sense, I'm kind of bad at explaining it :P

Link to comment

The chatbox command simply opens the chatbox and allows an alternative way to input commands. The default "t" is bound to "chatbox say".

The second argument represents what command the chatbox enters - so when you press t and type something, it inputs "say hi". In otherwords, chatbox represents the command, and what the player types are the arguments. So this is what you want:

bindKey(player, "p", "down", "chatbox", "staffChat") 
  
addCommandHandler("staffChat",  
    function ( player, cmd, ... ) 
        local message = table.concat({...}," ") 
        outputChatBox ( "ADMINCHAT-"..getPlayerName(player)..": "..message ) 
    end  
) 

So, what happens is, p is bound to "chatbox staffChat". When "chatbox staffChat" is entered, the chatbox is initiated in a mode where the "staffChat" command is entered, with the user message as the arguments. Once the player presses enter, it does "staffChat " command. The above example code grabs the message and outputs it to chatbox.

Using the command binds system means the 'staffChat' p bind will appear in the user's MTA Settings menu, so they are able to configure it to their liking. So i'm not sure why you'd need to worry about users binding it for themselves, or the need to use a 'staff' command to execute the chatbox command.

Hope that helps.

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