Trigger / Script Question : Targetting / Auto-Attack

Posted by Mattrious on Mon 04 Nov 2024 09:07 PM — 7 posts, 11,057 views.

#0
Good afternoon,

I am sure this has been asked a few time over the years, and I can assure you that I've dug through the all forums and posts over the years. Watched some of Nick's videos and exhausted ChatGPT to the point I think they're going to cancel my subscription.

I am trying to figure out to setup a pretty straight forward script where, I set a target and then when I walk into a room with an NPC, the client will issue some sort of attack or other command, etc.

I can get the targetting stuff setup with variables without issue. Though, I am trying to figure out how to setup an auto-attack feature (use a 'charge' or 'kill' etc).

So recalling back to Nick's video back from 2009 -- I easily got the process setup of setting a target, and then easily creating an alias to inititate a command.

My goal, is to take that one step further and as I walk into a room, the client would see <NPC is here> and then if it matches the target, it would attack.

[Exits: north east south west]
There is a goblin here, lazing behind a pile of recently gathered stones.
There is a goblin here, lazing behind a pile of recently gathered stones.

So pasted above is just the exits and then mobs (not the full room name, description or ASCII map).

The goal would be to set goblin as a target, and when my character walked into the room, it would attack the goblin.

Is there a way to do this? I can get triggers and such to work easily with:

You are thirsty.
<drink cup>

I just can not figure out how to get the client to attack a create or mob that I run into while walking.
Australia Forum Administrator #1
Didn't I cover that in the tutorials?

Assuming you have a targetting alias that saves the target into a variable (which is certainly mentioned in the tutorials), say call the variable "target", then make a trigger:

Match on: There is a @target *
Expand variables: checked
Send: kill @target
#2
Nick Gammon said:

Didn't I cover that in the tutorials?

Assuming you have a targetting alias that saves the target into a variable (which is certainly mentioned in the tutorials), say call the variable "target", then make a trigger:

Match on: There is a @target *
Expand variables: checked
Send: kill @target


If you did, I must have missed it. I watched your relatively straight forward of creating a target and setting up variables -- but couldn't find anything that set upt he autoattacking piece. I'll go back and do a bit more digging a long with what you've provided here. Thank you as always Nick. Hope you're doing well.
Australia Forum Administrator #3
That was what I was talking about ... creating a target variable.
#4
Nick Gammon said:

That was what I was talking about ... creating a target variable.


I understand. I created the variable and had no issue with that. I was just a bit confused on creating a system where a trigger/script would see said target in a room as I am walking and inititate an attack command, such as kill, charge, etc.

I do have one additional question. Is there a way to make the trigger dynamic? So that @target will just fire on a single keyword and not have to see a string like:

A @target is *

The @target *

Something like (?i)\b@target\b

I've been playing around with it and can not get that puiece to work, so I need to edit the @target string for different NPCs that have different short-descriptions, etc.
Australia Forum Administrator #5

<triggers>
  <trigger
   enabled="y"
   expand_variables="y"
   match="(?i)^There is .* \b@target\b"
   regexp="y"
   sequence="100"
  >
  <send>kill @target</send>
  </trigger>
</triggers>


Template:pasting
For advice on how to copy the above, and paste it into MUSHclient, please see Pasting XML.


A bit of testing showed that you need to match on more than just the target name, otherwise it will match every time the target appears in the output (eg. "you attack the gnoll", "you punch the gnoll", "the gnoll dies") would all cause the trigger to fire again, unwanted.
Amended on Wed 06 Nov 2024 08:35 PM by Nick Gammon
#6
Awesome! Thank you for this Nick. You're a rockstar -- and much appreciated for all the work you've done with this software over the years.