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

Play RetroMUD
Post new topic  Reply to topic     Home » Forums » zMUD General Discussion
nostra
Wanderer


Joined: 23 May 2001
Posts: 68
Location: Sweden

PostPosted: Thu Jun 10, 2004 7:40 am   

Comparing lists and looping spells question
 
I have a big problem. Somehow, I need to write a script that compares data-keys in a record variable list with the values in a string list. Cool

The reason for this "odd" treatment of datalists is that I want to "boost" my beneficiary spell-affects and the only (?) way I figured this would be possible is to compare two lists:

One with my 'current spells' and one master list with 'all possible spells' - and for each spell that is "missing" in my currentspell list should be casted (the "cast instruction" is given by the 2nd field in the datarecord list).

So, my two lists are:

1) Stringlist: currentspells (current beneficiary spells)
Example
armor
shield


2) Datarecord: allspells (all beneficiary spells)
Example
data-key record-variable
armor cast armor
shield play A A B# D#
detect alignment play A G E A#
strength cast strength

Now, I want to execute the record-variable (ie cast the spell) for all spells (data-keys) in allspells that are not in my currentspells list.

In this example the script should execute:

play A G E A#
cast strength


since I'm lacking 'detect alignment' and 'strength'.

One more factor to account for: the script cannot execute all commands straight away. It has to wait for the output line "You have completed your casting" before continuing to next state.


Any and all ideas are very welcome Smile

Cheers,
Mikael
/Sweden
Reply with quote
Serentus
Apprentice


Joined: 28 Sep 2001
Posts: 103
Location: USA

PostPosted: Thu Jun 10, 2004 9:27 am   
 
Something like this should work for you. I can't test it right now so it may have a syntax error or missing curly brace.

#ALIAS Spellup {#FORALL @all_possible_spells {#IF %ismember(%1,@current_spells)=0 {#ADDITEM missing_spells {%1}}};#IF (@missing_spells) {#EXEC @{all_spells.%item(@missing_spells,1)}}}

#TRIGGER {You have completed your casting} {#DELNITEM missing_spells;#IF (@missing_spells) {#EXEC @{all_spells.%item(@missing_spells,1)}}}

You may or may not want:
#TRIGGER {You failed your casting} (#IF (@missing_spells) {#EXEC @{all_spells.%item(@missing_spells,1)}}}
Reply with quote
nexela
Wizard


Joined: 15 Jan 2002
Posts: 1644
Location: USA

PostPosted: Thu Jun 10, 2004 9:50 am   
 
*drool* a challenge :P ok Im VERY tired and NOT testing this. :P

ALIAS spellup
PATTERN:
#VAR TmpCastList "" //Initiate the Var
#PRIO {#LOOPDB @AllSpells {#IF (!%ismember(%key,@CurrentSpells)) {#ADDI TmpCastList {%val}}}} //Add to it
#EXEC %pop(TmpCastList) //Start first cast

This will ALSO need a trigger on a succesfull cast (paste this in command line)
#TRIGGER "TmpCast" {^You have completed your casting} {#IF (!%null(@TmpCastList) {#EXEC %pop(TmpCastList);#SAY Spellups left:%numitems(@TmpCastList)}}


Now If you get a fail Message modifie the script above as shown below
ALIAS spellup
PATTERN:
#VAR TmpCastList "" //Initiate the Var
#PRIO {#LOOPDB @AllSpells {#IF (!%ismember(%key,@CurrentSpells)) {#ADDI TmpCastList {%val}}}} //Add to it
#VAR TmpCastSpell {%item(@TmpCastList,1} //Add to single Cast in case of fail
#EXEC %pop(TmpCastList) //Start first cast

New Trigger here
#TRIGGER "TmpCastOK" {^You have completed your casting} {#IF (!%null(@TmpCastList) {#VAR TmpCastSpell {%item(@TmpCastList,1};#EXEC %pop(TmpCastList);#SAY Spellups left:%numitems(@TmpCastList)}}

New Trigger here
#TRIGGER "TmpCastFail" {^You fail your cast} {#IF (!%null(@TmpCastSpell)) {#EXEC @TmpCastSpell}}

