Author Topic: GUI help - button makes player talk  (Read 1011 times)

On a GUI, how would I make a button that, when pressed, made the player enter something into their text field.

My use for this is, when someone clicks a brick, a restaurant menu GUI pops up with buttons next to the dishes, and when the player clicks a button, it makes the player say "/C restaurant [food item]", which uses the cmd events to then trigger more events to work.

I stripped the code from the prompt events to get my GUI to pop up when the event is triggered, so all I need is the button help.

So let's talk a little bit about what happens when you send a chat message.

When a player types something into the chat field, what normally happens is that the game grabs all the text in the chat area, and puts it into a string, let's call it %message. Then the game (still on the client side) runs a function called commandToServer() which is basically how all scripted communication from the client to the server happens. Specifically, it calls
Code: [Select]
commandToServer('MessageSent', %message);(Note the single quotes, not double quotes; this is important in this case.)
When the client calls this function on its own machine, the end result is a transmission to the server, which causes the server to run
Code: [Select]
serverCmdMessageSent(%client, %message);
The exception to this is when the chat starts with a slash. When this is detected, the chat is not sent to the server at all. Instead, a different commandToServer() is sent, specifically the one after the slash, with everything after that being arguments separated by spaces. So "/C restaurant [food_item]" will run:
Code: [Select]
commandToServer('C', %shop, %item);where %shop is "restaurant" and %item is "[food_item]". This makes the server call
Code: [Select]
serverCmdC(%client, %shop, %item);
So to answer your question, routing through the chat system would be clumsy and is entirely unnecessary. The "command" field of your button only needs to have:
Code: [Select]
commandToServer('C', "restaurant", "item");
« Last Edit: July 14, 2013, 10:47:41 AM by Mr. Wallet »

don't forget you need to include the client

commandToServer('C', %client, "restaurant", "item");

wait stuff thats only for server, sorry

don't forget you need to include the client

Code: [Select]
commandToServer('C', %client, "restaurant", "item");

... what?