Temporarily disabling one trigger

Posted by Caelen on Thu 08 Jul 2010 06:03 AM — 8 posts, 25,937 views.

#0
I found a part of the help files that mentions a trigger enable/disable script.

Script function

world.EnableTrigger

Type

Method

Summary

Enables or disables a trigger

Prototype

long EnableTrigger(BSTR TriggerName, BOOL Enabled);

I don't understand how it's supposed to be used at all though. I'd like to make an alias that lets me temporarily disable one of my anti-theft triggers so I can access my gold for shopping, preferably one that will take only a certain amount of gold out and then immediately re-enable the trigger as well.

Any ideas?

Edit: I did find that other thread about disabling all scripting, but that's not what I'm after. :)
Amended on Thu 08 Jul 2010 06:06 AM by Caelen
USA #1
Give your trigger a name (a.k.a. a label) via the trigger editor, and use that as the first parameter to EnableTrigger(). The second parameter is either true or false, telling it whether to enable it or disable. Example:

EnableTrigger("foolabel", true)
Australia Forum Administrator #2
Another approach is to have a "shopping" alias that sets a variable, eg.


shopping = true


Then in your anti-theft trigger (which you leave enabled) test it, eg.


if not shopping then
  Send "kill thief"
else
  shopping = false
end -- if


That is, you react with your anti-theft action if the shopping flag is not set, otherwise you allow this particular action, but then clear the shopping flag, so it only gets allowed once.
#3
Twisol said:

Give your trigger a name (a.k.a. a label) via the trigger editor, and use that as the first parameter to EnableTrigger(). The second parameter is either true or false, telling it whether to enable it or disable. Example:

EnableTrigger("foolabel", true)



So THAT'S what the label is used for! Thanks!

And... truth be told, I like this one better than the shopping variable. I can make one alias like

alias: getsafe * gold
EnableTrigger("mygold", false)
Send "get %1 gold from @pack"
EnableTrigger("mygold", true)


here's hoping I did the code bracket thingy right...

And, I have all of my item numbers stored as variables, so @pack will return the pack's ID number.

Edit:


<aliases>
  <alias
   match="getsafe * gold"
   enabled="y"
   expand_variables="y"
   send_to="12"
   sequence="100"
  >
  <send>require "wait"
wait.make (function ()

 EnableTrigger("mygold", false)
 Send ("get %1 gold from @pack")
 wait.time(0.1)

 EnableTrigger("mygold", true)

end)</send>
  </alias>
</aliases>
Amended on Thu 08 Jul 2010 08:00 AM by Caelen
Australia Forum Administrator #4
Your problem here is that the Send is not instantaneous. You remember "lag"? There is always some, even if it is fairly minor.

What you have done is disable the trigger, send something to the MUD, and enable it again immediately. However the MUD may take a few milliseconds (at least) to respond.
#5
Nick Gammon said:

Your problem here is that the Send is not instantaneous. You remember "lag"? There is always some, even if it is fairly minor.

What you have done is disable the trigger, send something to the MUD, and enable it again immediately. However the MUD may take a few milliseconds (at least) to respond.


Yep! *points at the edit* I caught that after my first test.
USA #6
Note that sending over the network is "asynchronous". Once the data is sent, the script resumes doing whatever it was doing, and you can't make any assumptions about whether the server has received the data. The most you can say after Send() returns, really, is "this data will be sent", because it might not have even left your computer yet!

You can do two things: automatically enable the "mygold" trigger after a few seconds, or use a trigger to wait for a line that shows the action was received and occured successfully. With getting gold, you can usually count on "You get X gold sovereigns from your pack.", except you need to handle the case where you don't have any gold too.

Actually, the time-based alternative is a good fallback in case something weird happens and you never get the line you expected.

EDIT: Major ninja...
#7
The final setup:


<variables>
  <variable name="getgold">1</variable>
</variables>

<triggers>
  <trigger
   enabled="y"
   expand_variables="y"
   group="Theft"
   match="You get * gold sovereigns from a *"
   send_to="12"
   sequence="100"
  >
  <send>if (GetVariable("getgold")) == "1" then
 Send "touch amnesia"
 Send "stand"
 Send "put money in @gold"
else
 SetVariable ("getgold", "1")
end</send>
  </trigger>
</triggers>

<aliases>
  <alias
   match="getsafe * gold"
   enabled="y"
   expand_variables="y"
   send_to="12"
   sequence="100"
  >
  <send>SetVariable("getgold", "2")
Send ("get %1 gold from @gold")</send>
  </alias>
</aliases>


The timer was too finicky, so I went with the altered trigger instead. It does what I want, which is let me get a specific amount of gold with a single alias, or I can use "all" in place of a number to grab all of it.

Thanks for the help!