How to create a trigger that reacts to two separate lines?

Post Reply
EmanueleCiriachi
Posts: 9
Joined: Tue Jul 18, 2017 8:03 pm

How to create a trigger that reacts to two separate lines?

Post by EmanueleCiriachi »

Hello everyone,

first time user.
I am trying to create a script to buff my character; since casting can fail, I want to be able to detect different actions according to different sequences of inputs, that will happen at different intervals of time.

For example, I start with an Alias to issue command A; the mud will output B, then C or D according to whether the spell fails or succeeds.

So I need to be able to recognize A then B then D, and A then B then C, but ONLY if they happen in this order, and in-between I need to be able to issue commands. Can I achieve this with triggers?

Jor'Mox
Posts: 1146
Joined: Wed Apr 03, 2013 2:19 am

Re: How to create a trigger that reacts to two separate lines?

Post by Jor'Mox »

So, yes, you can do what you are trying to do, and the key is going to be using enableTrigger and disableTrigger, so that your triggers are only firing when you need them to.

Within your alias A, you want to enableTrigger("My Trigger B") i.e. you need to turn on the trigger of the appropriate name that will capture output B.

Then, within "My Trigger B", you need to disableTrigger("My Trigger B") and enableTrigger("My Trigger C") and enableTrigger("My Trigger D"). Note that you just need the enableTrigger and disableTrigger bits, each on their own line.

Then in "My Trigger C" and "My Trigger D" you do whatever you need to have happen, and also disableTrigger("My Trigger C") and disableTrigger("My Trigger D"). I assume you should be disabling both triggers within both triggers, since only one of those two things will be happening per time you issue the command, and you don't want to accidentally have one of the triggers fire later on.

Now, IF messages C and D are fairly generic, AND you want to have your script do multiple things to buff you at once that might involve C and/or D, then you could use a table to keep track of the order in which the things that will be triggering C/D are sent, so you can respond appropriately to each one in turn. That would look something like this:
Alias A:
Code: [show] | [select all] lua
enableTrigger("My Trigger B")
my_cmd_tbl = my_cmd_tbl or {}
table.insert(my_cmd_tbl,"A")
send("A")
"My Trigger B" would stay the same.

My Trigger C:
Code: [show] | [select all] lua
local cmd = table.remove(my_cmd_tbl,1)
if cmd == "A" then
   -- do some stuff here
elseif cmd == "something else"
  -- do some other stuff here
end
if table.is_empty(my_cmd_tbl) then
   disableTrigger("My Trigger C")
   disableTrigger("My Trigger D")
end

EmanueleCiriachi
Posts: 9
Joined: Tue Jul 18, 2017 8:03 pm

Re: How to create a trigger that reacts to two separate lines?

Post by EmanueleCiriachi »

Thank you! I thought there was a built-in way of making triggers fire in succession - I guess I will sort it with LUA after all.

User avatar
demonnic
Posts: 886
Joined: Sat Dec 05, 2009 3:19 pm

Re: How to create a trigger that reacts to two separate lines?

Post by demonnic »

You could use a child-parent trigger setup for this.

Have alias for your command A which sets a variable to true:
Code: [show] | [select all] lua
commandA = true
send("commandA")


Make a trigger for the first line, named something which makes sense, but I'll use "First line" here. Make the fire length 99. Make a trigger for the failure and for the success, and have them do what you want, checking to see if commandA is true before doing anything. At the end of the success trigger, have it do
Code: [show] | [select all] lua
-- any other actions you wanna take on success
commandA = false
setTriggerStayOpen("First line", 0)

And on the one for failure, have it do
Code: [show] | [select all] lua
send("commandA")
setTriggerStayOpen("First line",0)

With this method, the triggers for the success and failure lines can be enabled all the time, but do not get checked unless the first line trigger has fired. When the first line fires, the fire length of 99 means it'll test the child triggers against the next 99 lines of mud output. Doesn't matter what comes in between, as long as the success or failure line comes in the next 99 lines. And when you call setTriggerStayOpen("First line",0) it stops checking the child triggers any more, until the first line trigger fires again.

Post Reply