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
N86eAL
Novice


Joined: 13 Jan 2008
Posts: 33
Location: Sweden

PostPosted: Sun Feb 17, 2008 1:44 pm   

To match a word against a sentance.
 
So here I am once again with a little more advanced problem that I have been fighting. This problem is revolving around a prot message that you get when inspecting a friend. A typical message could look like this.

"The target is affected by prot1, prot2, prot3, prot4."

I tried searching the cmud help files, but didn't get far. One thing I noticed, is that you can play with write file. Doing something like this

^The target is affected by (*)
#WRITE 1 %1

Where 1 is an already created textfile called prots. Then if you use grep, you can find out if there your word is in there or not. Let's say the textfile looks like this "hi, my, name, is, bob." and you do something like this,

#SHOW %grep(1,"bob"), it will output something like this "hi, my, name, is, bob.|hi, my, name, is, bob.". But if I will try and find a word, maybe "sweden", then there will be no output at all. But I can't just go out and create a trigger for that output, since there are more things that look just liek that. Is there another way to do this?

The main thing I want to do is to do a check if a certain prot is up or not.
Reply with quote
Vijilante
SubAdmin


Joined: 18 Nov 2001
Posts: 5182

PostPosted: Sun Feb 17, 2008 3:23 pm   
 
As an example for what you want to do based on the information you gave. Simply enter at the command line.
Code:

#CLASS SpellupOthers
#VAR OthersHaveAffects {} {}
#TRIGGER {^(%w) is affected by (*).$} {#ADDKEY OthersHaveAffect {%1} {%replace(%2,", ","|")}}
#ALIAS CheckAffect {$example=%db(@OthersHaveAffects,%1);#IF (%ismember(%2,$example)) {#SHOW {%1 is affected by %2}} {#SHOW {%1 does not have the %2 affect}}}
#CLASS 0
#SHOW "John is affected by prot1, prot2, prot3."
#SHOW "Doe is affected by prot4."
#EXEC {"CheckAffect John prot4;CheckAffect John prot3"}
_________________
The only good questions are the ones we have never answered before.
Search the Forums
Reply with quote
N86eAL
Novice


Joined: 13 Jan 2008
Posts: 33
Location: Sweden

PostPosted: Sun Feb 17, 2008 4:05 pm   
 
OMG, OMG! %replace was just what I was looking for. I am going to play some more with my thoughts, and probably get to a solution that will work. I will post what I did if I succeeded. :P
Reply with quote
N86eAL
Novice


Joined: 13 Jan 2008
Posts: 33
Location: Sweden

PostPosted: Sun Feb 17, 2008 5:53 pm   
 
Ok, this is probably done way wrong or something, but it works! Didn't spend so much time on it because I was mad as hell because I couldn't get it to work(do still not understand the reason). Got it to work, and don't have enough knowledge about cmud to make it better...yet. I mean, the most advanced that I have done before this one was a run macro with if statements.

Code:

#variable protsup ""
xx %1
xx %replace(@test,", ","|")
xx %replace(@test,".","")
xx %replace(@test," and ","|")
#VAR test {<Array>|@test}
#VAR Arr {%arrhigh(test)}

