Using GMCP with Mudlet, a tutorial

JonathinJonathin Retired in a hole.

This tutorial is meant for beginners. Some of the information may not be 100% factually correct, but in the context it is helpful for understanding.

I decided to remake the GMCP tutorial from the old forums for people that are trying to use it but are having a difficult time trying to figure it out.



GMCP is a sort of 'invisible' information sent by the server to Mudlet. Luckily, Mudlet knows what to do with the information and populates the tables automatically (this means that Mudlet stores the information automatically). GMCP information is stored in tables. If you haven't done so already, take a look at my Lua Table Tutorial' on my website (link in signature) so you have a basic understanding of tables.

The GMCP information is stored in a sort of family-tree looking thing (as seen below).
image

So, to access the character vitals information, you need to use gmcp.Char.Vitals. In that 3rd level table are:
  • willpower (wp)
  • max willpower (maxwp)
  • endurance (ep)
  • max endurance (maxep)
  • mana (mp)
  • max mana (maxmp)
  • health (hp)
  • max health (maxhp)
  • percentage to the next level (nl)
  • string (not used in this tutorial)

So to access the "hp" value, you use gmcp.Char.Vitals.hp. An example of this would be echo(gmcp.Char.Vitals.hp) and you get an output of your current health (4588 for me).
To view the other tables, I'd suggest using display(gmcp.<table>).



GMCP for Mudlet starts to get a little confusing when you want to script with it. You can in fact script something to fire when the GMCP info is received. People get confused while doing it because there are several things that must be done perfectly each time you want to use this method of scripting. First, I will go over "user defined event handlers".

You know how when you go to the scripts page and create a new script, there are 2 little boxes between script name and the actual script? Those are for event handlers. To create an event handler, you just type what you want into the box with a + and - next to it and press +. To remove one, you click on the registered event handler and click the -. 

Events are like flags being raised on ships. They tell other people about the ship and the other ships can react accordingly, however as opposed to ships, the events are not changed to try and fool Mudlet, so you can use a single event handler without having to worry about it changing.

The event handlers are just the tables that you want to use. To use vitals as an example again, if we want to create a script to fire when gmcp.Char.Vitals is received, we just use gmcp.Char.Vitals as the event handler. You can use just gmcp or gmcp.Char, but we want to be as specific as we can so that we aren't firing 5 or more times per event.



Now that you have your event handler, you need to name your script and the function that you actually want to fire when the event is raised. To tell Mudlet what function to fire, your script name and function name must be the same. For example, if I used "test" as a script name and "test()" as a function name, it would work whereas "test" for the script name and "leap()" as the function name would not.

So, if you wanted to create a script to sip health every time that gmcp.Char.Vitals was received (not recommended), you'd do:

Script name: sip
Event handler: gmcp.Char.vitals
Script:
  function sip()
    send("sip health")
  end--function sip()

This would fire and sip health every single time that gmcp.Char.Vitals was received by Mudlet.



If you wanted to make it sip only when you were below a certain amount of health, you'd do this:

Script name: sip
Event handler: gmcp.Char.vitals
Script:
  function sip()
    if tonumber(gmcp.Char.Vitals) < 2000 then
      send("sip health")
    end--if
  end--function sip()


Notice the "tonumber()" in there. GMCP information is stored as "strings", which means that Mudlet can't perform math on them until you convert them to actual numbers. This function would fire only when you're below 2000 health.

Finally, if you wanted to sip only when you're below a certain percentage, you would do something a little more complex with math:

Script name: sip
Event handler: gmcp.Char.vitals
Script:
  function sip()
    if (tonumber(gmcp.Char.Vitals.hp)/tonumber(gmcp.Char.Vitals.maxhp)*100 < 80 then
      send("sip health")
    end--if
  end--function sip()

This will sip only if you're below 80% of your max health. If you want to create a proper auto sipper, you'll also need some triggers for health/mana balance, but this should at least get you started.
I am retired and log into the forums maybe once every 2 months. It was a good 20 years, live your best lives, friends.

Comments

  • CardanCardan The Garden
    For extra reading, the official GMCP document is available on the Iron Realms website here.
  • JonathinJonathin Retired in a hole.
    Oh, I knew I forgot to add something. I stuck that into my last tutorial. Thanks, @Cardan!
    I am retired and log into the forums maybe once every 2 months. It was a good 20 years, live your best lives, friends.
  • EXCELLENT Tutorial, I'd been ignoring GMCP because it never made any sense whenever anyone brought it up before.

    Now I totally understand!
Sign In or Register to comment.