About Us
Products
Purchase
Downloads
Support
Forums
Contact Us
Site
 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
chris123zugg
Adept


Joined: 23 Aug 2013
Posts: 214

PostPosted: Thu Apr 03, 2025 10:27 pm   

Trying to use match for a script
 
Code:
$monsters = 0
#IF %match(%1, "A Spiral Gun") {$monsters = $monsters+1;monster = "gun"}
#IF %match(%1, "A Groma") {$monsters = $monsters+1;monster = "groma"}
#IF %match(%1, "A Cloud Eye") {$monsters = $monsters+1;monster = "eye"}
#IF %match(%1, "A Clone Soldier") {$monsters = $monsters+1;monster = "soldier"}
#IF %match(%1, "A Leago") {$monsters = $monsters+1;monster = "leago"}
#IF %match(%1, "A Leeva") {$monsters = $monsters+1;monster = "leeva"}
#IF %match(%1, "A Ripper") {$monsters = $monsters+1;monster = "ripper"}
#IF %match(%1, "A Massive Generator") {$monsters = $monsters+1;monster = "generator"}
#IF %match(%1, "Zamuza") {$monsters = $monsters+1;monster = "zamuza"}
#IF %match(%1, "Balba") {$monsters = $monsters+1;monster = "balba"}
#IF %match(%1, "Brain") {$monsters = $monsters+1;monster = "brain"}
#IF %match(%1, "Galga", "Zamuza", "Balba", "Brain", "Generator") {$monsters = $monsters+1;#if (@monster == "balba" || @monster == "brain" || @monster == "zamuza" && @monster == "galga" ) {#10 truce;k %1}}
#ala "heh" {+2} {#print $monsters}


In this im trying to ensure if there's more than 1 monster in the room via $monsters and if the trigger see's the monsters names galga/brain etc AND there are more than 1 monster in the room to truce X 10. it pretty much works but im asking here if there's a better way of doing it? Thanks in advance!
Reply with quote
shalimar
GURU


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

PostPosted: Sun Apr 06, 2025 11:38 am   
 
You need to wrap the equation in parentheses for it to evaluate.
This is also true of the #IF statement for best results

$monsters = ($monsters+1)

#IF (%ismember(@monster, "Galga|Zamuza|Balba|Brain|Generator")) {#10 truce;k @monster}

%ismember can test against a list
and since it would have incremented your variable already in a previous match, there is no need to increment again.
_________________
Discord: Shalimarwildcat
Reply with quote
chris123zugg
Adept


Joined: 23 Aug 2013
Posts: 214

PostPosted: Sun Apr 06, 2025 11:58 am   
 
Code:

<?xml version="1.0" encoding="ISO-8859-1" ?>
<cmud>
  <trigger name="seczmobs" type="Loop Pattern" param="10" priority="240" copy="yes">
    <pattern>^!(*)$</pattern>
    <value>$monsters = 0
#IF %match(%1, "A Spiral Gun") {monster = "gun"}
#IF %match(%1, "A Groma") {monster = "groma"}
#IF %match(%1, "A Cloud Eye") {monster = "eye"}
#IF %match(%1, "A Clone Soldier") {monster = "soldier"}
#IF %match(%1, "A Leago") {monster = "leago"}
#IF %match(%1, "A Leeva") {monster = "leeva"}
#IF %match(%1, "A Ripper") {monster = "ripper"}
#IF %match(%1, "A Massive Generator") {monster = "generator"}
#IF %match(%1, "Zamuza") {monster = "zamuza"}
#IF %match(%1, "Balba") {monster = "balba"}
#IF %match(%1, "Brain") {monster = "brain"}
#IF (%ismember(@monster, "Gun|Groma|Eye|Soldier|Leago|Leeva|Ripper")) {$monsters = ($monsters+1)}
#IF (%ismember(@monster, "Galga|Zamuza|Balba|Brain|Generator")) {$monsters = ($monsters + 1);#IF ($monsters > 1) {#10 truce;k @monster}}
#ala "heh" {+2} {#print $monsters}
</value>
  </trigger>
</cmud>



I changed this to loop pattern as its stopped at the first instance and wont process the rest of the monsters in the room. I need it to count all of them and if its more than 1 truce and then attack just 1. whats happeneing is its seeing the first group counting 1, then seeing the second group and attacking it too.
Also, it's not adding the two groups even though each pattern match nulls out the monsters, and then re-adds them i think is why its not adding properly.
Reply with quote
shalimar
GURU


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

PostPosted: Sun Apr 06, 2025 12:32 pm   
 
I am guessing this could do with a better pattern then just *, then you could use the repeat within line checkbox, or perhaps use the comma delineation to better establish your count.

Can you show us a complex example of a line this would be expected to fire on seeing?
_________________
Discord: Shalimarwildcat
Reply with quote
shalimar
GURU


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

PostPosted: Sun Apr 06, 2025 1:36 pm   
 
But I would design a trigger like this off of a variable.
In this case it would be key=value pairs, which we can preload with your known values like so:

#ADDKEY mobList {A spiral Gun=gun|A Groma=groma|A Cloud Eye=eye|A Clone Soldier=soldier|And So On=etc}

Then you could do something like:

#TR {({@mobList})*is standing here.$} {target=%db(@mobList, %1)}
_________________
Discord: Shalimarwildcat
Reply with quote
chris123zugg
Adept


Joined: 23 Aug 2013
Posts: 214

PostPosted: Sun Apr 06, 2025 1:55 pm   
 
^!(*)$ is the pattern match
however the ! is ONLY for monsters, so there's no way to really make this fail based on other things in the "room"
as there is never anything in the room desc etc. that would have a ! in it.
Reply with quote
shalimar
GURU


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

PostPosted: Sun Apr 06, 2025 6:19 pm   
 
Yea, that is unlikely to give a false match.
Doesn't really change how I would approach the problem, though.

Whether you use a bunch of if statements, or a database variable, you are still working off a known list.
Then it becomes a matter of personal preference, ease of expansion and legibility.

Is each mob on its own line?
_________________
Discord: Shalimarwildcat
Reply with quote
chris123zugg
Adept


Joined: 23 Aug 2013
Posts: 214

PostPosted: Sun Apr 06, 2025 7:19 pm   
 
sorry yes they do.


~Section 15 (w,d,u,sw)
!A Leago [wounded] attacking you!.
!A Leago.
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