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
Quit
Wanderer


Joined: 19 Jul 2008
Posts: 59

PostPosted: Fri Aug 02, 2013 9:08 pm   

Trigger Help
 
Hi

I play on Aardwolf and the mobs/player can have many different aura on them or zero :

(Invis) (Golden Aura) A tiny, winged creature buzzes merrily around you.
(Golden Aura) (White Aura) Gueldar the Armorer stands here, creating some new armor.
(Hidden) (Invis) (Red Aura) A rich haughty eldar strolls past, completely ignoring you.
A goblin carries a large money sack that reads 'Tax'.

I have made a string list @Mob_auras with all the aura but without the ()
Code:
<?xml version="1.0" encoding="ISO-8859-1" ?>
<cmud>
  <var name="Mob_auras" type="StringList" sorted="1" copy="yes">
    <value>Angry|Animated|Charmed|Diseased|Golden Aura|Hidden|Invis|Linkdead|Marked|Red Aura|Stealth|Translucent|Undead|White Aura</value>
    <json>["Angry","Animated","Charmed","Diseased","Golden Aura","Hidden","Invis","Linkdead","Marked","Red Aura","Stealth","Translucent","Undead","White Aura"]</json>
  </var>
</cmud>



How do I make a #Trigger so I can save the aura in a string list like:
@aura = Invis,Golden Aura| Golden Aura,White Aura|.....
and the mob name:
@LongMobName = A tiny, winged creature buzzes merrily around you.|Gueldar the Armorer stands here, creating some new armor.|.....

and what if there is zero aura can I sting list hold Empty string
or should I use a record list

I need both the aura and mob name later to save in my sql database, so they need to pair up.
Reply with quote
MattLofton
GURU


Joined: 23 Dec 2000
Posts: 4834
Location: USA

PostPosted: Sat Aug 03, 2013 6:10 pm   
 
1)turn on the roomchars tags via the TAG command (if you don't, may as well not bother attempting this project as you will be unable to avoid false-positives)

2)build a multistate trigger that can match on the {roomchars} tags and everything in between:

Code:
#trigger "tRoomChars" {^~{roomchars~}$} {
  Mobs = ""
  Players = ""
}
#condition {(*)} {
  #if (%1 = "{/roomchars}") {
    //the list is ended, do whatever you wanted to do at end-of-list
   #state tRoomChars 0
  } {
    //this line is a mob/player line, do whatever you wanted to do at in-the-list
  }
} {manual}


NOTE: the condition needs to have the ANSI trigger option enabled

There's no reason to bother limiting the pattern because we want to include any lines that don't have any auras.

3)figure out if each line matched is a mob or a player

NOTE: the below code goes in the in-the-list section of the #IF command above
Code:

#switch (%pos("(Angry)",%1) or %pos("(Animated)",%1) or %pos("(Charmed)",%1) or %pos("(Undead)",%1)) {
    //long version of mob-only auras
    Mobs = %additem(%1,@Mobs)
  }
  (%pos("(A)",%1) or %pos("(C)",%1) or %pos("(U)",%1)) {
    //short version of mob-only auras
    Mobs = %additem(%1,@Mobs)
  }
  (%pos("[AFK]",%1) or %pos("(Linkdead)",%1) or %pos("(Stealth)",%1)) {
    //long version of player-only auras
    #additem Players %1
  }
  (%pos("(S)",%1)) {
    //short version of player-only auras
    #additem Players %1
  }
  (1) {
    //this line has either no auras or only auras common to both mobs and players
    //look for the player-color positional phrases at the end of the line
    #switch (%ends(%1,%e"[1;32m is here."%e"[0m")) {#additem Players %1}
      (%ends(%1,%e"[1;32m is sitting here."%e"[0m")) {#additem Players %1}
      (%ends(%1,%e"[1;32m is sleeping here."%e"[0m")) {#additem Players %1}
      (%match(%1,%e"[1;32m is sleeping on *."%e"[0m")) {#additem Players %1}
      (%match(%1,%e"[1;32m is sleeping in *."%e"[0m")) {#additem Players %1}
      (%ends(%1,%e"[1;32m is resting here."%e"[0m")) {#additem Players %1}
      (%match(%1,%e"[1;32m is resting on *."%e"[0m")) {#additem Players %1}
      (%match(%1,%e"[1;32m is fighting *."%e"[0m")) {#additem Players %1}
      (1) {Mobs = %additem(%1,@Mobs)}
  }


At this point, all the roomchars lines should be in either the players variable or the mobs variable. In the end-of-list part of the #IF above, you can then use %match() with a pattern of "%q(%w*)" to separate auras from names.
_________________
EDIT: I didn't like my old signature
Reply with quote
Quit
Wanderer


Joined: 19 Jul 2008
Posts: 59

PostPosted: Sun Aug 04, 2013 8:28 pm   
 
Thanks for your code, I learn lots from it.

But what is the (1) in your code good for ?

Here is what I have made and its working ok for me.
Code:
<?xml version="1.0" encoding="ISO-8859-1" ?>
<cmud>
  <trigger name="mobtrigger" priority="8560" copy="yes">
    <pattern>^~{roomchars~}$</pattern>
    <value>#Gag
     AuraAndMob = ""

</value>
    <trigger type="Manual">
      <pattern>(*)</pattern>
      <value>#if (%1 = "{/roomchars}") {
  #state mobtrigger 0
  #Gag
  } {
  $aura = ""
  #FORALL @Mob_auras {#IF %match(%1,%i) {$aura = $aura + %i}} {}
  $tempmobname = %trim( %subregex( %1, "(\(Red Aura\)|\(Golden Aura\)|\(White Aura\)|\(Invis\)|\(Hidden\)|\(Translucent\)|\(Wounded\)|\[AFK\]|\(Linkdead\)|\(Angry\))"))
  $aura = %numitems(@AuraAndMob) + $aura
  #ADDKEY AuraAndMob $aura $tempmobname
}</value>
    </trigger>
  </trigger>
</cmud>


#ADDKEY need to have unique keys, but it is the same with %addkey, I was hoping that %addkey could have same keys.
Reply with quote
MattLofton
GURU


Joined: 23 Dec 2000
Posts: 4834
Location: USA

PostPosted: Mon Aug 05, 2013 12:36 am   
 
The (1) lets you define an ELSE condition in case there's something you want to do only when all the other conditions evaluate to false. In the case of the outer #SWITCH, this means when the only auras present are those that can be found on both mobs and players alike; in the inner #SWITCH, it means that the matched line does not contain any of the substrings associated with player position (sitting, sleeping, etc). You wouldn't want this code to run on every line.

As for #ADDKEY, that's why I stuck with the stringlists. You can add duplicates to a stringlist via %additem (players cannot be duplicates anyways, so I used #additem there).
_________________
EDIT: I didn't like my old signature
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