[Home] [Downloads] [Search] [Help/forum]


Register forum user name Search FAQ

Gammon Forum

Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to "verify" your details, making threats, or asking for money, are spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the password reset link.
[Folder]  Entire forum
-> [Folder]  MUSHclient
. -> [Folder]  Lua
. . -> [Subject]  Simple GMCP plugin

Simple GMCP plugin

It is now over 60 days since the last post. This thread is closed.     [Refresh] Refresh page


Pages: 1 2  3  4  5  

Posted by Solara   USA  (59 posts)  [Biography] bio
Date Wed 01 Oct 2014 04:27 PM (UTC)
Message
Hi I'm trying to enable very simple GMCP data capture from a mud.

I downloaded Twisol's plugin that he posted in another thread (now closed or else I'd have replied to that post). It can be downloaded here: http://jonathan.com/mushclient-achaea-plugins

So I enabled the plugin and it seems to work since it shows the GMCP data when I enable debug by typing "gmcp debug".

My question is, how do I capture that data into variables? I can write simple lua scripts using aliases/triggers. But trying to look through his other xml and lua files for other plugins using GMCP data is a bit confusing for this non-programmer.

The GMCP data I get from the mud is as follows when I turn debug on:

"message"="Char.Vitals"
"data":
"fatigue"=0
"mana"=100
"hp"=100
"bleeding"=0

"message"="Char.Team"
"data":
1:
"name"="Chiara"
"pos"="0"
"leader"="0"
"hp"="100"
"blood"="0"
2:
"name"="Nicole"
"pos"="1"
"leader"="1"
"hp"="100"
"blood"="0"

I would like to capture all the Char.Vitals into individual variables to display, as well as the hp/blood for Char.Team for Chiara.

Is there a simple alias/trigger script someone can show me that can capture the data using Twisol's GMCP plugin please?
[Go to top] top

Posted by Nick Gammon   Australia  (23,045 posts)  [Biography] bio   Forum Administrator
Date Reply #1 on Wed 01 Oct 2014 08:44 PM (UTC)
Message
Looks like your private message to Twisol bounced.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Nick Gammon   Australia  (23,045 posts)  [Biography] bio   Forum Administrator
Date Reply #2 on Wed 01 Oct 2014 09:02 PM (UTC)
Message
It's been a while since I worked on this, but it looks like you have a table of data. Check out inside where the debugging is displayed. If all that is in one table, just extract stuff out in the usual Lua way.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Solara   USA  (59 posts)  [Biography] bio
Date Reply #3 on Thu 02 Oct 2014 01:11 AM (UTC)

Amended on Thu 02 Oct 2014 01:16 AM (UTC) by Solara

Message
His plugin consists of a very short plugin.xml, debug.xml, a main.lua, a plugger.xml, and ppi.lua.

I can decipher simple aliases/trigger scripts, but can't understand complex plugins like main.lua and ppi.lua.

Surely there must be a simple function or variable that I can call from within an alias or trigger for each of the gmcp data?

I can paste the contents of each file if it makes it easier for people to decipher the plugin, but a couple lua files seem rather large and I don't want to waste space on this forum.
[Go to top] top

Posted by Nick Gammon   Australia  (23,045 posts)  [Biography] bio   Forum Administrator
Date Reply #4 on Thu 02 Oct 2014 03:54 AM (UTC)
Message
There's another thread about mappers, coincidentally:

http://www.gammon.com.au/forum/?id=12601&reply=12#reply12

Try getting rid of those plugins and installing the ATCP_NJG one, and see what sort of debugging you get out of it.

Twisol does tend to split his code between various plugins and files.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Solara   USA  (59 posts)  [Biography] bio
Date Reply #5 on Thu 02 Oct 2014 04:14 AM (UTC)

Amended on Thu 02 Oct 2014 04:33 AM (UTC) by Solara

Message
I'll take a look at the links tomorrow, but fyi, i had already tried the aardwof gmcp plugin that's available using the gmcp_handler.xml.

