random delay and many trigtexts

Posted by Doorie on Sat 10 Oct 2009 07:04 PM — 7 posts, 28,433 views.

Finland #0
hello!

first time in here, so here i go:

1) i need to have a random delay between the trigger text and the action i want. delay time something like n+(1.000 - 10.000) seconds. i tried searching functions and also searched here in forums, but couldn't find a solution.

2) there are several death messages in mud what i use, and i have them all triggered for some action. instead of having 10 different ones, can i have some kind of: "trigtext1"|"trigtext2" solution, so taht i can have only one trigger?

thank you:)

-s-

USA #1
Hello! Welcome to the forums ;)

1) You can use the scripting function DoAfter. Example:

DoAfter(10, "text to send")


The first parameter is the delay, in seconds, before that text is sent. This creates a temporary MUSHclient timer, and does NOT pause the actual script - it just tells MUSHclient it wants to do something later, and continues doing whatever comes after the DoAfter call.

If you want to randomize the time it takes, you could do...


DoAfter(MtRand()*9+1, "text to send")


You'll want to put MtSrand(os.time()) in your scripting file too, so that the random-number generator always gives you a different sequence instead of starting with the same one every time.


2) Yep! With "Regular expression" enabled, you can do something like:

^(deathmessage1|deathmessage2|deathmessage3)$


If you don't know much about regular expressions, I'd learn up on them. Regex is very powerful when it comes to triggers (and aliases). A good website is here[1].


[1]: http://www.regular-expressions.info/
Amended on Sat 10 Oct 2009 07:43 PM by Twisol
Finland #2
this does not match:

^(* unanimated corpse falls to the ground.|* staggers to the ground ... dead.)$

do i need some leading char in front of * char? or . char?

(how do i put that stuff into code-box?)
USA #3
While "* unanimated corpse falls to the ground." will work in non-regex triggers, * means something entirely different in regex. This is what you'd want:


^(.+? unanimated corpse falls to the ground\.|.+? staggers to the ground \.\.\. dead\.)$


.+? breaks down like this:

'.' is any single character. Anything at all.
'+' is a modifier, meaning "one or more". Together with the dot, it matches one or more of anything.
'?', when used after the + in this case, is a secondary modifier. Advanced topic, but it changes the "greediness" of the match. With the ?, it'll try to match one of anything, two of anything, three of anything, etc. in that order. Without it, it'll try to match as much as possible, then as much as possible minus one, etc. Trust me, this works better with the ?.

It's basically the regex-ified version of the non-regex *. You'll also notice slashes before the other dots in the triggers - that's because we want it to match a literal dot, and not 'anything'.
Amended on Sun 11 Oct 2009 09:48 AM by Twisol
Finland #4
ok, works, kinda..

to clarify: i don't use this trigger in script file, but 'inside' alt-enter -> triggers.

previously, i was able to fish out %1 parameter, which would be the name of the mob. now it is impossible, the first parameter is the whole death message line, not the * -char, which was able to rely it before.

who can i fish out the mob name, (* == %1) when using regexps?

i tried with (.*?) and with (.+?) but the same result..
USA #5

^(?:(.+?) unanimated corpse falls to the ground\.|(.+?) staggers to the ground \.\.\. dead\.)$


I changed the outer () to a (?:), which means it doesn't capture it and store it in %1, and surrounded the targets inside with () so they ARE captured. Try this one.
Australia Forum Administrator #6
Template:regexp
Regular expressions
  • Regular expressions (as used in triggers and aliases) are documented on the Regular expression tips forum page.
  • Also see how Lua string matching patterns work, as documented on the Lua string.find page.