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, confirm your email, resolve issues, 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.

Due to spam on this forum, all posts now need moderator approval.

 Entire forum ➜ MUDs ➜ General ➜ Lua Counter(s) from triggers ( For Newbies :) )

Lua Counter(s) from triggers ( For Newbies :) )

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


Posted by Lua_Newbie   (25 posts)  Bio
Date Sun 07 Jun 2015 07:43 AM (UTC)
Message
I would like to share this as it took considerable effort to figure out for a programming newbie so here it is.

If you want to track progress throughout your adventure on any given MUD that supports Lua scripting you can do so within MUSHclient using the following:

first make a trigger by pressing ALT + Enter and clicking on the "Triggers" section in the list on the left hand side

Secondly create the trigger that you want to match on so for example if you wanted to track gold from mob corpses in the case of Aardwolf the trigger would be something like this:

You get * gold * from the * corpse of *.

The easiest way to do this is to copy and paste the line you wish to match on (containing the data you wish to track) from the output window of MUSH client into the Trigger and change anything in that line that will be different each time into a WILDCARD (asterisk).

Those asterisks are wildcards which will match on anything that is sent from the MUD server, you may be wondering why the second one for coins... it's because from time to time you may come across a mob that only drops 1 COIN.

Now this is where it gets fiddly, in the send box you need to put this :

SetVariable ("corpse_gold", (tonumber (GetVariable ("corpse_gold")) + %1 ))

Finally, you need to Send To : Script in the dropdown menu within the trigger creation window and also click the "Expand Variables" Checkbox and make sure it is ticked.