I also tried to look at your gmcp_demo.xml (http://www.gammon.com.au/forum/?id=12479) that you posted on this thread and changing a few things, but there are hooks/calls in there that relate only to the aardwolf gmcp plugin so it didn't work for the one I'm using.

The reason I ended up using Twisol is because it is the only one that actual seems to work and show data when debug is turned on.


Addendum: Okay well I decided to go back and retry the aardwolf gmcp plugin and turning on gmcpdebug 1 and 2 I do get the data.

This is the simple debug data I get returned during debug:

Char.Vitals { "hp":100, "mana":100, "fatigue":0, "bleeding":0 }
Char.Team [{"blood":"0", "hp":"100", "leader":"0", "name":"Kami", "pos":"0"}, {"blood":"0", "hp":"100", "leader":"1", "name":"Pringle", "pos":"1"}]

I enabled your GMCP_Demo.xml that you made referencing the aardwolf gmcp plugin but it errors out probably because it has data there that does not pertain to the mud I'm playing.
[Go to top] top

Posted by Solara   USA  (59 posts)  [Biography] bio
Date Reply #6 on Thu 02 Oct 2014 04:50 AM (UTC)

Amended on Thu 02 Oct 2014 05:00 AM (UTC) by Nick Gammon

Message
So I modified your GMCP_Demo.xml to eliminate data that this mud doesn't send and changed vitals that it does and it does work, showing a status bar for hp, mana, fatigue, bleeding.


<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE muclient>

<muclient>
<plugin
   name="GMCP_demo"
   author="Nick Gammon"
   id="b9171e77bc4ed6d2926eebdc"
   language="Lua"
   purpose="GMCP demonstration"
   date_written="2014-06-09"
   requires="4.73"
   version="1.0"
>
</plugin>

<!--  Script  -->

<script>
<![CDATA[

fulldata = {}

--=================================================================================
-- Called when plugin receives telnet data - main entry point for actually running
-- the plugin.
--=================================================================================
function OnPluginBroadcast (msg, id, name, text)

   -- Look for GMCP handler.
   if (id == '3e7dedbe37e44942dd46d264') then
      if (text == 'reload') then
         -- invalidate current data
         fulldata = {} 
         return
      end
     -- print ("GMCP packet = ", text)
      if (text == "Char.Base" or text == "Char.Vitals" or text == "Char.Status" or text == "Char.Maxstats") then
         res, gmcparg = CallPlugin("3e7dedbe37e44942dd46d264","gmcpval","Char")

         luastmt = "gmcpdata = " .. gmcparg
         assert (loadstring (luastmt or "")) ()

         -- copy into fulldata
         for k, v in pairs (gmcpdata) do
           fulldata [k] = v
         end -- for
      
      if text == "Char.Vitals" then
        ShowHealth ()
      end -- if
      end
   end
end


function ShowHealth ()
  hp          = tonumber (fulldata.Vitals.hp)
  mana        = tonumber (fulldata.Vitals.mana)
  fatigue     = tonumber (fulldata.Vitals.fatigue)
  bleeding    = tonumber (fulldata.Vitals.bleeding)

  SetStatus ("Health: " .. hp .. " Mana: " .. mana .. " Fatigue = " .. fatigue .. " Bleeding = " .. bleeding )
  
end -- ShowHealth

]]>
</script>
</muclient>


So I am one step closer to doing what I want, which is to capture the data into variables to put into a miniwindow using simple aliases/trigger (I am only used to writing those, not actual plugin xml files). And I'd like to capture the Char.Team data as well.
[Go to top] top

Posted by Solara   USA  (59 posts)  [Biography] bio
Date Reply #7 on Thu 02 Oct 2014 05:40 AM (UTC)
Message
Okay so trying to capture the data into variables so I can use it for other triggers/scripts I tried to change the ShowHealth function to this in the GMCP_Demo.xml:

function ShowHealth ()
hp = tonumber (fulldata.Vitals.hp)
mana = tonumber (fulldata.Vitals.mana)
fatigue = tonumber (fulldata.Vitals.fatigue)
bleeding = tonumber (fulldata.Vitals.bleeding)

SetVariable ("Health", hp)
SetVariable ("Mana", mana)
SetVariable ("Fatigue", fatigue)
SetVariable ("Bleeding", bleeding )

end -- ShowHealth


But that did not work. Under variables I don't see any of those set at all. I can do Note (hp) from within the plugin and it does send the correct data to the screen. How do you use SetVariable in a plugin file?

I also tried to add a second ShowHealthTeam function to capture the team hp/blood/position by adding these lines but the plugin errored out:

-- print ("GMCP packet = ", text)
if (text == "Char.Vitals" or text == "Char.Team") then
res, gmcparg = CallPlugin("3e7dedbe37e44942dd46d264","gmcpval","Char")

luastmt = "gmcpdata = " .. gmcparg
assert (loadstring (luastmt or "")) ()

-- copy into fulldata
for k, v in pairs (gmcpdata) do
fulldata [k] = v
end -- for

if text == "Char.Vitals" then
ShowHealth ()
end -- if
if text == "Char.Team" then
ShowHealthTeam ()
end -- if
end
end
end
.
.
.

function ShowHealthTeam ()
hp2 = tonumber (fulldata.Team.hp)
position = tonumber (fulldata.Team.pos)
blood = tonumber (fulldata.Team.blood)

SetVariable ("Health2", hp2)
SetVariable ("Position", position)
SetVariable ("Bleeding", blood )

end -- ShowHealth


I'm thinking it errored out because Char.Team has hp/blood/pos/leader data for each team member, so how do I go about pulling name "Chiara"'s numbers?
[Go to top] top

Posted by Nick Gammon   Australia  (23,045 posts)  [Biography] bio   Forum Administrator
Date Reply #8 on Thu 02 Oct 2014 06:01 AM (UTC)
Message
What do you mean it didn't work? Variables are local to plugins. You can get them from other plugins or the main world file by using GetPluginVariable.

http://www.gammon.com.au/scripts/doc.php?function=GetPluginVariable

Another approach a plugin can use is to "Execute" a string like: "plugin-info: health now 456"

Then make an alias in your main world file to "catch" such a string.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Solara   USA  (59 posts)  [Biography] bio
Date Reply #9 on Thu 02 Oct 2014 06:12 AM (UTC)
Message
Okay so after a bit more reading it seems it's difficult to push a plugins' variable to the world's global variable. Easier to pull it with GetPluginVariable. And using Notify within the plugin to notify the world.

So how do I set a Notify command within the gmpc_demo.xml to notify the world that the variables have been updated?

And I'm still stumped as to how to pull Char.Team gmcp data (hp, blood, pos) for a specific or all team members.
[Go to top] top

Posted by Twisol   USA  (2,257 posts)  [Biography] bio
Date Reply #10 on Thu 02 Oct 2014 06:14 AM (UTC)

Amended on Thu 02 Oct 2014 06:17 AM (UTC) by Twisol

Message
Hi Solara (and Nick - long time no see!),

I saw your comment on my blog, but I figured I'd respond here since you already have a thread. It'd been a while since I last used these plugins, but let me see if I can help.

My GMCP plugin is only useful to other plugins, so you'll want to modify an existing plugin. I usually recommend my RoomName.plugin, since it's so minimal but has all the parts necessary to work. You'd just want to make sure to modify its plugin.xml so it has a unique ID, and probably change the name and author. :P

In your case, you'll want to modify the listening code (lines 10-12 of RoomName.plugin/scripts/main.lua) to include one Listen block for each message you're interested in. You can then create exposed variables in the plugin with GetVariable(), and access them from anywhere (such as your non-plugin aliases, triggers, etc.) using GetPluginVariable() and the ID you gave your plugin.

I'll subscribe to this thread, so let me know if you have any issues. I see you're looking into the Aardwolf plugin as well, but in either case, I hope you find something that works for you!

[EDIT]:
Quote:
So how do I set a Notify command within the gmpc_demo.xml to notify the world that the variables have been updated?
Unless something has changed since the last time I actively developed in MUSHclient, there's no pleasant way to do that. The whole point of GMCP.plugin and the PPI module is to allow other plugins to be notified on just such occasions, but the "world" scripts are more limited in this respect.

[EDIT]: I don't consider Execute a pleasant way. :D

'Soludra' on Achaea

Blog: http://jonathan.com/
GitHub: http://github.com/Twisol
[Go to top] top

Posted by Nick Gammon   Australia  (23,045 posts)  [Biography] bio   Forum Administrator
Date Reply #11 on Thu 02 Oct 2014 06:14 AM (UTC)
Message
Like I said, Execute a command like "variables changed".

Then make an alias in the main world that matches "variables changed". Problem solved.

Template:function=Execute Execute

The documentation for the Execute script function is available online. It is also in the MUSHclient help file.


- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Solara   USA  (59 posts)  [Biography] bio
Date Reply #12 on Thu 02 Oct 2014 06:26 AM (UTC)
Message
this is now my modified ShowHealth function within gmcp_demo:

function ShowHealth ()
hp = tonumber (fulldata.Vitals.hp)
mana = tonumber (fulldata.Vitals.mana)
fatigue = tonumber (fulldata.Vitals.fatigue)
bleeding = tonumber (fulldata.Vitals.bleeding)

end -- ShowHealth


This is the content of my alias to try to pull those variables and display them. I get nil errors.

hp = GetPluginVariable ("b9171e77bc4ed6d2926eebdc", "hp")
mana = GetPluginVariable ("b9171e77bc4ed6d2926eebdc", "mana")
fatigue = GetPluginVariable ("b9171e77bc4ed6d2926eebdc", "fatigue")
bleeding = GetPluginVariable ("b9171e77bc4ed6d2926eebdc", "bleeding")

note (hp)
note (mana)
note (fatigue)
note (bleeding)
[Go to top] top

Posted by Twisol   USA  (2,257 posts)  [Biography] bio
Date Reply #13 on Thu 02 Oct 2014 06:27 AM (UTC)

Amended on Thu 02 Oct 2014 06:28 AM (UTC) by Twisol

Message
"Note" is case-sensitive. You have to use it like: Note(hp).

'Soludra' on Achaea

Blog: http://jonathan.com/
GitHub: http://github.com/Twisol
[Go to top] top

Posted by Solara   USA  (59 posts)  [Biography] bio
Date Reply #14 on Thu 02 Oct 2014 06:37 AM (UTC)

Amended on Thu 02 Oct 2014 08:17 PM (UTC) by Solara

Message
Ha, yeah embarrasing error. I don't get any errors now after changing to Note, but all variables are still 'nil'. I know the gmcp data is being rceived and I didn't change anything within thte gmcp_demo.xml except to remove the SetStatus commands.

Edit: Okay figured out the problem. I have to actually do SetVariable within the plugin for it to be called:

function ShowHealth ()
  hp          = tonumber (fulldata.Vitals.hp)
  mana        = tonumber (fulldata.Vitals.mana)
  fatigue     = tonumber (fulldata.Vitals.fatigue)
  bleeding    = tonumber (fulldata.Vitals.bleeding)

  SetVariable ("Health_gmcp", hp)
  SetVariable ("Mana_gmcp", mana)
  SetVariable ("Fatigue_gmcp", fatigue)
  SetVariable ("Bleeding_gmcp", bleeding)

end -- ShowHealth



Now, can anyone help me pull the gmcp data for the Char.Team? It seems it's Char.Team.1 for first team member, Char.Team.2 for second team member, etc.

Here's the verbose gmcp data from the mud:

Char.Vitals { "hp":100, "mana":100, "fatigue":0, "bleeding":0 }
gmcpdata serialized: {
  Char = {
    Team = {
      [1] = {
        name = "Chiara",
        blood = "0",
        hp = "100",
        leader = "0",
        pos = "0",
        },
      [2] = {
        name = "Nicole",
        blood = "0",
        hp = "100",
        leader = "1",
        pos = "1",
        },
      },
    Vitals = {
      fatigue = "0",
      mana = "100",
      hp = "100",
      bleeding = "0",
      },
    },
  }
Char.Team [{"blood":"0", "hp":"100", "leader":"0", "name":"Chiara", "pos":"0"}, {"blood":"0", "hp":"100", "leader":"1", "name":"Nicole", "pos":"1"}]
gmcpdata serialized: {
  Char = {
    Team = {
      [1] = {
        name = "Chiara",
        blood = "0",
        hp = "100",
        leader = "0",
        pos = "0",
        },
      [2] = {
        name = "Nicole",
        blood = "0",
        hp = "100",
        leader = "1",
        pos = "1",
        },
      },
    Vitals = {
      fatigue = "0",
      mana = "100",
      hp = "100",
      bleeding = "0",
      },
    },
  }
[Go to top] top

The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).

To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.


144,342 views.

This is page 1, subject is 5 pages long: 1 2  3  4  5  [Next page]

It is now over 60 days since the last post. This thread is closed.     [Refresh] Refresh page

Go to topic:           Search the forum


[Go to top] top

Quick links: MUSHclient. MUSHclient help. Forum shortcuts. Posting templates. Lua modules. Lua documentation.

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.

[Home]