Register to post in forums, or Log in to your existing account
 

Play RetroMUD
Post new topic  Reply to topic     Home » Forums » CMUD General Discussion
deathkitty
Apprentice


Joined: 14 Apr 2008
Posts: 105

PostPosted: Tue Apr 22, 2008 6:10 pm   

getting rid of brackets in a pattern for setting a target variable has brackets
 
here is the current trigger:
Pite moves aggressively towards &target!

Normally, this works fine and I can then use macro buttons to quickly attack the target without typing name, but sometimes there are NPCs with brackets in their names and you cannot attack them when you include the brackets, so I need to get rid of them, while the trigger will still work for normal NPCs without them.

summary:
here's the mud text:
Pite moves aggressively towards the scary mugger (hiding)!

I want it to only capture as @target "scary mugger", not the (hiding) bit. but if say, the pattern was
Pite moves aggressively towards the Triad thug!
I also need that to still work


Any ideas please anyone? I have no clue what to do from here :(


Last edited by deathkitty on Fri Apr 25, 2008 6:10 pm; edited 1 time in total
Reply with quote
Fang Xianfu
GURU


Joined: 26 Jan 2004
Posts: 5155
Location: United Kingdom

PostPosted: Tue Apr 22, 2008 6:21 pm   
 
#trig {Pite moves aggressively towards ([^~(])*!} {#var target %1}

[^~(] means "any character that's not a bracket"
_________________
Rorso's syntax colouriser.

- Happy bunny is happy! (1/25)
Reply with quote
Dharkael
Enchanter


Joined: 05 Mar 2003
Posts: 593
Location: Canada

PostPosted: Tue Apr 22, 2008 6:43 pm   
 
maybe a trim to rid yourself of the inevitable trailing space.
#var target %trim(%1)
_________________
-Dharkael-
"No matter how subtle the wizard, a knife between the shoulder blades will seriously cramp his style."
Reply with quote
deathkitty
Apprentice


Joined: 14 Apr 2008
Posts: 105

PostPosted: Wed Apr 23, 2008 6:50 pm   
 
Dharkael I don't understand what that is meant to do? I am not worried about spaces I am worried about the " (hiding)" bit which I need removed

Fang Xianfu you misunderstand I think: I still want to attack the hiding scary mugger, I still want it in the pattern, but I want it to be captured in the @target variable as "scary mugger" instead of "scary mugger (hiding)"
Reply with quote
Fang Xianfu
GURU


Joined: 26 Jan 2004
Posts: 5155
Location: United Kingdom

PostPosted: Wed Apr 23, 2008 7:14 pm   
 
No, I understood you perfectly, and that's exactly what that trigger does. The &variable syntax is horrible to look at and to use, so I didn't use it in this example - rather, I specified the pattern's captures myself and then put what needed capturing in the variable later.

Seriously, it works. Try it out.

Code:
#trig {Pite moves aggressively towards ([^~(])*!} {#say %1}
#say "Pite moves aggressively towards the scary mugger!"
#say "Pite moves aggressively towards the scary mugger (hiding)!"


Both give the same result, that is "the scary mugger".

Dharkael's point is that the way I have it set up now, your target will always end in a space. It doesn't really matter, but if you want to get rid of it, you need to use the %trim function like he suggested.
_________________
Rorso's syntax colouriser.

- Happy bunny is happy! (1/25)
Reply with quote
Taz
GURU


Joined: 28 Sep 2000
Posts: 1395
Location: United Kingdom

PostPosted: Wed Apr 23, 2008 7:16 pm   
 
Well you probably want to change Pite to something like %w so it doesn't just match that person it'll match other people as well as long as they only have one word as a name, although the trigger isn't anchored so that probably doesn't matter.

Anyway I just tested what Fang gave you and it works fine, although it does capture "the" into the variable as well and I don't know if "the scary mugger" will cause you problems.
_________________
Taz :)
Reply with quote
oldguy2
Wizard


Joined: 17 Jun 2006
Posts: 1201

PostPosted: Thu Apr 24, 2008 12:26 am   
 
If you only want to capture what the actual thing is you can use this.

Code:
^\w+ moves aggressively towards [\w ]* (\w+)[^!]*!


The outcome would be:

Pite moves aggressively towards the scary mugger!
Target = mugger
Pite moves aggressively towards the scary mugger (hiding)!
Target = mugger
Pite moves aggressively towards scary mugger!
Target = mugger
Pite moves aggressively towards the big scary hooded mugger (hiding in the bushes)!
Target = mugger
Reply with quote
deathkitty
Apprentice


Joined: 14 Apr 2008
Posts: 105

PostPosted: Fri Apr 25, 2008 5:42 pm   
 
ok.... how would I go about making it also exclude small green scorpion, black cat, or black cloud?

to try give you an idea of what i am trying to do here's what i have it as at the moment:
^Pite moves aggressively towards the {^small green scorpion|black cat|black cloud}&target!

with an example of the thing I want to capture being the same as before, and the result I wanting the same as before (I actually want the bit just before mugger, like scary mugger or snarling mugger so I can differentiate if there is more than one being attacked by my group) - I still need the (hiding) bit stripped

those ones with lots of square brackets are regex ones right? i dont really understand those only the zmud ones so far :S so it's hard for me to tell what of the above stuff I actually should use
Reply with quote
shalimar
GURU


Joined: 04 Aug 2002
Posts: 4798
Location: Pensacola, FL, USA

PostPosted: Fri Apr 25, 2008 6:04 pm   
 
#TR {moves aggressively towards (*)!} {
$thisTarget=%replace(%1, " (hiding)", "")
$excludeList="the black cat|a small green scorpion|ect"
#IF (%ismember($thisTarget, $excludeList)) {do nothing} {do something}
}
_________________
Discord server
Reply with quote
deathkitty
Apprentice


Joined: 14 Apr 2008
Posts: 105

PostPosted: Fri Apr 25, 2008 6:26 pm   
 
thanks shalimar that kind of works, but how do I get it to set a variable from the new bit? when I put target = %1 in the 'do something' bit, it just uses the original unedited captured bit, so "a snarling mugger (hiding)" instead of "a snarling mugger" (for example)


(this is what i did:)
$thisTarget=%replace(%1, " (hiding)", "")
$excludeList="the black cat|a small green scorpion|ect"
#IF (%ismember($thisTarget, $excludeList)) {} {target = %1}

the idea isnt to actualy do an action as such just capture it in a variable so i can push a macro button to attack the named @target
Reply with quote
Fang Xianfu
GURU


Joined: 26 Jan 2004
Posts: 5155
Location: United Kingdom

PostPosted: Fri Apr 25, 2008 8:01 pm   
 
Use $thisTarget instead of %1.
_________________
Rorso's syntax colouriser.

- Happy bunny is happy! (1/25)
Reply with quote
oldguy2
Wizard


Joined: 17 Jun 2006
Posts: 1201

PostPosted: Sat Apr 26, 2008 1:26 am   
 
You can set a target to "a snarling mugger"? Weird.
Reply with quote
Display posts from previous:   
Post new topic   Reply to topic     Home » Forums » CMUD General Discussion All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

© 2009 Zugg Software. Hosted by Wolfpaw.net