Without going into much detail this retrieves the variable corpse_gold from the variables table in the MUSH config (in the same list as the triggers section right at the bottom on the left in the config window (ALT + Enter) and sets it to it's current value plus the gold received from the mob's corpse. NOTE : You MUST create the variable and give it a starting value !!
(%1 will match the first wildcard, to match a different wildcard use whichever position the wildcard is in for example you want to manipulate with wildcard 4's data, you would use %4 in the same way as %1 above)

This Variable/Counter trick can be used as a counter for anything as long as the trigger matches the output from the MUD and fires, you could count total exp earned, rare MOB exp, Trivia Points from various things (Aardwolf) etc.

I hope this proves useful to others as it did me when someone kindly offered assistance when I couldn't work it out.

- Lunk (of Aardwolf)
Top

Posted by Lua_Newbie   (25 posts)  Bio
Date Reply #1 on Sun 07 Jun 2015 09:06 AM (UTC)

Amended on Sun 07 Jun 2015 09:31 PM (UTC) by Nick Gammon

Message
You will need to copy and paste ALL the code in this and the other posts for this plugin to work (ONLY tested and working in Aardwolf), into notepad or a text editor as 1 file and save it as Quaffer.xml in the plugins folder. of the world directory within the MUSH folder :


<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE muclient>
<muclient>
<plugin
  name="Quaffer"
  author="Abelinc/Luanewb"
  id="91db3f0b6bb87464ca75f5c7"
  language="Lua"
  purpose="Auto Quaffs Potions"
  date_written="2015-03-01"
  requires="4.00"
  version="1.21"
  save_state="y"
  >
<description trim="y">
<![CDATA[
Install this plugin to automatically quaff potions when
hp/mn/mv drops below user-defined percentage
 
qff                     --> Displays the current values
 
qff bag <bagname>       --> Sets which container to get potions from
 
qff hp potion <potname> --> Sets which hp potion to quaff
 
qff mn potion <potname> --> Sets which mana potion to quaff
 
qff mv potion <potname> --> Sets which moves potion to quaff
 
qff hp percent #        --> Sets the hp percent you must fall below to quaff
 
qff mn percent #        --> Sets the mn percent you must fall below to quaff
 
qff mv percent #        --> Sets the mv percent you must fall below to quaff
 
qff hp count #          --> Sets how many consecutive rounds the plugin
                           will quaff hp pots before skipping a round
                                                       
qff mn count #          --> Sets how many consecutive rounds the plugin
                           will quaff mn pots before skipping a round
                                                       
qff mv count #          --> Sets how many consecutive rounds the plugin
                           will quaff mv pots before skipping a round
                                                       
qff on/off              --> Turns the actions of the plugin on or off
]]>
</description>
</plugin>
<aliases>
  <alias
  name="quaffer"
  script="qff_settings"
  match="^qff ?(hp percent|mn percent|mv percent|hp count|mn count|mv count|hp potion|mn potion|mv potion|bag|on|off|help)?( [a-z0-9]+)?"
  enabled="y"
  regexp="y"
  ignore_case="y"
  sequence="100"
 >
  </alias>
  </aliases>
  <script>
 
<![CDATA[
require "checkplugin"
require "serialize"
require "commas"
require "gmcphelper"
function OnPluginBroadcast (msg, id, name, text)
  -- Look for GMCP handler.
  if (id == '3e7dedbe37e44942dd46d264') then
     if (text == "char.vitals") then
        res, gmcparg = CallPlugin("3e7dedbe37e44942dd46d264","gmcpval","char")
                 luastmt = "gmcpdata = " .. gmcparg
        assert (loadstring (luastmt or "")) ()
                   do_autoquaff_hp ()
                   do_autoquaff_mn ()
                   do_autoquaff_mv ()
     end
  end
end
 
function do_autoquaff_hp ()
        if (os.time () - autoquaff_lastfired_hp) > 3 then -- if we've fired hp within 3 seconds, don't bother with other checks, do nothing
                if qff_enable == "yes" then -- if not enabled, don't do anything
                        if (gmcpval("status.state")) == "8" then
                                qff_currcount_hp = 0 -- if we're not fighting, then reset quaff counts for hp
                        end
                        if (gmcpval("status.state")) == "8" then -- if fighting
                                if tonumber ((tonumber(gmcpval("vitals.hp"))/tonumber(gmcpval("maxstats.maxhp"))*100)) < tonumber (qff_percent_hp) then -- if HP low
                                        if tonumber (qff_currcount_hp) < tonumber (qff_count_hp) then -- if we haven't overquaffed hp yet
                                                Send ("get " .. qff_hp_potion .. " " .. qff_bag)
                                                Send ("quaff " .. qff_hp_potion)
                                                qff_currcount_hp = qff_currcount_hp + 1
                                                autoquaff_lastfired_hp = os.time ()
                                                else qff_currcount_hp = 0 -- if we had overquaffed, we're only skipping 1 round and back at it
                                                autoquaff_lastfired_hp = os.time ()
                                        end -- end the overquaffing checks
                         else qff_currcount_hp = 0
                                end -- end HP check
                        end -- end if fighting
                end -- end if enabled check
        end -- end 3 second time check
end -- do_autoquaff_hp

- Lunk (of Aardwolf)
Top

Posted by Lua_Newbie   (25 posts)  Bio
Date Reply #2 on Sun 07 Jun 2015 09:08 AM (UTC)
Message

function do_autoquaff_mn ()
        if (os.time () - autoquaff_lastfired_mn) > 3 then -- checkif we've fired mn within 3 seconds, don't bother with other checks, do nothing
                if qff_enable == "yes" then -- checkif not enabled, don't do anything
                        if (gmcpval("status.state")) == "8" then
                                qff_currcount_mn = 0 -- checkif we're not fighting, then reset quaff counts for mn
                                end
                                if (gmcpval("status.state")) == "8" then -- checkif fighting
                                        if tonumber ((tonumber(gmcpval("vitals.mana"))/tonumber(gmcpval("maxstats.maxmana"))*100)) < tonumber (qff_percent_mn) then -- checkif MN low
                                                if tonumber (qff_currcount_mn) < tonumber (qff_count_mn) then -- checkif we haven't overquaffed mn yet
                                                Send ("get " .. qff_mn_potion .. " " .. qff_bag)
                                                Send ("quaff " .. qff_mn_potion)
                                                qff_currcount_mn = qff_currcount_mn + 1
                                                autoquaff_lastfired_mn = os.time ()
                                                else qff_currcount_mn = 0 -- checkif we had overquaffed, we're only skipping 1 round and back at it
                                                autoquaff_lastfired_mn = os.time ()
                                        end -- end the overquaffing checks
                                        else qff_currcount_mn = 0
                                end -- end MN check
                        end -- end checkif fighting
                end -- end checkif enabled check
        end -- end 3 second time check
end -- do_autoquaff_mn
 
function do_autoquaff_mv ()
        if (os.time () - autoquaff_lastfired_mv) > 3 then -- if we've fired within 3 seconds, don't bother with other checks, do nothing
                if qff_enable == "yes" then -- if not enabled, don't do anything
                        if (gmcpval("status.state")) == "8" then
                        qff_currcount_mv = 0 -- if we're not fighting, then reset quaff counts for mn
                        end
                        if (gmcpval("status.state")) == "8" then -- if fighting
                                if tonumber ((tonumber(gmcpval("vitals.moves"))/tonumber(gmcpval("maxstats.maxmoves"))*100)) < tonumber (qff_percent_mv) then -- if MV low
                                        if tonumber (qff_currcount_mv) < tonumber (qff_count_mv) then -- if we haven't overquaffed mn yet
                                        Send ("g " .. qff_mv_potion .. " " .. qff_bag)
                                        Send ("quaff " .. qff_mv_potion)
                                        qff_currcount_mv = qff_currcount_mv + 1
                                        autoquaff_lastfired_mv = os.time ()
                                        else qff_currcount_mv = 0 -- if we had overquaffed, we're only skipping 1 round and back at it
                                        autoquaff_lastfired_mv = os.time ()
                                        end -- end the overquaffing checks
                                else qff_currcount_mv = 0
                                end -- end MV check
                        end -- end if fighting
                end -- end if enabled check
        end -- end 3 second time check
end -- do_autoquaff_mv

- Lunk (of Aardwolf)
Top

Posted by Lua_Newbie   (25 posts)  Bio
Date Reply #3 on Sun 07 Jun 2015 09:09 AM (UTC)

Amended on Sun 07 Jun 2015 09:34 PM (UTC) by Nick Gammon

Message

function qff_settings (name, line, wildcards)
        if wildcards [1] == "" then
                qff_tellme ()
        elseif wildcards [1] == "on" then
                qff_enable = "yes"
                        ColourNote ("yellow", "", "Quaffer plugin enabled.")
        elseif wildcards [1] == "off" then
                qff_enable = "no"
                        ColourNote ("yellow", "", "Quaffer plugin disabled.")
        elseif wildcards [1] == "help" then
                        qff_help ()
        else
                if wildcards [2] == "" then
                        ColourNote ("yellow", "", "You need to enter a value!")
                        return
        end
                        if wildcards [1] == "hp potion" then
                                qff_hp_potion = wildcards [2]
                                ColourNote("yellow", "", "Set quaffer heal pot to : " .. qff_hp_potion)
                        elseif wildcards [1] == "mn potion" then
                                qff_mn_potion = wildcards [2]
                                ColourNote("yellow", "", "Set quaffer mana pot to : " .. qff_mn_potion)
                        elseif wildcards [1] == "mv potion" then
                                qff_mv_potion = wildcards [2]
                                ColourNote("yellow", "", "Set quaffer moves pot to : " .. qff_mv_potion)
                        elseif wildcards [1] == "bag" then
                                qff_bag = wildcards [2]
                                ColourNote("yellow", "", "Set quaffer bag to : " .. qff_bag)
                        else
                                if wildcards [1] == "hp percent" then
                                        qff_percent_hp = tonumber (wildcards [2])
                                        ColourNote ("yellow", "", "Set quaffer hp percent to : " .. qff_percent_hp)
                                elseif wildcards [1] == "mn percent" then
                                        qff_percent_mn = tonumber (wildcards [2])
                                        ColourNote ("yellow", "", "Set quaffer mn percent to : " .. qff_percent_mn)
                                elseif wildcards [1] == "mv percent" then
                                        qff_percent_mv = tonumber (wildcards [2])
                                        ColourNote ("yellow", "", "Set quaffer mv percent to : " .. qff_percent_mv)
                                elseif wildcards [1] == "hp count" then
                                        qff_count_hp = tonumber (wildcards [2])
                                        ColourNote ("yellow", "", "Set quaffer hp count to : " .. qff_count_hp)
                                elseif wildcards [1] == "mn count" then
                                        qff_count_mn = tonumber (wildcards [2])
                                        ColourNote ("yellow", "", "Set quaffer mn count to : " .. qff_count_mn)
                                elseif wildcards [1] == "mv count" then
                                        qff_count_mv = tonumber (wildcards [2])
                                        ColourNote ("yellow", "", "Set quaffer mv count to : " .. qff_count_mv)
                                end
                        end                    
                end
end -- qff_settings
 
function qff_tellme (name, line, wildcards)
        ColourNote ("yellow", "", "Bag        : " .. qff_bag)
        ColourNote ("yellow", "", "HP Potion  : " .. qff_hp_potion)
        ColourNote ("yellow", "", "MN Potion  : " .. qff_mn_potion)
        ColourNote ("yellow", "", "MV Potion  : " .. qff_mv_potion)
        ColourNote ("yellow", "", "HP Percent : " .. qff_percent_hp)
        ColourNote ("yellow", "", "MN Percent : " .. qff_percent_mn)
        ColourNote ("yellow", "", "MV Percent : " .. qff_percent_mv)
        ColourNote ("yellow", "", "HP Count   : " .. qff_count_hp)
        ColourNote ("yellow", "", "MN Count   : " .. qff_count_mn)
        ColourNote ("yellow", "", "MV Count   : " .. qff_count_mv)
        ColourNote ("yellow", "", "Enabled    : " .. qff_enable)
end
 
function qff_help (name, line, wildcards)
 ColourNote ("teal", "", world.GetPluginInfo (world.GetPluginID (), 3))
 return true -- done  
end -- qff_help
 
function OnPluginInstall ()
if GetVariable ("enabled") == "false" then
   ColourNote ("yellow", "", "Warning: Plugin " .. GetPluginName ().. " is currently disabled.")
   check (EnablePlugin(GetPluginID (), false))
   return
end -- they didn't enable us last time
 
 OnPluginEnable ()  -- do initialization stuff
 end -- OnPluginInstall

- Lunk (of Aardwolf)
Top

Posted by Lua_Newbie   (25 posts)  Bio
Date Reply #4 on Sun 07 Jun 2015 09:11 AM (UTC)

Amended on Sun 07 Jun 2015 09:35 PM (UTC) by Nick Gammon

Message

function OnPluginEnable ()
        checkplugin ("3e7dedbe37e44942dd46d264", "GMCP_handler")
        qff_count_hp = GetVariable ("qff_count_hp")
        if GetVariable ("qff_count_hp") == nil then
                SetVariable ("qff_count_hp", tonumber(1))
        end
        qff_count_mn = GetVariable("qff_count_mn")
        if GetVariable ("qff_count_mn") == nil then
                SetVariable ("qff_count_mn", tonumber(1))
   	end
        qff_count_mv = GetVariable ("qff_count_mv")
        if GetVariable ("qff_count_mv") == nil then
                SetVariable ("qff_count_mv", tonumber(1))
        end
        qff_bag = GetVariable ("qff_bag")
        if GetVariable ("qff_bag") == nil then
                SetVariable ("qff_bag", "bag")
        end
        qff_hp_potion = GetVariable ("qff_hp_potion")
        if GetVariable ("qff_hp_potion") == nil then
                SetVariable ("qff_hp_potion", "heal")
        end
        qff_mn_potion = GetVariable ("qff_mn_potion")
        if GetVariable ("qff_mn_potion") == nil then
                SetVariable ("qff_mn_potion", "lotus")
        end
        qff_mv_potion = GetVariable ("qff_mv_potion")
        if GetVariable ("qff_mv_potion") == nil then
                SetVariable ("qff_mv_potion", "tea")
        end
        qff_percent_hp = GetVariable ("qff_percent_hp")
        if GetVariable ("qff_percent_hp") == nil then
                SetVariable ("qff_percent_hp", "50")
        end
        qff_percent_mn = GetVariable ("qff_percent_mn")
        if GetVariable ("qff_percent_mn") == nil then
                SetVariable ("qff_percent_mn", "50")
        end
        qff_percent_mv = GetVariable ("qff_percent_mv")
        if GetVariable ("qff_percent_mv") == nil then
                SetVariable ("qff_percent_mv", "50")
        end
        qff_count_hp = GetVariable ("qff_count_hp")
        if GetVariable ("qff_count_hp") == nil then
                SetVariable ("qff_count_hp", tonumber "30")
        end
        qff_count_mn = GetVariable ("qff_count_mn")
        if GetVariable ("qff_count_mn") == nil then
                SetVariable ("qff_count_mn", tonumber "30")
        end
        qff_count_mv = GetVariable ("qff_count_mv")
        if GetVariable ("qff_count_mv") == nil then
                SetVariable ("qff_count_mv", tonumber "30")
        end
        qff_enable = GetVariable ("qff_enable")
        if GetVariable ("qff_enable") == nil then
                SetVariable ("qff_enable", "yes")
        end
       
        qff_enable = GetVariable ("qff_enable")
        autoquaff_lastfired_hp = os.time ()
        autoquaff_lastfired_mn = os.time ()
        autoquaff_lastfired_mv = os.time ()
        Send_GMCP_Packet("request char")
end -- OnPluginEnable
 
function OnPluginSaveState ()
 SetVariable ("enabled", tostring (GetPluginInfo (GetPluginID (), 17)))
 SetVariable ("qff_percent_hp", qff_percent_hp)
 SetVariable ("qff_percent_mn", qff_percent_mn)
 SetVariable ("qff_percent_mv", qff_percent_mv)
 SetVariable ("qff_count_hp", qff_count_hp)
 SetVariable ("qff_count_mn", qff_count_mn)
 SetVariable ("qff_count_mv", qff_count_mv)
 SetVariable ("qff_hp_potion", qff_hp_potion)
 SetVariable ("qff_mn_potion", qff_mn_potion)
 SetVariable ("qff_mv_potion", qff_mv_potion)
 SetVariable ("qff_bag", qff_bag)
 SetVariable ("qff_enable", qff_enable)
 end -- OnPluginSaveState
]]>
</script>
</muclient>


So just to recap copy all the code in these 4 parts into the same file in sequential order as listed (1,2,3,4) and be sure to save as file extension .xml (e.g : Quaffer.xml)

Enjoy :)

- Lunk (of Aardwolf)
Top

Posted by Nick Gammon   Australia  (23,140 posts)  Bio   Forum Administrator
Date Reply #5 on Sun 07 Jun 2015 09:36 PM (UTC)
Message
Thanks for the post.

I have merged the 5 threads you made into one, a little easier for people to work with. I also "escaped" brackets and backslashes as described here:

Template:codetag To make your code more readable please use [code] tags as described here.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
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.


19,957 views.

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

Go to topic:           Search the forum


[Go to top] top

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