Cleaning up messy triggers, with a table

Posted by Chyort on Sun 01 Mar 2009 02:32 AM — 4 posts, 20,484 views.

USA #0
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>
Australia Forum Administrator #1
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.

USA #2
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
Australia Forum Administrator #3
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.