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


Register forum user name Search FAQ

Gammon Forum

[Folder]  Entire forum
-> [Folder]  MUSHclient
. -> [Folder]  Lua
. . -> [Subject]  Cleaning up messy triggers, with a table

Cleaning up messy triggers, with a table

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


Posted by Chyort   USA  (58 posts)  [Biography] bio
Date Sun 01 Mar 2009 02:32 AM (UTC)
Message
Ok, i was hoping someone might be able to help me clean up some triggers, i know it can be done with a table easier. i just dont know how to do it
What i have below is a brute force approach to clearing an area. when ever it repops or i login, the triggers all get turned off except for the starting trigger.
When ever something dies i hunt @target. As mobs in the area go extinct and i see "You don't sense a trail of anyone like that.". My trigger turns itself off, and turns the next one on in the chain and updates the new target untill it runs out and then it hunts down bamex, another char of mine. Then it just waits for the next repop.
What i would like to do is replace these half dozen triggers with something that just goes down a table, but that would require calling from a script file and i honestly dont understand that enough to try.

There are a few other things i would also like to do using a table and just going down the list. Im hoping that with a decent example, that i can figure out all the simple modifications for my other projects myself. any help would be appreciated.



<triggers>
  <trigger
   back_colour="8"
   match="You don\'t sense a trail of anyone like that\.$"
   match_back_colour="y"
   match_text_colour="y"
   name="logan"
   regexp="y"
   send_to="12"
   sequence="100"
   text_colour="10"
  >
  <send>SetVariable "target", "haenish-soldier"
EnableTrigger "logan", false
EnableTrigger "soldier", true
send "hunt haenish-soldier"</send>
  </trigger>
  <trigger
   match="You don\'t sense a trail of anyone like that\.$"
   name="soldier"
   regexp="y"
   send_to="12"
   sequence="101"
  >
  <send>SetVariable "target", "haen-villager"
EnableTrigger "soldier", false
EnableTrigger "villager", true
send "hunt haen-villager"</send>
  </trigger>
  <trigger
   match="You don\'t sense a trail of anyone like that\.$"
   name="villager"
   regexp="y"
   send_to="12"
   sequence="102"
  >
  <send>SetVariable "target", "raider"
EnableTrigger "villager", false
EnableTrigger "raider", true
send "hunt raider"</send>
  </trigger>
  <trigger
   match="You don\'t sense a trail of anyone like that\.$"
   name="raider"
   regexp="y"
   send_to="12"
   sequence="103"
  >
  <send>SetVariable "target", "bamex"
EnableTrigger "raider", false
EnableTrigger "is_dead", false
send "hunt bamex"</send>
  </trigger>
</triggers>
[Go to top] top

Posted by Nick Gammon   Australia  (22,975 posts)  [Biography] bio   Forum Administrator
Date Reply #1 on Sun 01 Mar 2009 07:18 PM (UTC)
Message
Certainly this is crying out for a table. I can't quite see how your original script would have worked, in Lua you need to put arguments into brackets, unless there is a single string literal. Anyway, this is my table version:


<triggers>
  <trigger
   back_colour="8"
   enabled="y"
   match="You don\'t sense a trail of anyone like that\.$"
   match_back_colour="y"
   match_text_colour="y"
   regexp="y"
   send_to="12"
   sequence="100"
   text_colour="10"
  >
  <send>

-- table of targets

targets = {
  "haenish-soldier",
  "haenish-villager",
  "raider",
  "bamex",

  --&gt; add more here

  }

-- move onto next target
target_number = (target_number or 0) + 1

-- wrap at end
if target_number &gt; #targets then
  target_number = 1
end -- if

target = targets [target_number]


SetVariable ("target", target)
Send  ("hunt " .. target)

</send>
  </trigger>
</triggers>



This trigger maintains a table of targets, which you can easily add to, and a target_number which is how far it currently is through the table. Each time you get the killed message it adds one, and wraps around to the start at the end of the table. Then it just sets the new target as the target, and hunts it.


- Nick Gammon

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

Posted by Chyort   USA  (58 posts)  [Biography] bio
Date Reply #2 on Sun 01 Mar 2009 11:19 PM (UTC)
Message
its isn't using lua, its using jscript. I'm just actually trying to learn a scripting language and since lua is recommended, that is what I'm playing with. Although there isnt a whole lot of documentaion on it. heh

and what i lack in knowledge. i make up for in brute force a lot of times.. i take what i have/know and modify it until it does what i want it to :P

Thanks for the help btw
[Go to top] top

Posted by Nick Gammon   Australia  (22,975 posts)  [Biography] bio   Forum Administrator
Date Reply #3 on Mon 02 Mar 2009 01:30 AM (UTC)
Message
Well, you posted in the Lua section. :-)

There is a quite a bit of documentation at the head of the Lua section:

http://www.gammon.com.au/forum/bbshowpost.php?bbtopic_id=113

Check out my topics about Lua tables, and there is other stuff about serialization.

- Nick Gammon

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


13,718 views.

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]