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

Gammon Forum

See www.mushclient.com/spam for dealing with forum spam. Please read the MUSHclient FAQ!

[Folder]  Entire forum
-> [Folder]  MUSHclient
. -> [Folder]  Tips and tricks
. . -> [Subject]  Auto disabling Trigger
Home  |  Users  |  Search  |  FAQ
Username:
Register forum user name
Password:
Forgotten password?

Auto disabling Trigger

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


Pages: 1 2  

Posted by Marco   (36 posts)  [Biography] bio
Date Sat 29 Apr 2017 08:22 AM (UTC)

Amended on Sat 29 Apr 2017 08:40 AM (UTC) by Marco

Message
Good Morning, this topic is similar to one found in:
"Timed Trigger" and ""Enableing, Disableing ALL triggers""

but a bit different in some way.

I would like to set up a trigger that let me flee when i meet "Shere Khan", so an expression very simple like
"^.*Shere Khan"   

Works fine but when i meet that beast the tipycal output is:
Shere Khan is here
Shere Khan is surrounded in deep darkness
Shere Khan bites you!
Shere khan scratches you with its claws!
Shere khan scratches you with its claws!
Shere khan scratches you with its claws!
Shere khan scratches you with its claws!
Shere khan scratches you with its claws!
Shere Khan hits you with its disintegrating ray!

So... if i send something like:
"stand; flee" 

it will fires 9 times(!) creating a confusing and not good at all situation..

For me will be good enough that the Trigger autodisable itself for 2-3 senconds after the first fire and then enable self again.

I would like, if possible, NOT deactivating ALL the triggers but only THAT one.

I'm opened to every suggestion, even different from mine, even though i think is quiet good. if there isn't the possibility to disable only that particular trigger would be good (also) the temporary deactivation of all the triggers.

Anyways even if you won't be able to help me, thank you very much in advance!
[Go to top] top

Posted by Nick Gammon   Australia  (21,322 posts)  [Biography] bio   Forum Administrator
Date Reply #1 on Sat 29 Apr 2017 10:07 AM (UTC)
Message
The simple thing would be to find when you last used the trigger (eg. with os.time ()) and only respond if (say) 5 seconds have elapsed since you last responded.

- Nick Gammon

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

Posted by Marco   (36 posts)  [Biography] bio
Date Reply #2 on Sat 29 Apr 2017 11:36 AM (UTC)

Amended on Sat 29 Apr 2017 11:41 AM (UTC) by Marco

Message
Nick Gammon said:

The simple thing would be to find when you last used the trigger (eg. with os.time ()) and only respond if (say) 5 seconds have elapsed since you last responded.


As always a light in the shadows.
Yes you are right Nick, but is not enough.

Most probably i'm too naive (noob) to fully understand if the solution you suggested should work, but some doubts come to my mind. So, please, let me underline something a second time, and forgive me if you already take that in consideration and it's only a problem of my understanding.

The output given with 9 entries happen istantly in the same "round", all together, and that fires the script 9 times with the
 "stand; flee" 
sent 9 times with a nonsense action, a lag in acting and the possibility to be catch again by the nice (only by the name) Disney warrior-mage beast and likely to be killed and scrapped.

It should be wise that the first few code lines contain a deactivation of the trigger AND the memorization of the time value (like you suggested) used then to timing the reactivation of the same.

If you all please could suggest some code solution or simply a suggestion i would be so glad!
[Go to top] top

Posted by Marco   (36 posts)  [Biography] bio
Date Reply #3 on Sat 29 Apr 2017 02:30 PM (UTC)

Amended on Sat 29 Apr 2017 06:26 PM (UTC) by Marco

Message
------- later Edited ----------

Marco said:

If you all please could suggest some code solution or simply a suggestion i would be so glad!


In the meanwhile I'll try myself something then i'll post here the code.
Anyways i don't know how to stop ONLY THAT trigger instead of them all.

That's why i asked if, besides the old examples that blocked ALL triggers, there is the possibility to stop the specific trigger and the istructions / commands i should use.
In the forum,
Template:post=7991 Please see the forum thread: http://gammon.com.au/forum/?id=7991.

i found Nick at a point made something like:
-- if ends with quote, end of multi-line chat
  if line:sub (-1) == '"' then
    EnableTrigger ("multi_line_chat", false)  -- no more lines to go
  else
    EnableTrigger ("multi_line_chat", true)  -- capture subsequent lines
  end -- if

So it'll be enough i give a name to the Trigger and use "EnableTrigger" to deactivate and activate it again after few seconds?
I could store the value of the time in a local variable and make all the calculation there.

Someone knows in which format "os.time ()" operates?
[Go to top] top

