Targetting help

Share your scripts and packages with other Mudlet users.
chrio
Posts: 73
Joined: Mon Aug 22, 2016 11:34 am

Re: Targetting help

Post by chrio »

Like you said, saving the command to a variable and re-sending that is probably how you want to do it. In your trigger actions you can save and send the command to a var like this:

spellcast = "cast heal on " .. matches[2]
send(spellcast)


Then you can just use the command action "send(spellcast)" to repeat the last spell sent when needed, for example by binding a key to that command, or using triggers.

If you use triggers to detect fizzle, I assume that you need a short delay before you recast the spell, that's when temporary timers comes in, like this: tempTimer(1.5, [[ send(spellcast) ]]) which waits for 1.5 seconds before running the command.

Duugan
Posts: 25
Joined: Fri Aug 26, 2016 4:00 am

Re: Targetting help

Post by Duugan »

That sounds pretty simple actually...

I thought I'd have to add variables in another window/tab. I suppose that is more for if you want variables to have a default 0, " ", MyNameIsBob, etc? for more advanced coding?

While we're talking variables, how would I get a trigger to capture a group of words? For example, when I forage it can be an orange root, a few pieces of grain, a handful of acorns....if I wanted to eat or drop or give said item away, I know (\w+) is a word, but how would I capture 3 to 5 words of varying length? Thanks again Chrio. I really appreciate the help!

User avatar
SlySven
Posts: 1019
Joined: Mon Mar 04, 2013 3:40 pm
Location: Deepest Wiltshire, UK
Discord: SlySven#2703

Re: Targetting help

Post by SlySven »

You put a pair of '('')' around the "capture group" in the perl regexp {which is why you have to escape actual '(' ')' 's in the expression with a '\' before each of them I believe} and the whole term ends up in the "matches" table with indexes starting from 2, you just have to express those groups of words in the correct way...

chrio
Posts: 73
Joined: Mon Aug 22, 2016 11:34 am

Re: Targetting help

Post by chrio »

Duugan wrote:While we're talking variables, how would I get a trigger to capture a group of words?
As mentioned earlier, \w means a word char meaning only letters and numbers. If you want to match any character you can use a dot.

\w+ one or more of a-zA-z0-9
.+ one or more of any character at all, spaces included

The parenthesis marks the different parts of the pattern you want to add to the matches array.

^(Foo) tells you: (Do this) and then (that)$
matches[1] -> Foo tells you: Do this and then that
matches[2] -> Foo
matches[3] -> Do this
matches[4] -> that

The highligt toggle on the trigger is used to mark the capture groups, and you can use display(matches) as the trigger action to see the content of the matches array.

Duugan
Posts: 25
Joined: Fri Aug 26, 2016 4:00 am

Re: Targetting help

Post by Duugan »

Ok. So if I wanted to match exact phrases it would be:
You scrounge up (some acorns)
You scrounge up (a handful of nuts)
You scrounge up (an orange root)
And then the script part would be...
Send("Eat '.. matches[2]'")
Send("Eat '.. matches[3]'")
Send("Eat '.. matches [4]'")?

If it's an unknown phrase it would be:
Soandso gives you (.+)\. <--- to end before the period?
And then:
Send("wear ".. matches[2]")

Am I close to getting that right? It seems like the first one would do better as single triggers, like you scrounge up an acorn > send eat acorn though...

Duugan
Posts: 25
Joined: Fri Aug 26, 2016 4:00 am

Re: Targetting help

Post by Duugan »

Also, an update on the variable for recasting... it works great. I tested it last night and it only had a small hiccup. If she asks for a heal and then later I manually cast a spell..... if I fizzle it resends the heal to her. Aside from making aliases for all my casting, is there another way to fix that? It's not a huge deal, but it's something.
One of my favorite parts about FF12 and Dragon Age Origins/2 was setting up tactics and getting them just right. This reminds me if that, but on an even bigger scale. It's awesome. :)

chrio
Posts: 73
Joined: Mon Aug 22, 2016 11:34 am

Re: Targetting help

Post by chrio »

Duugan wrote:Ok. So if I wanted to match exact phrases it would be:
You scrounge up (some acorns)
You scrounge up (a handful of nuts)
You scrounge up (an orange root)
And then the script part would be...
Send("Eat '.. matches[2]'")
Send("Eat '.. matches[3]'")
Send("Eat '.. matches [4]'")?
Almost. You will never get anything in matches[3] and [4]. They only get filled if you have more than one matching group in the same pattern row. Also, you have some problems mixing quotation marks for your strings.

Instead of using send, you can try out the trigger with echo(), and change it to send once you got it working the way you want.
Also, you can test triggers with `echo See forum post
Duugan wrote:Also, an update on the variable for recasting... it works great. I tested it last night and it only had a small hiccup. If she asks for a heal and then later I manually cast a spell..... if I fizzle it resends the heal to her. Aside from making aliases for all my casting, is there another way to fix that? It's not a huge deal, but it's something.
One of my favorite parts about FF12 and Dragon Age Origins/2 was setting up tactics and getting them just right. This reminds me if that, but on an even bigger scale. It's awesome. :)
Two ways to handle this that I can think of:

1) add another trigger for successful casts that disables the fizzle trigger, and enable the fizzle trigger in your cast-trigger-action. (see enableTrigger/disableTrigger)

2) in your cast-trigger-action, enable the fizzletrigger and add a temptimer that disables the fizzletrigger within a reasonable time.

You have to figure out how you handle multiple fizzles in a row too. You kan kill a temptimer before it goes off (and create it again if that's what you want).

Duugan
Posts: 25
Joined: Fri Aug 26, 2016 4:00 am

Re: Targetting help

Post by Duugan »

Would something like this work, then?
You scrounge up some (acorns)
You scrounge up a handful of (nuts)
You scrounge up an orange (root)
Send("eat ".. matches[2])?

Would that put whichever triggered word activated it in matches[2]?

Duugan
Posts: 25
Joined: Fri Aug 26, 2016 4:00 am

Re: Targetting help

Post by Duugan »

If I'm understanding how matches work, what you're saying is I could do something like this...

(\w+) says '(\w+)' as a perl regex and in the script
Target=matches[2]
Spell=matches[3]
Send("cast "Spell" "Target)<--is that how you would add a space?

That would, in theory, cast heal, fly, etc on the one talking?

chrio
Posts: 73
Joined: Mon Aug 22, 2016 11:34 am

Re: Targetting help

Post by chrio »

Duugan wrote:Send("cast "Spell" "Target)<--is that how you would add a space?

That would, in theory, cast heal, fly, etc on the one talking?
Almost. You need to concatenate the values using double dots.

So in your case you want: send("cast " .. Spell .. " " .. Target)
Green parts are strings, blue parts are variables.

Post Reply