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.
Entire forum
MUSHclient
Lua
Simple GMCP plugin
It is now over 60 days since the last post. This thread is closed.
  Refresh page
Pages: 1
2
3 4
5
Posted by
| Twisol
USA (2,257 posts) bio
|
Date
| Reply #30 on Sat 04 Oct 2014 02:44 AM (UTC) Amended on Sat 04 Oct 2014 02:45 AM (UTC) by Twisol
|
Message
| Make sure you escape any [i] you put in your code before you paste it into the forum, or you'll see weird italicized text like what happened in your post. Just replace [ with \[ and it'll display properly.
At any rate, it is a good idea to do a loop for this kind of thing. The reason "Ti_Name" doesn't turn into "T1_Name" is because the 'i' is in a string. Strings are just characters, and the scripting language doesn't change strings at all. You have to format the string in other ways. One way is
Another, which personally I prefer, is
|
'Soludra' on Achaea
Blog: http://jonathan.com/
GitHub: http://github.com/Twisol | top |
|
Posted by
| Twisol
USA (2,257 posts) bio
|
Date
| Reply #31 on Sat 04 Oct 2014 02:49 AM (UTC) |
Message
|
Solara said: Is there a command I can put into the plugin for it to erase/refresh the table of GMCP data each time it runs?
Put this just after the -- print ("GMCP packet = ", text) line:
if text == "Char.Team" then
fulldata.Team = nil
end
|
'Soludra' on Achaea
Blog: http://jonathan.com/
GitHub: http://github.com/Twisol | top |
|
Posted by
| Solara
USA (59 posts) bio
|
Date
| Reply #32 on Sat 04 Oct 2014 02:23 PM (UTC) Amended on Sat 04 Oct 2014 02:35 PM (UTC) by Solara
|
Message
| So I was able to clean up the code and use a loop to define the variables, and it seems to be working as far as I can tell:
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE muclient>
<muclient>
<plugin
name="Xyllo_Vitals"
author="LP"
id="b9171e77bc4ed6d2926eebdc"
language="Lua"
purpose="GMCP Vitals for Xyllomer"
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.Team" then
fulldata.Team = nil
end
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 ShowHealth ()
SetVariable ("HP_gmcp", fulldata.Vitals.hp)
SetVariable ("Mana_gmcp", fulldata.Vitals.mana)
SetVariable ("Fatigue_gmcp", fulldata.Vitals.fatigue)
SetVariable ("Bleeding_gmcp", fulldata.Vitals.bleeding)
end -- ShowHealth
function ShowHealthTeam ()
for x=1,8 do
if fulldata.Team[x] ~= nil then
SetVariable ("T"..x.."_Name", fulldata.Team[x].name)
SetVariable ("T"..x.."_HP", fulldata.Team[x].hp)
SetVariable ("T"..x.."_Blood", fulldata.Team[x].blood)
if fulldata.Team[x].pos == "0" then SetVariable ("T"..x.."_Pos", "Front")
else SetVariable ("T"..x.."_Pos", "Back")
end
end -- if
end -- loop
end -- ShowHealthTeam
]]>
</script>
</muclient>
But adding "if text == "Char.Team" then fulldata.Team = nil end" didn't seem to have erased the table? Unless I need to reset all the variables that I set as well? I'm not sure the variables I set for prevous team members carry over with each update of the gmcp data/table? | top |
|
Posted by
| Twisol
USA (2,257 posts) bio
|
Date
| Reply #33 on Sat 04 Oct 2014 03:20 PM (UTC) |
Message
|
Solara said:
But adding "if text == "Char.Team" then fulldata.Team = nil end" didn't seem to have erased the table? Unless I need to reset all the variables that I set as well? I'm not sure the variables I set for prevous team members carry over with each update of the gmcp data/table?
Sorry, you're right - my error. The table itself will be cleared and repopulated every time, and you can remove the code I suggested. The problem is, indeed, that the variables from a previous Team update stay set if you don't alter them in the future.
Does your MUD have a maximum to the number of teams you can be notified of? If so, you can just write a second loop before the first that clears the variables for all possible teams. DeleteVariable("T"..i.."_name") , etc. would do it. |
'Soludra' on Achaea
Blog: http://jonathan.com/
GitHub: http://github.com/Twisol | top |
|
Posted by
| Solara
USA (59 posts) bio
|
Date
| Reply #34 on Sat 04 Oct 2014 04:18 PM (UTC) Amended on Sat 04 Oct 2014 05:20 PM (UTC) by Solara
|
Message
| Maybe it's the mud still sending old data (though when I'm not teamed with anyone, gmcpdebug 1 or 2 only shows Char.Vitals and no Char.Team data).
I added this to the beginning of the plugin:
for i=1,8 do
DeleteVariable ("T"..i.."_Name")
DeleteVariable ("T"..i.."_HP")
DeleteVariable ("T"..i.."_Blood")
DeleteVariable ("T"..i.."_Pos")
end -- loop
function OnPluginBroadcast (msg, id, name, text)
But still getting old/static previous team member data. | top |
|
Posted by
| Twisol
USA (2,257 posts) bio
|
Date
| Reply #35 on Sat 04 Oct 2014 04:25 PM (UTC) |
Message
| If you put code outside of any function, it will only be called once, when the plugin loads. You need to put it in ShowHealthTeam. |
'Soludra' on Achaea
Blog: http://jonathan.com/
GitHub: http://github.com/Twisol | top |
|
Posted by
| Solara
USA (59 posts) bio
|
Date
| Reply #36 on Sat 04 Oct 2014 05:32 PM (UTC) Amended on Sat 04 Oct 2014 05:42 PM (UTC) by Solara
|
Message
| Hmm I seem to have been wrong in one of my previous statements.
When I removed myself from a team, gmcpdebug 1 shows only Char.Vitals. But gmcpdebug 2 shows old Char.Team data still.
So I guess the mud's not updating the Char.Team and it's not the plugin's fault?
Addendum: I just tried a ReloadPlugin ("b9171e77bc4ed6d2926eebdc") command (via an alias I type, not part of plugin) to test and it did seem to remove old Char.Team data. So could it be the GMPC_Handler plugin that's maintaining old team data?
Btw, moving the DeleteVariable routines down to the ShowHealthTeam function did not seem to update Char.Teams. So what's ReloadPlugin doing that I am not doing within the plugin? Clearing out GMPC_Handler old table somewhere? | top |
|
Posted by
| Twisol
USA (2,257 posts) bio
|
Date
| Reply #37 on Sat 04 Oct 2014 05:35 PM (UTC) Amended on Sat 04 Oct 2014 05:36 PM (UTC) by Twisol
|
Message
| Reloading a plugin clears all of its "SetVariable" variables. (This is not true in all cases, but is certainly true of this plugin.)
Can you post the full plugin again, with the DeleteVariable loop inside ShowHealthTeam? |
'Soludra' on Achaea
Blog: http://jonathan.com/
GitHub: http://github.com/Twisol | top |
|
Posted by
| Solara
USA (59 posts) bio
|
Date
| Reply #38 on Sat 04 Oct 2014 05:43 PM (UTC) |
Message
| <?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE muclient>
<muclient>
<plugin
name="Xyllo_Vitals"
author="LP"
id="b9171e77bc4ed6d2926eebdc"
language="Lua"
purpose="GMCP Vitals for Xyllomer"
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.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 ShowHealth ()
SetVariable ("HP_gmcp", fulldata.Vitals.hp)
SetVariable ("Mana_gmcp", fulldata.Vitals.mana)
SetVariable ("Fatigue_gmcp", fulldata.Vitals.fatigue)
SetVariable ("Bleeding_gmcp", fulldata.Vitals.bleeding)
end -- ShowHealth
function ShowHealthTeam ()
for x=1,8 do
DeleteVariable ("T"..x.."_Name")
DeleteVariable ("T"..x.."_HP")
DeleteVariable ("T"..x.."_Blood")
DeleteVariable ("T"..x.."_Pos")
end -- loop
for x=1,8 do
if fulldata.Team[x] ~= nil then
SetVariable ("T"..x.."_Name", fulldata.Team[x].name)
SetVariable ("T"..x.."_HP", fulldata.Team[x].hp)
SetVariable ("T"..x.."_Blood", fulldata.Team[x].blood)
if fulldata.Team[x].pos == "0" then SetVariable ("T"..x.."_Pos", "Front")
else SetVariable ("T"..x.."_Pos", "Back")
end
end -- if
end -- loop
end -- ShowHealthTeam
]]>
</script>
</muclient>
| top |
|
Posted by
| Twisol
USA (2,257 posts) bio
|
Date
| Reply #39 on Sat 04 Oct 2014 06:30 PM (UTC) Amended on Sat 04 Oct 2014 06:35 PM (UTC) by Twisol
|
Message
| It appears that the Aardwolf GMCP plugin does in fact "remember" previous data sent by the server, making it impossible to detect the removal of GMCP data:
Quote: Aardwolf GMCP Handler.
Purpose is to receive incoming GMCP messages and populate the global table 'gmcpdata' with the values as received so that GMCP under Mushclient can use partial refreshes of data. For example, we might receive:
char.vitals { "hp": 100000, "mana": 90000, "moves": 41599 }
Then next time, if only HP and Mana have changed, receive:
char.vitals { "hp": 100000, "mana": 85000 }
The previous value for 'moves' will be remembered and available until it is refreshed.
It may be simpler for you to use my GMCP.plugin, which leaves such "remembering" up to the user, and modify my RoomName.plugin. In fact, here is a modified RoomName.plugin/scripts/main.lua to match what we've done so far:
local PPI = require("ppi")
local function ShowHealth(message, Vitals)
SetVariable("HP_gmcp", Vitals.hp)
SetVariable("Mana_gmcp", Vitals.mana)
SetVariable("Fatigue_gmcp", Vitals.fatigue)
SetVariable("Bleeding_gmcp", Vitals.bleeding)
end
local function ShowHealthTeam(message, Team)
for i=1,8 do
if Team[i] then
SetVariable("T"..i.."_Name", Team[i].name)
SetVariable("T"..i.."_HP", Team[i].hp)
SetVariable("T"..i.."_Blood", Team[i].blood)
if Team[i].pos == "0" then
SetVariable("T"..i.."_Pos", "Front")
else
SetVariable("T"..i.."_Pos", "Back")
end
else
DeleteVariable("T"..i.."_Name")
DeleteVariable("T"..i.."_HP")
DeleteVariable("T"..i.."_Blood")
DeleteVariable("T"..i.."_Pos")
end
end
end
-- (ID, on_success, on_failure)
PPI.OnLoad("29a4c0721bef6ae11c3e9a82", function(gmcp)
gmcp.Listen("Char.Vitals", ShowHealth)
gmcp.Listen("Room.Info", ShowHealthTeam)
end, function(reason)
-- Do nothing if GMCP.plugin is not present.
end)
function OnPluginListChanged()
PPI.Refresh()
end
|
'Soludra' on Achaea
Blog: http://jonathan.com/
GitHub: http://github.com/Twisol | top |
|
Posted by
| Solara
USA (59 posts) bio
|
Date
| Reply #40 on Sat 04 Oct 2014 07:46 PM (UTC) Amended on Sat 04 Oct 2014 07:56 PM (UTC) by Solara
|
Message
| Trying to switch over to your plugins but I'm a bit confused.
Do I download and enable both the GMCP plugin AND the modified RoomInfo plugin?
They both contain the same filenames (plugger.xml, PPI.lua, plugin.xml, main.lua).
I renamed RoomInfo's plugin.xml to xyllo.xml, but replacing GMCP's main.lua with the modified main.lua with what you typed above errors out.
It's a bit hard to decipher with the plugins pulling from PPI.lua, plugger.xml, plugin.xml, main.lua.
If I need to keep both GMCP and RoomInfo plugins enabled, which files for RoomInfo contains the link to 'main.lua' that I can rename so I can put both GMCP's main.lua and RoomInfo's renamed main.lua into the same subfolder?
Edit: Okay so figuring that maybe it doesn't look for filename but the plugin ID, i just reanmed RoomInfo's main.lua to xyllo.lua and put it in the script subfolder. No errors, but my triggers are not finding the info - gets nil.
I have my triggers pull from plugin ID for RoomInfo's main.lua: ("e94f6bd8509a2b00d10cb226", | top |
|
Posted by
| Twisol
USA (2,257 posts) bio
|
Date
| Reply #41 on Sat 04 Oct 2014 07:55 PM (UTC) Amended on Sat 04 Oct 2014 07:57 PM (UTC) by Twisol
|
Message
| Yes, you need everything, and both plugins need to be enabled. Just drop the GMCP.plugin and RoomName.plugin directories into your plugins location. There's no need to modify GMCP.plugin at all, and you only need to add each one's plugin.xml to MUSHclient from the Plugins dialog.
See here for a discussion of the "structured plugin" format that my plugins use: http://www.gammon.com.au/forum/?id=10011 . Not everything is in the first post, so you may need to read through a little bit.
The upshot is that plugins.xml is just metadata, and the plugin scripts are in the scripts/ directory. You can ignore libraries/ files - that's just used for static libraries used by the plugin. (This is why ppi.lua appears in both GMCP.plugin and RoomName.plugin: GMCP and RoomName use the PPI module to communicate, so they both need the library.)
There's no need to rename anything. Just replace the contents of RoomName.plugin's main.lua with the code I posted previously. You probably also want to edit some of the metadata in RoomName.plugin/plugin.xml, like the author, name, unique id. |
'Soludra' on Achaea
Blog: http://jonathan.com/
GitHub: http://github.com/Twisol | top |
|
Posted by
| Solara
USA (59 posts) bio
|
Date
| Reply #42 on Sat 04 Oct 2014 08:01 PM (UTC) Amended on Sat 04 Oct 2014 08:10 PM (UTC) by Solara
|
Message
| Okay so copying all the folders straight over and not renaming anything, plugins are working BUT none of the char.team info is being pulled correctly (no errors or nil). It thinks everything is nil for char.team.
What you wrote here, does it mean if Team[x] is NOT nil, then set?
if Team[x] then
SetVariable("T"..x.."_Name", Team[x].name)
SetVariable("T"..x.."_HP", Team[x].hp)
SetVariable("T"..x.."_Blood", Team[x].blood)
Bah I don't know how to escape out the [ i ] so changing it to x. | top |
|
Posted by
| Twisol
USA (2,257 posts) bio
|
Date
| Reply #43 on Sat 04 Oct 2014 08:02 PM (UTC) Amended on Sat 04 Oct 2014 08:06 PM (UTC) by Twisol
|
Message
| You're making your job out to be much more invasive than it needs to be. :) The idea of the "structured plugin" is to make it easy to change only the parts that need to be changed. Our region of concern is RoomName.plugin/scripts/main.lua , as that is where the plugin's main code lives. It's the equivalent of the Lua code you already saw in GMCP_Demo.xml, but without the XML wrapper.
The XML wrapper itself is one directory up, and is called plugin.xml . This is what it should always be named; if you want to rebrand it, rename RoomName.plugin to WhateverYourNameIs.plugin. This file contains plugin metadata, like the author and your plugin's unique ID. This is the ID you'd use in GetPluginVariable, because - after all - you're going to be asking this plugin for its variables.
Everything else is support. Plugger.xml handles loading main.lua and supports using require() to load scripts in scripts/ and libraries . It's totally generic and never needs to be modified.
PPI.lua is a library that supports communications between plugins. GMCP.plugin uses it to expose an interface for other plugins to be notified of GMCP messages. RoomName.plugin uses it to tell GMCP.plugin it wants to be told about Room.Name messages. PPI.lua never needs to be modified. |
'Soludra' on Achaea
Blog: http://jonathan.com/
GitHub: http://github.com/Twisol | top |
|
Posted by
| Twisol
USA (2,257 posts) bio
|
Date
| Reply #44 on Sat 04 Oct 2014 08:04 PM (UTC) |
Message
|
Solara said: What you wrote here, does it mean if Team is NOT nil, then set?
Yes, it's a convenient shorthand. (Technically, if Team is not nil and not false.)
Solara said: It thinks everything is nil for char.team.
Did you replace the original contents of RoomName.plugin/scripts/main.lua with the script I posted previously? Don't rename it to xyllo.lua - it needs to be called main.lua. |
'Soludra' on Achaea
Blog: http://jonathan.com/
GitHub: http://github.com/Twisol | 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 3, subject is 5 pages long:
1
2
3 4
5
It is now over 60 days since the last post. This thread is closed.
  Refresh page
top