Posted by Meerclar   USA  (733 posts)  [Biography] bio
Date Reply #4 on Sat 29 Apr 2017 05:38 PM (UTC)
Message
Little simpler a solution would be to disable the trigger immediately and have 2 trigger to enable it - 1 for failed fleeing, one for successful fleeing. You can even use a common group for any other autoflee triggers to have keep them from spamming you.

Meerclar - Lord of Cats
Coder, Builder, and Tormenter of Mortals
Stormbringer: Rebirth
storm-bringer.org:4500
www.storm-bringer.org
[Go to top] top

Posted by Marco   (36 posts)  [Biography] bio
Date Reply #5 on Sat 29 Apr 2017 06:03 PM (UTC)

Amended on Sat 29 Apr 2017 06:25 PM (UTC) by Marco

Message
Meerclar said:

Little simpler a solution would be to disable the trigger immediately and have 2 trigger to enable it - 1 for failed fleeing, one for successful fleeing. You can even use a common group for any other autoflee triggers to have keep them from spamming you.


Thank you Meerclar, could be good.
Anyhow require the two activating triggers to be enabled ONLY when the main one fired, so, in a way, i have to use for those, what it's supposed to be used for the former.

I know it'll work perfectly, but i would like to try something as simple as possible.

Thank you for your support.
I would be pleased to understand if what i asked in my previous reply n°3; just re-edited and updated, is possible. .
[Go to top] top

Posted by Meerclar   USA  (733 posts)  [Biography] bio
Date Reply #6 on Sat 29 Apr 2017 06:47 PM (UTC)

Amended on Sat 29 Apr 2017 06:52 PM (UTC) by Meerclar

Message
From a difficulty to write perspective, my solution is worlds easier than capturing os.time and manipulating timers to enable/disable a single trigger.

Trigger 1 (and all of your autoflee triggers) get a group name of say, autoflee and as their final operation, disable the autoflee trigger group

Trigger 2 and 3 enable the autoflee group based on your successful and failed flee messages respectively.

You aren't going to find a simpler solution that doesn't require a solid working knowledge of timers and callbacks and I'm not entirely certain I'd call those simpler even knowing how to write them.

As for how to write such triggers, a forum search for EnableTriggerGroup (or EnableTrigger if individual triggers) gets you a great many very easy to work from example, one of which Nick helped me lock down.

Meerclar - Lord of Cats
Coder, Builder, and Tormenter of Mortals
Stormbringer: Rebirth
storm-bringer.org:4500
www.storm-bringer.org
[Go to top] top

Posted by Nick Gammon   Australia  (21,322 posts)  [Biography] bio   Forum Administrator
Date Reply #7 on Sat 29 Apr 2017 08:01 PM (UTC)

Amended on Sat 29 Apr 2017 08:02 PM (UTC) by Nick Gammon

Message
Marco said:

So it'll be enough i give a name to the Trigger and use "EnableTrigger" to deactivate and activate it again after few seconds?


Yes, just use EnableTrigger in the trigger and make it disabled (second argument would be false). Of course, the trigger has to "send to script" not directly to the MUD. So your sending text would be:


EnableTrigger ('mytrigger', false)
Send "stand"
Send "flee"


Where 'mytrigger' is the name you give to the trigger.




As for re-enabling, you could find suitable text that re-enables it (eg. changing rooms) or set up a one-shot timer.

For example:


DoAfterSpecial(5, "EnableTrigger ('mytrigger', true)", sendto.script)


(That would also be done in the trigger above). Eg.


EnableTrigger ('mytrigger', false)
DoAfterSpecial(5, "EnableTrigger ('mytrigger', true)", sendto.script)
Send "stand"
Send "flee"





Marco said:

Someone knows in which format "os.time ()" operates?


Look at the documentation in the help. It returns seconds.

http://www.gammon.com.au/scripts/doc.php?lua=os.time

- Nick Gammon

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

Posted by Marco   (36 posts)  [Biography] bio
Date Reply #8 on Sun 30 Apr 2017 05:05 AM (UTC)

Amended on Sun 30 Apr 2017 05:28 AM (UTC) by Marco

Message
Nick Gammon said:


EnableTrigger ('mytrigger', false)
DoAfterSpecial(5, "EnableTrigger ('mytrigger', true)", sendto.script)
Send "stand"
Send "flee"


Oh, my! Brilliant! But most surprising was that i spent a lot of time in the forum and i was starting thinking something similar (i swear!), even though i had many doubts about the syntax and you saved me a lot of time! In fact i remember the tread of   DoAfter   in the FAQ
Template:faq=25 Please read the MUSHclient FAQ - point 25.

