GMCP questions

Posted by Niax on Tue 24 Nov 2020 10:10 PM — 2 posts, 14,051 views.

#0
Hi. I am curious if anybody can help me understand how to use GMCP in plugins. I've been pouring over the threads on the forum and feel like i have maybe a basic idea, but am struggling to actually utilize them.

I've yet to create anything that works, i am curious what i would need to do to get the following schenario to work correctly.

GMCP sends a packet of information during combat to indicate if your damage to an NPC is immune (thus doing no damage). I would like a note to be printed that states that the mob i am fighting is immune.

Here is the GMCP information the game sends when a mob is immune.

char.combat_immunity {"combat_immunity": "a tame dragon is immune to your attack"}


i'm embarrased to show what i've written so far but i'll go ahead and do so just so you can see what i've attempted.


<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE muclient>
<!-- Saved on Sunday, November 22, 2020, 7:28 PM -->
<!-- MuClient version 5.03 -->

<!-- Plugin "immunedamage" generated by Plugin Wizard -->

<muclient>
<plugin
   name="immunedamage"
   author="Niax"
   id="e96785ac51b51fbcc18d90e0"
   language="Lua"
   purpose="checks for immune damage and says something"
   save_state="y"
   date_written="2020-11-22 19:27:43"
   requires="5.03"
   version="1.0"
   >

</plugin>


<!--  Get our standard constants -->

<include name="constants.lua"/>

<!--  Triggers  -->

<triggers>
  <trigger
   custom_colour="1"
   enabled="y"
   expand_variables="y"
   group="immune"
   keep_evaluating="y"
   match="^You hit (.*) (.*), missing (.*) and (.*?) defends (.*?)\, leaving (.*?) at (.*?) percent. You are hit (.*?)\, are missed (.*?)\, and defend (.*?)\."
   regexp="y"
   send_to="12"
   sequence="100"
  >
  </trigger>
</triggers>

<![CDATA[

--requires gmcp_handler for mm
--char.combat_immunity {"combat_immunity": "a tame dragon is immune to your attack"}

local res, gmcparg = CallPlugin("f67c4339ed0591a5b010d05b"), "gmcpval", "char.combat_immunity")
loadstring ("gmcpdata = " .. gmcparg)

Print ("this is a test. should proc on immune damage")

end

]]>


</muclient>


i have a feeling that part of the reason this isn't working is because this isn't something that i can request from gmcp behind the scenes but is instead something that is sent by the game. It doesn't happen every single combat round which i thought was odd but i'm not overly familiar with how these packets would be sent.

any insight into this would be very helpful. I am attempting to build this for blind players who are using the combat mode superbrief in materia magica. (as well as myself who isn't blind but doesn't like spam)
Australia Forum Administrator #1

GMCP generally provides “events” (things that happen without you requesting them) from time to time, like entering a new room, or your HP changing.

You can download a generic GMCP handler plugin from GMCP_handler_NJG.

This basically does the “low level” stuff, and then does a BroadcastPlugin function call to send that information to all interested plugins.

An example of what you might do is GMCP_message_receiver_test.

That basically does this:

function OnPluginBroadcast (msg, id, name, text)
 if id == "74f8c420df7d59ad5aa66246" then  -- GMCP_handler_NJG
  
   -- pull out GMCP message, plus the data belonging to it
   message, params = string.match (text, "([%a.]+)%s+(.*)")
  
   -- no match? oops!
   if not message then
      return
   end -- if
           
   -- ensure we have an array or object
   if not string.match (params, "^[%[{]") then
      params =  "[" .. params .. "]"  -- JSON hack, make msg first element of an array.
   end -- if 
   
   -- decode it
   result = assert (json.decode (params))
   
   -- debugging
   ColourNote ("yellow", "", "GMCP: " .. message)
   
   -- find a handler for this message type
   local handler = handlers [message:lower ()]
   
   -- warn if not found
   if not handler then
     ColourNote ("red", "", "Warning: No handler for: " .. message)
     return
   end -- no handler
   
   -- call the handler, pass in whatever we got
   handler (result)
  end -- if GMCP message
end -- OnPluginBroadcast

The GMCP_handler_NJG plugin is plugin ID 74f8c420df7d59ad5aa66246, so you can see that this responds to messages from that plugin.

It does a JSON decode of the message, and then passes the decoded message to a “handler” of which there is a table of handlers in this plugin.

So in your case you would want a handler for char.combat_immunity, and in that handler you would get a table, and I am presuming that inside that table would be combat_immunity set to “a tame dragon is immune to your attack” in your example.

So then in that function you could print the message that you want.

You might need to put in a few debugging displays to see what is happening, plus turn debugging on in the GMCP handler (type “gmcpdebug 1”).