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


Register forum user name Search FAQ

Gammon Forum

[Folder]  Entire forum
-> [Folder]  MUSHclient
. -> [Folder]  General
. . -> [Subject]  Changing text color based on identifier

Changing text color based on identifier

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


Pages: 1  2 

Posted by Deacla   USA  (42 posts)  [Biography] bio
Date Reply #15 on Tue 13 Jul 2010 11:08 PM (UTC)
Message
Well my first goal is ease of use, and second portability. So I went back to the plugin and dropped the script file. It works while the world is open just like before. but the serialization is either not saving or its loading incorrectly. Does OnPluginInstall load every time the world opens or just the first time the plugin is installed? and now the code.
</plugin>

<triggers>
  <trigger
   enabled="y"
   match="^You take (.*) from the corpse of (?:.*)\.$"
   regexp="y"
   send_to="12"
   sequence="90"
  >
  <send>

  Note("%1") 							-- make a note to see what was captured

  if AutoSacItems["%1"] then			-- check item name for match in table
    Send ("drop '" .. "%1" .. "'")
    Send ("sac '" .. "%1" .. "'")
  end -- if

  </send>
 
 </trigger>
</triggers>
<aliases>
  <alias
   match="AddSacItem (.*)"
   regexp="y"
   enabled="y"
   send_to="12"
   sequence="100"
  >
  <send>AutoSacItems["%1"] = true
Note ("Added '" .. "%1" .. "' to AutoSacItems list.")</send>
  </alias>
</aliases>

<script>
<![CDATA[

require "serialize"  -- needed to serialize table to string

AutoSacItems = {}  -- ensure table exists, if not loaded from variable

-- on plugin install, convert variable into Lua table

function OnPluginInstall ()
  assert (loadstring (GetVariable ("AutoSacItems") or "")) ()
end -- function OnPluginInstall

-- on saving state, convert Lua table back into string variable

-- save_simple is for simple tables that do not have cycles (self-reference)
-- or refer to other tables

function OnPluginSaveState ()
  SetVariable ("AutoSacItems", 
               "AutoSacItems = " .. serialize.save_simple (AutoSacItems))
end -- function OnPluginSaveState

]]>

</script>

I copy/pasted the last bit from your serialization topic and plugged in my own variable name. My plan is to expand on this functionality once the core is working, then passing it on all the other MM'ers on MUSH..

--

working way to hard to play
[Go to top] top

Posted by Nick Gammon   Australia  (23,001 posts)  [Biography] bio   Forum Administrator
Date Reply #16 on Tue 13 Jul 2010 11:16 PM (UTC)
Message
Deacla said:

Does OnPluginInstall load every time the world opens or just the first time the plugin is installed?


After the plugin is installed, OnPluginInstall is called.

Did you set save_state="y" in the plugin header? Check the save state file (RH-double-click on the plugin in the plugin list).

- Nick Gammon

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

Posted by Deacla   USA  (42 posts)  [Biography] bio
Date Reply #17 on Tue 13 Jul 2010 11:41 PM (UTC)
Message
*Smacks forehead*
Doh! It's always something simple. Just had to add that one flag. I'll post the full plugin once I've fleshed out the alias's.

--

working way to hard to play
[Go to top] top

Posted by Deacla   USA  (42 posts)  [Biography] bio
Date Reply #18 on Wed 14 Jul 2010 05:25 AM (UTC)
Message
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE muclient>

<muclient>
<plugin
   name="MM_Auto_Sac"
   author="Deacla"
   id="dc109a6028175ae32994c209"
   language="Lua"
   save_state="y"
   purpose="Auto Sacs Items"
   requires="4.52"
   version="1.0"
   >
<description trim="y">
<![CDATA[

---------------------------------------------------------------------------
---------------------------++++++++++++++++--------------------------------

MUD: Materia Magica
Requires: serialize.lua

This plugin keeps a list of items that are to be automatically
sacrified when you grab them from a corpse. It also saves this list
when MUSHclient is closed. Command line usage is as follows:

ASI item name	(Adds Item 'item name' to the auto-sac list)
RSI item name	(Removes Item 'item name' to the auto-sac list)
sacson			(Turns on all auto-sac triggers)
sacsoff			(Turns off all auto-sac triggers)
sacshelp		(Displays this command list)

---------------------------++++++++++++++++--------------------------------
---------------------------------------------------------------------------

]]>
</description>
</plugin>

