Page 1 of 1

Help with using GMCP Trigger

Posted: Mon Jan 24, 2022 4:04 am
by pip
Greetings, I am new to scripting and I am trying to figure out how to use Mudlet's gmcp event to make a trigger to leave a room when a door is open or close a door when it's opened.

Is it possible and how would I use this event for my scripting purposes?

Re: Help with using GMCP Trigger

Posted: Sat Feb 05, 2022 5:04 pm
by atari2600tim
Do you mean for the triggering event to be the opening of the door, or when you wander around and encounter an open door?
Closing your door to interrupt an intruder who has opened it, opening every door as you explore, leaving immediately when someone opens your prison door, controlling a patrolling bot by having a human player open and close doors for it... a person might want to do any of those, and I just haven't played your game, so I will try to be vague at the expense of being wordy. I'll put the basics of how to react upon GMCP messages and then speculate a little bit on locked doors if I can.

Most of what I learned came from https://www.mudlet.org/wp-content/uploa ... torial.pdf or from lurking on the Discord channel. Some games have info on web about what they send out via GMCP too. So anyway, that PDF will say most of the same things that I'm about to write, but phrased differently.

To see what kind of data that the game has sent you, type 'lua gmcp'... the lua alias is preinstalled on new profiles, and the gmcp is the name of variable it is going to display. When you get a GMCP message, it puts data into that variable, structured as a table, and it will also call some events to notify you that it has changed... the new data is not sent as an argument to the event, it is just in the variable. The called events will have names of the message name and then with each section removed, like if the GMCP message is something like

Code: Select all

Char.Items.List { "location": "room", "items": [  ] }
then the events called will be `gmcp.Char.Items.List`, `gmcp.Char.Items`, `gmcp.Char`. But how do you know if you got sent an event like `Char` with all character data at once, or if you got sent `Char.Items.List.location` and `Char.Items.List.items`? Turn on debugging, and it will tell you the name of each message that arrives.

So basically you will walk around and get the game to send you the message that you are interested in. Look at the red message names. Do `lua gmcp` to see what data is being sent. Go into the scripts editor, create a script item with whatever name you like, such as `HandleLocks`. Add an event handler using the name of the message that the game sent you, it might be `Room.Info` on Achaea, or `room.info` on Discworld, something else on other games, just put it in the one line box and push the plus sign to move it into the list box. Then in the code box put a block of code with function having the same name as you put in the top of the editor box, something like

Code: Select all

function HandleLocks
  echo("Got a message\n")
end
Now you have an event that just displays a line notifying you that you got the message. Customize that code box and put in whatever logic you want. The send or sendAll functions will send commands to the game, and some if blocks will let you decide when to do it or not, the language can do loops and all the other usual stuff.

I haven't seen what gmcp messages are sent with door locked/unlocked info on any games that I played. I imagine that there would be a table that has list of doors and their status, and you might loop through them. Or look at a specific one that is along your path. Maybe a game might have list of directions and list of usable exits and you have to compare lists. A message that notifies you of opening and closing might just have the info about the single door that changes. It depends on the setup of the individual game.

If you go on the Discord in the help channel and describe the data that it sends you, and what you hope to do with it, someone will help with the logic for it probably quicker than the forum.