But i would have failed. In fact you use a different instruction   DoAfterSpecial . Great!

So, yes, i think that the solution found by Meerclar was good because the reactivation happened only in "" Safety "" conditions, but this one is what i was looking for since the beginning, so yeah... thank you a lot for that, Nick.

So i'm going to use this solution and post what will happen.

Nick Gammon said:

As for re-enabling, you could find suitable text that re-enables it (eg. changing rooms)

That's clever and avoid many problems...


Nick Gammon said:

Marco said:

Someone knows in which format "os.time ()" operates?


Look at the documentation in the help. It returns seconds.

http://www.gammon.com.au/scripts/doc.php?lua=os.time


Yes, sorry. I had to think about it without asking.
Thank you very much Nick and thank you Meerclar also, because of your prompt support.
See you for the next topic!
[Go to top] top

Posted by Marco   (36 posts)  [Biography] bio
Date Reply #9 on Sun 30 Apr 2017 07:31 AM (UTC)

Amended on Sun 30 Apr 2017 04:02 PM (UTC) by Marco

Message
Edited: YES! It works GREAT! i will tune the parameters to fit better as possible the situation required and the timing in the MUD. That's the code at the moment.

EnableTrigger ('shere', false)
Execute ("stand; flee")
-- Execute ("order follower guard on") ** optional param. i'll use later
ColourNote ("yellow", "", " .    .    .      .    .    .    .     .     ====     S  H  E  R  E      K  H  A  N    ! ! !       ====")
ColourNote ("yellow", "", " .    .    .      .    .    .    .     .     ====     S  H  E  R  E      K  H  A  N    ! ! !       ====")
ColourNote ("yellow", "", " .    .    .      .    .    .    .     .     ====     S  H  E  R  E      K  H  A  N    ! ! !       ====")
DoAfterSpecial(4, "EnableTrigger ('shere', true)", sendto.script)
DoAfterNote (4.1, "- - - - - - -         Trigger Enabled         - - - - - -")

As you can imagine the trigger is named  'shere' .
I reduced a bit the delay to 4 seconds and i prefered use an  Execute  instead of  Send  only because of MUD problems (... ... ...) so i can put two different command in a row with a  " ; "  to stack those.

The  ColourNote  just to make a video notification.
Note that i put the reactivation of the trigger at the End of the procedure so that  stand; flee  can be executed quickly after the deactivation of the trigger.

Thank you!
[Go to top] top

Posted by Marco   (36 posts)  [Biography] bio
Date Reply #10 on Sun 30 Apr 2017 04:20 PM (UTC)

Amended on Mon 01 May 2017 10:36 AM (UTC) by Marco

Message
TWO Last Questions:

1) Is there a place in MUSHclient where the last direction taken is stored? I would like using a table to reverse this direction (e.g. if went   nord  , i came from   south   obviusly, so i'd like to memorize   south   in the variable.

2) Is there a status, a variable or something else to understand if you are engaged in combat OR NOT, so, in the latter instead of  stand; flee  i could choose to go back in the direction i came from?

- - - E D I T - - -     i could do something like that
Note(SetMapping (true))  -- i activate automapping when i'm going to shere khan area
if string.match (line, "^*.+hits you") then  -- i'll find the best string here to much when engaged, maybe the prompt..
  local num_item = Note(GetMappingCount ()) -- count item in automap (from 0 to n)
  local last_dir = Note(GetMappingItem(num_item-1)) -- get last direction
  Note(ReverseSpeedwalk (last_dir)) -- execute a reverse speedwalk only for the last direction
  Note(GetRemoveMapReverses (true)) -- remove the backtracks from automap 
end -- if

Could it works?
The only think, is find the best way to check if i'm battling (engaged) with Shere Khan or not.
[Go to top] top

Posted by Marco   (36 posts)  [Biography] bio
Date Reply #11 on Mon 01 May 2017 10:40 AM (UTC)

Amended on Mon 01 May 2017 05:19 PM (UTC) by Marco

Message
It doesn't work... i got

Error number: 0
Event:        Run-time error
Description:  [string "Trigger: shere"]:2: bad argument #1 to 'match' (string expected, got nil)

stack traceback:

	[C]: in function 'match'

	[string "Trigger: shere"]:2: in main chunk
Called by:    Immediate execution


Understood that  line  is  Nil  'cause in the former example was the argument of the Function  Chat  .

My hope was the client was capturing the text (like when it is logging) and i could access to that text in someway.

Sorry for my trivial questions but i'm really new to this.
Instead of looking in the " line " (nil) i've cahnged the check like this
if not string.match ("%1", "^.*(ti graffia|ti morde|ti colpisce)") =="" then
   Execute ("stand; flee")