<triggers>
  <trigger
   enabled="y"
   group="AutoSacTriggers"
   match="^You take (.*) from the corpse of (?:.*)\.$"
   name="SacFromCorpse"
   regexp="y"
   send_to="12"
   sequence="90"
  >
  <send>

  if AutoSacItems["%1"] then			-- check item name for match in table
    Send ("drop '" .. "%1" .. "'")
    Send ("sac '" .. "%1" .. "'")
  end -- if

  </send>
 
 </trigger>
</triggers>
<aliases>
  <alias
   match="^ASI (.*)$"
   regexp="y"
   enabled="y"
   send_to="12"
   sequence="100"
  >
  <send>AutoSacItems["%1"] = true
Note ()
ColourTell("silver", "black", "Added '" .. "%1" .. "' to AutoSacItems list.")
Send ("")</send>
  </alias>
  <alias
   match="^RSI (.*)$"
   regexp="y"
   enabled="y"
   send_to="12"
   sequence="100"
  >
  <send>AutoSacItems["%1"] = nil
Note ()
ColourTell("silver", "black", "Removed '" .. "%1" .. "' from the AutoSacItems list.")
Send ("")</send>
  </alias>
  <alias
   match="^sacson$"
   regexp="y"
   enabled="y"
   send_to="12"
   sequence="100"
  >
  <send>EnableTriggerGroup ("AutoSacTriggers", true)
Note ()
ColourTell("silver", "black", "Sacs are now ON!.")
Send ("")</send>
  </alias>
  <alias
   match="^sacsoff$"
   regexp="y"
   enabled="y"
   send_to="12"
   sequence="100"
  >
  <send>EnableTriggerGroup ("AutoSacTriggers", false)
Note ()
ColourTell("silver", "black", "Sacs are now OFF!.")
Send ("")</send>
  </alias>
  <alias
   match="^sacshelp$"
   regexp="y"
   enabled="y"
   send_to="12"
   sequence="100"
  >
  <send>
Note ()
ColourTell("white", "black", "Auto_sac commands:")Note()
ColourTell("silver", "black", "ASI item name")Note("    (Adds Item 'item name' to the auto-sac list)")
ColourTell("silver", "black", "RSI item name")Note("    (Removes Item 'item name' to the auto-sac list)")
ColourTell("silver", "black", "sacson")Note("           (Turns on all auto-sac triggers)")
ColourTell("silver", "black", "sacsoff")Note("          (Turns off all auto-sac triggers)")
Send ()</send>
  </alias>
</aliases>

<script>
<![CDATA[

require "serialize"  -- needed to serialize table to string

AutoSacItems = {}  -- ensure table exists, if not loaded from variable

-- on plugin install, convert variable into Lua table

function OnPluginInstall ()
  assert (loadstring (GetVariable ("AutoSacItems") or "")) ()
end -- function OnPluginInstall

-- on saving state, convert Lua table back into string variable

-- save_simple is for simple tables that do not have cycles (self-reference)
-- or refer to other tables

function OnPluginSaveState ()
  SetVariable ("AutoSacItems", 
               "AutoSacItems = " .. serialize.save_simple (AutoSacItems))
end -- function OnPluginSaveState

]]>

</script>
</muclient>

--

working way to hard to play
[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.


55,648 views.

This is page 2, subject is 2 pages long:  [Previous page]  1  2 

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]


Written by Nick Gammon - 5K   profile for Nick Gammon on Stack Exchange, a network of free, community-driven Q&A sites   Marriage equality

Comments to: Gammon Software support
[RH click to get RSS URL] Forum RSS feed ( https://gammon.com.au/rss/forum.xml )

[Best viewed with any browser - 2K]    [Hosted at HostDash]