NOTES: You might need to put {}'s around the #EXEC params but Im not sure
Reply with quote
nostra
Wanderer


Joined: 23 May 2001
Posts: 68
Location: Sweden

PostPosted: Thu Jun 10, 2004 10:28 am   
 
Thanks for a quick and extensive reply!

However (and this is kinda embarassing) after I entered your trigger as above (you forgot a bracket, but that's all) and seeing that evertyhing is looking good I type "spellup" and nothing happens. Zip, zero, nada.

Could it be something with my generic settings? (I see from the code that the #exec command should kick in" but zmud doesn't twist an inch).

Any idea? :-)

Thanks,
Mikael
Reply with quote
LightBulb
MASTER


Joined: 28 Nov 2000
Posts: 4817
Location: USA

PostPosted: Thu Jun 10, 2004 3:08 pm   
 
This was tough.

ENTER AT COMMAND LINE
#AL spellup {
#VAR spelluplist {}
#LOOPDB @allspells {#ADDI spelluplist {%key}}
#FORALL @currentspells {#DELI spelluplist {%i}}
#IF @spelluplist {
#T+ Spellups
%db( @allspells, %item( @spelluplist, 1))
}}
#TR {You have completed your casting} {
#DELN spelluplist 1
#IF @spelluplist {%db( @allspells, %item( @spelluplist, 1))} {#T- Spellups}
} {Spellups}

If desired, a recast trigger would be quite easy and should also go in the Spellups class. Use your own failure pattern. You may have as many of these as needed if there is more than one failure pattern.
#TR {You lost your concentration} {
#IF @spelluplist {%db( @allspells, %item( @spelluplist, 1))} {#T- Spellups}
} {Spellups}
Reply with quote
nostra
Wanderer


Joined: 23 May 2001
Posts: 68
Location: Sweden

PostPosted: Thu Jun 10, 2004 6:30 pm   
 
It works like a charm Smile

Two questions though:

#TR {You lost your concentration} {
#IF @spelluplist {%db( @allspells, %item( @spelluplist, 1))} {#T- Spellups}
} {Spellups}

1) Is "spellups" (marked red) a typo?

2) Is it possible to throw in a "wait" state after "You have completed your spell" (I switch between spellbooks and need to wait like 3 seconds between each spell complete). I have experimented with #alarm without any luck :(

This community is great [:p]

/Mikael
Reply with quote
nexela
Wizard


Joined: 15 Jan 2002
Posts: 1644
Location: USA

PostPosted: Thu Jun 10, 2004 8:56 pm   
 
spellups looks like a typo :P change it to spellup and as for a wait state try this

#TR {You have completed your casting} {#DELN spelluplist 1}
#COND {} {#IF @spelluplist {%db( @allspells, %item( @spelluplist, 1))} {#T- Spellups}
} {Spellups}} "" {wait|param=3000}

EDIT: Reread and fixed my booboo
Reply with quote
LightBulb
MASTER


Joined: 28 Nov 2000
Posts: 4817
Location: USA

PostPosted: Fri Jun 11, 2004 3:09 am   
 
1. Spellups is not a typo, it's the name I picked for the class to put the triggers in. You can change it to anything you prefer but you'll also need to change the #T+ and #T- commands.

2. You can easily add a delay to the triggers. Just move the casting action to a Wait-type multistate with a blank pattern. Nexela almost has it right.
#TR {You have completed your casting} {#DELN spelluplist 1} {Spellups}
#COND {} {#IF @spelluplist {%db( @allspells, %item( @spelluplist, 1))} {#T- Spellups}} {Wait|Param=3000}
Reply with quote
nexela
Wizard


Joined: 15 Jan 2002
Posts: 1644
Location: USA

PostPosted: Fri Jun 11, 2004 3:32 am   
 
Blah I need to start paying more attention. Maybe after I get a cast on my hand and the dbl vision gone ill be better :P
Reply with quote
Display posts from previous:   
Post new topic   Reply to topic     Home » Forums » zMUD 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