else
  local num_item = Note(GetMappingCount ()) -- count item in automap (from 0 to n)
  if not num_item == 0 or not num_item == nil then 
     local last_dir = Note(GetMappingItem(num_item-1)) -- get last direction
     print ("last_dir".. last_dir) -- this part is never printed so this condition never happend... mmm....
     Note(ReverseSpeedwalk (last_dir)) -- execute a reverse speedwalk only for the last direction
     --Note(GetRemoveMapReverses (true)) -- remove the backtracks from automap
  end -- if
end -- if
ColourNote ("yellow", "", ".    .    .     .     ====     S  H  E  R  E      K  H  A  N    ! ! !       ====")
DoAfterSpecial(4, "EnableTrigger ('shere', true)", sendto.script)
DoAfterNote (4.1, "                                       - - - - - - -         Trigger Enabled         - - - - - - - ")

Now the problem is the  sting.match  doesn't accept the   |   pipe simbol.
In fact when i try without branching the pattern is recognized and  sting.match  gives a NOT  nil  value.

Mmmmm.... what am i doing wrong?
EDIT: just read some of the plugin in world_plugin directory and i'm astoneshed how human being be able to write such a complicated code. Compliment Nick your mind so powerful (no joke here, i'm serious. I've got headhache
:_)
[Go to top] top

Posted by Nick Gammon   Australia  (21,322 posts)  [Biography] bio   Forum Administrator
Date Reply #12 on Tue 02 May 2017 04:16 AM (UTC)

Amended on Tue 02 May 2017 04:17 AM (UTC) by Nick Gammon

Message
Marco said:

TWO Last Questions:

1) Is there a place in MUSHclient where the last direction taken is stored? I would like using a table to reverse this direction (e.g. if went nord , i came from south obviusly, so i'd like to memorize south in the variable.


I have some tips here: http://www.gammon.com.au/forum/?id=12635

First you need a couple of tables:


-- -----------------------------------------------------------------
-- these commands will be considered "room changing" commands
-- -----------------------------------------------------------------
local valid_direction = {
  n = "n",
  s = "s",
  e = "e",
  w = "w",
  u = "u",
  d = "d",
  ne = "ne",
  sw = "sw",
  nw = "nw",
  se = "se",
  north = "n",
  south = "s",
  east = "e",
  west = "w",
  up = "u",
  down = "d",
  northeast = "ne",
  northwest = "nw",
  southeast = "se",
  southwest = "sw",
  ['in'] = "in",
  out = "out",
  }  -- end of valid_direction
  
-- for calculating the way back
local inverse_direction = {
  n = "s",
  s = "n",
  e = "w",
  w = "e",
  u = "d",
  d = "u",
  ne = "sw",
  sw = "ne",
  nw = "se",
  se = "nw",
  ['in'] = "out",
  out = "in",
  }  -- end of inverse_direction


Now you detect when you send a movement command:


-- -----------------------------------------------------------------
-- try to detect when we send a movement command
-- -----------------------------------------------------------------
function OnPluginSent (sText)
  last_direction_moved = valid_direction [sText]
end -- OnPluginSent


Now a table lookup tells you the inverse (way back) of the last direction you moved:


goback = inverse_direction [last_direction_moved]

- Nick Gammon

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

Posted by Nick Gammon   Australia  (21,322 posts)  [Biography] bio   Forum Administrator
Date Reply #13 on Tue 02 May 2017 04:18 AM (UTC)
Message
Marco said:

2) Is there a status, a variable or something else to understand if you are engaged in combat OR NOT, so, in the latter instead of stand; flee i could choose to go back in the direction i came from?


No, the client doesn't know if you are in combat or not. You could detect (with triggers) messages that indicate you are in combat (eg. * hits you with * HP) and other triggers that indicate the combat is over. Between them you could set up your own flag.

- Nick Gammon

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

Posted by Nick Gammon   Australia  (21,322 posts)  [Biography] bio   Forum Administrator
Date Reply #14 on Tue 02 May 2017 04:20 AM (UTC)

Amended on Tue 02 May 2017 04:21 AM (UTC) by Nick Gammon

Message
Marco said:

Now the problem is the string.match doesn't accept the | pipe simbol.
In fact when i try without branching the pattern is recognized and string.match gives a NOT nil value.


Yes, that is a Lua pattern-match, not a PCRE one. You can use the PCRE matching as described here:

http://www.gammon.com.au/scripts/doc.php?lua=re:match

- 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.


3,526 views.

This is page 1, subject is 2 pages long: 1 2  [Next page]

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 FutureQuest]