#LOOP 0,@Arr {#IF (%arrget(test,%i) == "ward of steel") {#add protsup "GPhys | "}}
#LOOP 0,@Arr {#IF (%arrget(test,%i) == "arcane bulwark") {#add protsup "GMag | "}}
#LOOP 0,@Arr {#IF (%arrget(test,%i) == "Corrosive opposition") {#add protsup "GAcid | "}}
#LOOP 0,@Arr {#IF (%arrget(test,%i) == "resist void") {#add protsup "GAsph | "}}
#LOOP 0,@Arr {#IF (%arrget(test,%i) == "infernal vestment") {#add protsup "GCold | "}}
#LOOP 0,@Arr {#IF (%arrget(test,%i) == "lightning guard") {#add protsup "GElec | "}}
#LOOP 0,@Arr {#IF (%arrget(test,%i) == "winter's rebuke") {#add protsup "Gfire | "}}
#LOOP 0,@Arr {#IF (%arrget(test,%i) == "venom fend") {#add protsup "GPoi | "}}
#LOOP 0,@Arr {#IF (%arrget(test,%i) == "psychic aegis") {#add protsup "GPsi | "}}
#LOOP 0,@Arr {#IF (%arrget(test,%i) == "armour of god") {#add protsup "AOG | "}}
#LOOP 0,@Arr {#IF (%arrget(test,%i) == "caustic opposition") {#add protsup "GLAcid | "}}
#LOOP 0,@Arr {#IF (%arrget(test,%i) == "endure void") {#add protsup "LAsph | "}}
#LOOP 0,@Arr {#IF (%arrget(test,%i) == "vestment of flame") {#add protsup "LCold | "}}
#LOOP 0,@Arr {#IF (%arrget(test,%i) == "spark shelter") {#add protsup "LElec | "}}
#LOOP 0,@Arr {#IF (%arrget(test,%i) == "rebuke of ice") {#add protsup "LFire | "}}
#LOOP 0,@Arr {#IF (%arrget(test,%i) == "mystic bulwark") {#add protsup "LMag | "}}
#LOOP 0,@Arr {#IF (%arrget(test,%i) == "poison fend") {#add protsup "LPoi | "}}
#LOOP 0,@Arr {#IF (%arrget(test,%i) == "mental aegis") {#add protsup "LPsi | "}}
#LOOP 0,@Arr {#IF (%arrget(test,%i) == "ward of stone") {#add protsup "LPhys | "}}
#LOOP 0,@Arr {#IF (%arrget(test,%i) == "iron will") {#add protsup "IW | "}}
#LOOP 0,@Arr {#IF (%arrget(test,%i) == "inner power") {#add protsup "IP | "}}
#LOOP 0,@Arr {#IF (%arrget(test,%i) == "stun resistance") {#add protsup "SR | "}}
#LOOP 0,@Arr {#IF (%arrget(test,%i) == "energy hauberk") {#add protsup "EH | "}}
#LOOP 0,@Arr {#IF (%arrget(test,%i) == "barkskin,") {#add protsup "BS | "}}
#LOOP 0,@Arr {#IF (%arrget(test,%i) == "barkskin.") {#add protsup "BS | "}}
#LOOP 0,@Arr {#IF (%arrget(test,%i) == "barkskin and") {#add protsup "BS | "}}
#LOOP 0,@Arr {#IF (%arrget(test,%i) == "two barkskins") {#add protsup "2 BS | "}}
#LOOP 0,@Arr {#IF (%arrget(test,%i) == "shield of protection") {#add protsup "SOP | "}}
#LOOP 0,@Arr {#IF (%arrget(test,%i) == "two shields of protection") {#add protsup "2 SOP | "}}
#LOOP 0,@Arr {#IF (%arrget(test,%i) == "displacement,") {#add protsup "DP | "}}
#LOOP 0,@Arr {#IF (%arrget(test,%i) == "displacement.") {#add protsup "DP | "}}
#LOOP 0,@Arr {#IF (%arrget(test,%i) == "displacement and") {#add protsup "DP | "}}
#LOOP 0,@Arr {#IF (%arrget(test,%i) == "two displacements") {#add protsup "2 DP | "}}
#LOOP 0,@Arr {#IF (%arrget(test,%i) == "stoneskin,") {#add protsup "SS | "}}
#LOOP 0,@Arr {#IF (%arrget(test,%i) == "stoneskin.") {#add protsup "SS | "}}
#LOOP 0,@Arr {#IF (%arrget(test,%i) == "stoneskin and") {#add protsup "SS | "}}
#LOOP 0,@Arr {#IF (%arrget(test,%i) == "two stoneskins") {#add protsup "2 SS | "}}
#LOOP 0,@Arr {#IF (%arrget(test,%i) == "vaporic armour,") {#add protsup "VA | "}}
#LOOP 0,@Arr {#IF (%arrget(test,%i) == "vaporic armour.") {#add protsup "VA | "}}
#LOOP 0,@Arr {#IF (%arrget(test,%i) == "vaporic armour and") {#add protsup "VA | "}}
#LOOP 0,@Arr {#IF (%arrget(test,%i) == "two vaporic armours") {#add protsup "2 VA | "}}
#LOOP 0,@Arr {#IF (%arrget(test,%i) == "force shield") {#add protsup "FS | "}}
#LOOP 0,@Arr {#IF (%arrget(test,%i) == "blurred image") {#add protsup "Blur | "}}
#LOOP 0,@Arr {#IF (%arrget(test,%i) == "regeneration") {#add protsup "Regen | "}}
#LOOP 0,@Arr {#IF (%arrget(test,%i) == "harmonious barrier") {#add protsup "HAB | "}}
#LOOP 0,@Arr {#IF (%arrget(test,%i) == "harmony armour") {#add protsup "HA | "}}
#LOOP 0,@Arr {#IF (%arrget(test,%i) == "true unpain") {#add protsup "TUP | "}}
#LOOP 0,@Arr {#IF (%arrget(test,%i) == "minor unpain") {#add protsup "MUP | "}}
#LOOP 0,@Arr {#IF (%arrget(test,%i) == "Preparation of harmony") {#add protsup "Hprep | "}}
#LOOP 0,@Arr {#IF (%arrget(test,%i) == "Infravision") {#add protsup "Infra | "}}
#LOOP 0,@Arr {#IF (%arrget(test,%i) == "Elixir of Stamina") {#add protsup "Elix(hpmax) | "}}
#LOOP 0,@Arr {#IF (%arrget(test,%i) == "Elixir of Dexterity") {#add protsup "Elix(dex) | "}}
#LOOP 0,@Arr {#IF (%arrget(test,%i) == "Resist heal") {#add protsup "RH | "}}
#LOOP 0,@Arr {#IF (%arrget(test,%i) == "Lesser acid invulnerability") {#add protsup "LACID | "}}
#LOOP 0,@Arr {#IF (%arrget(test,%i) == "Lesser physical invulnerability") {#add protsup "LPHYS | "}}
#LOOP 0,@Arr {#IF (%arrget(test,%i) == "Lesser psionic invulnerability") {#add protsup "LPSI | "}}
#LOOP 0,@Arr {#IF (%arrget(test,%i) == "Lesser magical invulnerability") {#add protsup "LMAG | "}}
#LOOP 0,@Arr {#IF (%arrget(test,%i) == "Lesser electric invulnerability") {#add protsup "LELEC | "}}
#LOOP 0,@Arr {#IF (%arrget(test,%i) == "Lesser asphyxiation invulnerability") {#add protsup "LASPH | "}}
#LOOP 0,@Arr {#IF (%arrget(test,%i) == "Lesser poison invulnerability") {#add protsup "LPOIS | "}}
#LOOP 0,@Arr {#IF (%arrget(test,%i) == "Lesser fire invulnerability") {#add protsup "LFIRE | "}}
#LOOP 0,@Arr {#IF (%arrget(test,%i) == "Lesser cold invulnerability") {#add protsup "LCOLD | "}}
#LOOP 0,@Arr {#IF (%arrget(test,%i) == "Greater acid invulnerability") {#add protsup "GACID | "}}
#LOOP 0,@Arr {#IF (%arrget(test,%i) == "Greater physical invulnerability") {#add protsup "GPHYS | "}}
#LOOP 0,@Arr {#IF (%arrget(test,%i) == "Greater psionic invulnerability") {#add protsup "GPSI | "}}
#LOOP 0,@Arr {#IF (%arrget(test,%i) == "Greater magical invulnerability") {#add protsup "GMAG | "}}
#LOOP 0,@Arr {#IF (%arrget(test,%i) == "Greater electric invulnerability") {#add protsup "GELEC | "}}
#LOOP 0,@Arr {#IF (%arrget(test,%i) == "Greater asphyxiation invulnerability") {#add protsup "GASPH | "}}
#LOOP 0,@Arr {#IF (%arrget(test,%i) == "Greater poison invulnerability") {#add protsup "GPOIS | "}}
#LOOP 0,@Arr {#IF (%arrget(test,%i) == "Greater fire invulnerability") {#add protsup "GFIRE | "}}
#LOOP 0,@Arr {#IF (%arrget(test,%i) == "Greater cold invulnerability") {#add protsup "GCOLD | "}}
#LOOP 0,@Arr {#IF (%arrget(test,%i) == "Eyes of the Tiger") {#add protsup "Tiger eyes | "}}
#LOOP 0,@Arr {#IF (%arrget(test,%i) == "Holy wisdom") {#add protsup "Holy wis | "}}
#LOOP 0,@Arr {#IF (%arrget(test,%i) == "Brain unpain") {#add protsup "BUP | "}}
#LOOP 0,@Arr {#IF (%arrget(test,%i) == "Salve of Magical Resistance") {#add protsup "Mag salve |"}}
pp @protsup
Reply with quote
Malach
Apprentice


