Trigger help needed!

Post Reply
finality
Posts: 2
Joined: Sat Mar 20, 2010 10:18 pm

Trigger help needed!

Post by finality »

I am very new to mudlet, and so far, it's been intimidating. frankly, it isn't very user friendly, and a little hard to figure out how to get it to work. and by "it" I mean the triggers, aliases, and such. not to mention the llua script is...complicated.

I have been trying for quite a while now to set up targetted defensive triggers, with absolutely zero success.
I am an absolute newbie at programming/scripting, and know nothing about any language, except a few codes someone told me.

what I'm trying to do is make a trigger that sees an attack, such as.

9191h, 11659e, 0g xb A:50% -
Iggy weaves his hands slowly in the air, whispering as a crackling ball of
lightning forms in his hand.
7682h, 10653e, 0g xb A:40% - Iggy: Glowing -

and captures the name of the person attacking, then inputs it into the trigger.

for instance, it would see the trigger line, which would be
"Iggy weaves his hands slowly in the air"
except "Iggy" would be some code that captures the name.

then it would send this

"Duck "the code that represents Iggy's name""

as another example, in Cmud, the scripting code is, %1, all the way to %99.

so in Cmud, the very same trigger would be.
#trigger {%1 weaves his hands slowly in the air}
then it would fire this. {duck %1}

I think it's called a wildcard or something.

I have read this topic, http://forums.mudlet.org/viewtopic.php?f=9&t=1230, and tried out what the users said, but it didn't work. I also watched Vadi5's videos on youtube, and tried what he said, (for making alias wildcards, the (.*) ) but that didn't work either.

please! I really need some help on this!

User avatar
Vadi
Posts: 5042
Joined: Sat Mar 14, 2009 3:13 pm

Re: Trigger help needed!

Post by Vadi »

perl regex pattern: (\w+) weaves his hands slowly in the air
script: send("duck " .. matches[2])

like so: Image

I'd highly recommend watching the triggers screencast as well. Let me know how the trigger goes!

User avatar
Jules
Posts: 118
Joined: Sun Oct 11, 2009 5:41 pm
Location: Plymouth State University - Sophomore

Re: Trigger help needed!

Post by Jules »

Mudlet uses a system called 'Regular Expressions' to process wildcards. Regular Expressions (or regex) is incredibly powerful, though unless you know what you're doing, look like absolute black magic! I'll try to show you some examples of regex in action.

Vadi's example of your script is correct. the (\w+) regex captures any non-whitespace string. So, the trigger "Iggy weaves his hands slowly in the air" can be translated to:

Code: Select all

(\w+) weaves his hands slowly in the air
When using this code in the trigger, you have to tell Mudlet that it's a "perl regex" trigger, in the drop-down menu on the side.

There are other regex's that you can use to capture pretty much anything, though I'll only go over the most basic 3 here. (\w+) I covered above, which, again, captures any non-whitespace string (so it would capture 'ball' in the string 'a ball', if the pattern was 'a (\w+)'.

The next most common one is the regex for capturing numbers: (\d+). Works the same as (\w+), however this has an interesting caveat in Mudlet. Mudlet captures (\d+) as strings. That's fine in everyday use when you're trying to compare something (if 100 == 100 then do something end), however, if you want to do any math for, say, an autosipper, you'll have to take that captured variable and turn it into a number. Luckily, Mudlet comes with the handy-dandy 'tonumber()' function, that will take any string and convert it into a number!

And finally, the (.*) wildcard. This thing captures anything! If you have a trigger with (.*) in it, it'll be capturing pretty much any line coming from the MUD! This is most used in the same way that (\w+) is, though instead of one string, it captures all strings, whitespace included. So, it would capture 'a ball' in 'a ball is dropped', if the pattern was '(.*) was dropped'.

Now that you know a little about regex, how do you go about utilizing that in your scripts? Mudlet has a built-in table called 'matches'. 'matches[1]' captures the ENTIRE string, which you often do not want! So, when scripting, you want to start off at 2. matches[2] processes the information captured by (.*), 'a ball', in the pattern 'a ball is dropped', from the above example. Think of 'matches' the same way you would as %1-%99

finality
Posts: 2
Joined: Sat Mar 20, 2010 10:18 pm

Re: Trigger help needed!

Post by finality »

it's working! thanks a lot for all your advice.

I now come to another problem, that require's some help.

is there a way to code a...trigger system or something, that when you input a command, it would save it, and if it gets back a message "you cannot do that while prone." or something similar, it would execute another trigger, that would be, say, for the message up thar, "Stand", then it would RE-Input the command for you?

also, can ya'll tell me how to make the trigger wait a number of seconds before firing?

and yet another question!

how would one progam a trigger to check a variable?

for example.

I'm fighting someone, and he knocks me off my feet right after I attack, so I don't have any balance.

a trigger would see the message "blah kicks out at your feet, knocking you to the ground."
and would set a Prone variable to 1, or something.

then, another trigger would see that same proning message, and check the variable for balance, and if I don't have it, it would wait for the message "you have regained balance" and then It would set balance back to 0, or meaning I have it. then another trigger would check both balance, and prone variable, and if I have balance, and I am still prone, it would send the command "stand"

I know I'm not being very specific with this, and it might be a bit confusing. but I can try to explain more if need be.!

sephiel
Posts: 17
Joined: Mon Nov 30, 2009 10:35 am

Re: Trigger help needed!

Post by sephiel »

For the last bit:

^(\w+) kicks out at your feet, knocking you to the ground.$

Code: Select all

prone = 1
if balance == 1 then
   send("stand")
end
You have recovered balance on all limbs.

Code: Select all

balance = 1
if prone == 1 then
   send("stand")
end
In pretty basic terms, = is used to define a variable, and == is used to evaluate it.

Post Reply