Joined: 03 Nov 2007
Posts: 132

PostPosted: Tue Feb 19, 2008 4:26 pm   
 
Okay here is what I would do to simplify that. I'm assuming that you have a list of current protection type things such as "Holy wisdom|Brain unpain|Eyes of the Tiger". You want to go through that list and add some particular words/chars to the protsup variable which you will then use to do something else. Here's a simpler way to do it:

Make a database record variable. You can read up on these but basically they allow you to have a key matched with a value. In your case the key would get things like "Holy wisdom", "Brain unpain" etc. and the value would be things like "Holy wis" and "BUP". So you build your database record:

#VAR MyRecord {Holy wisdom=Holy wis|Brain unpain=BUP} etc. etc. etc. Put it all in there. This would be like a database storage for you. You wouldn't change it unless you were adding a new protection key.

Now I'm assuming your test array is something that changes based on changing conditions in your mud? That's just a guess. So your "test" array may look something like "Holy wisdom|Brain unpain|Eyes of the Tiger"? Maybe? Anyway that's what I'm guessing! You can just make that a simple string list. So you could do something very simple like:

#LOOPDB @MyRecord {#IF (%ismember(%key, @test)) {#VAR protsup %concat(@protsup,%val, " | ")}}
pp @protsup

What you basically say with this code is "Loop through my database record that I store all my protection stuff in. If any key in that database record (keys being like "Holy wisdom", "Brain unpain") is a member of my current "test" list, then concat the value of that key (values being things like "Holy wis" and "BUP") as well as a " | " onto my protsup variable.

Just an idea on how to make it cleaner and easier to maintain.
_________________
Intel Core2 Quad CPU @ 2.4 GHZ with Windows Vista Home Premium and 2 GB Ram
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