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
Zoticus
Beginner


Joined: 16 Jan 2010
Posts: 24

PostPosted: Mon Nov 12, 2012 11:15 pm   

Defense handling help
 
Hello -

At the moment, my system does something like this:

When a prompt from the mud appears, it checks if any defenses are missing, and attempts to activate them.

However, to tell it which defenses to handle how, I have them in different places, so it knows what parameters must be met before that defense can be activated. Balance, free, elixir, etc.

I've got this in my balance check, currently:

#if (%ismember( defense, @Auto) and !%ismember( Deffing, @MyFlags)) {#Forall @BalanceDefs {#if (!%ismember( %i, @MyDefs) and %ismember( %i, @DefsOn)) {#exec @DefMap.%i}}

Obviously, 'Forall' tries to send every single defense that's not currently registered as an active def - in MyDefs - at once, which.. it can't do. I'm looking for suggestions how to have it check the whole variable of possible defs against missing defs, without having it send every single one at the same time.

Note, previously, this is how I handled these sort of defs -

#if (%ismember( defense, @Auto) and !%ismember( armor, @MyDefs)) {activate armor}
#if (%ismember( defense, @Auto) and !%ismember( floating, @MyDefs)) {float}

repeat by -every single def- I want kept up, which changes on a character by character basis, or even the needs of my character at a specific point - this method -functions- but it's not at all fluid. I want to be able to add/remove things from the 'DefsOn' variable to tell it what to keep up or ignore from the available defs in the applicable defense type variable.

Thanks for any input.
Reply with quote
shalimar
GURU


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

PostPosted: Mon Nov 12, 2012 11:47 pm   
 
well seeing as almost everything tests for %ismember( defense, @Auto), why not nest the#IFs to a degree?

#IF (%ismember( defense, @Auto)) {
#IF (!%ismember( armor, @MyDefs)) {activate armor}
#IF (!%ismember( floating, @MyDefs)) {float}
}


and so on, it probably won't speed things up too much (though it might) but it will be much easier to read

you could further simplify it by making a dbVar of powers to test for, and their activators

#ADDKEY defenseCheck.charName {armor=activate armor|floating=float}

and then the previous if could look something more like...

#IF (%ismember( defense, @Auto)) {#FORALL %dbkeys(@defenseCheck.%char) {#IF (!%ismember( %i, @MyDefs)) {#SEND @defenseCheck.%char.%i}}}

or you can add the various activaters to another stringlist.., and assuming you have the various success messages in another list you could do something like...

#TR {{@successfullDefenseActivated}} {#IF (@defensesNeeded) {#SEND %pop(defensesNeeded)}}
_________________
Discord: Shalimarwildcat
Reply with quote
Zoticus
Beginner


Joined: 16 Jan 2010
Posts: 24

PostPosted: Tue Nov 13, 2012 12:12 am   
 
shalimar wrote:
well seeing as almost everything tests for %ismember( defense, @Auto), why not nest the#IFs to a degree?

#IF (%ismember( defense, @Auto)) {
#IF (!%ismember( armor, @MyDefs)) {activate armor}
#IF (!%ismember( floating, @MyDefs)) {float}
}


Because that's exactly what I had before, and am trying to move away from. I don't want to have to go in and add / remove defs between characters from a thing that needs to otherwise remain static, when I could use an alias on login to set a variable of unique defs I want kept up.


shalimar wrote:
you could further simplify it by making a dbVar of powers to test for, and their activators

#ADDKEY defenseCheck.charName {armor=activate armor|floating=float}

and then the previous if could look something more like...

#IF (%ismember( defense, @Auto)) {#FORALL %dbkeys(@defenseCheck.%char) {#IF (!%ismember( %i, @MyDefs)) {#SEND @defenseCheck.%char.%i}}}


The DefMap variable is that. It does check for that , to decide how to activate the missing defenses.

shalimar wrote:
or you can add the various activaters to another stringlist.., and assuming you have the various success messages in another list you could do something like...

#TR {{@successfullDefenseActivated}} {#IF (@defensesNeeded) {#SEND %pop(defensesNeeded)}}


I could do that. I'm not exactly looking for a full on defup though - just upkeep of specific defenses as I desire I want them kept up, so that I can say, turn on floating or turn it off whenever I want. I have an alias that runs through the defs I usually keep up and puts them on. I want something for the defs that're more unique and situational that doesn't require me to make 50 different variations of

#IF (!%ismember( floating, @MyDefs)) {float}

into four different places that all handle their own unique requirements for activating their def type.
Reply with quote
Daern
Sorcerer


Joined: 15 Apr 2011
Posts: 809

PostPosted: Tue Nov 13, 2012 12:23 am   
 
If I understand correctly, your system works, you just need a delay between sending each defense, instead of sending them all at once? That's easily accomplished by adding a #wait x (where x is a number of milliseconds) after your #exec.
Reply with quote
shalimar
GURU


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

PostPosted: Tue Nov 13, 2012 12:28 am   
 
If you want optional defenses... i would suggest a button setup to toggle off each specific defense as needed for the current spellup
_________________
Discord: Shalimarwildcat
Reply with quote
Zoticus
Beginner


Joined: 16 Jan 2010
Posts: 24

PostPosted: Tue Nov 13, 2012 12:36 am   
 
I've got an alias that'll add whatever I want to the keepup variable. I don't need a button.

My issue is that if I add more than one def to that variable that's not active, it sends all of them at once.

I'm not sure how I could use #wait here to insert a delay between the sending of activation commands, given how forall works.
Reply with quote
shalimar
GURU


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

PostPosted: Tue Nov 13, 2012 12:45 am   
 
well, how long does the longest defense take to activate? use that time in miliseconds

#WHILE (@defensesNeeded) {#WAIT 60000;#SEND %pop(defensesNeeded)}

that will wait a minute between each defense attempt
_________________
Discord: Shalimarwildcat
Reply with quote
Zoticus
Beginner


Joined: 16 Jan 2010
Posts: 24

PostPosted: Tue Nov 13, 2012 1:04 am   
 
Wouldn't that sort of timer stop other things from happening while it was active?

These defenses would be added / removed during combat - when my whole system needs to be firing on all cylinders.
Reply with quote
shalimar
GURU


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

PostPosted: Tue Nov 13, 2012 1:25 am   
 
it did in zMUD, it has been fixed to work as expected in CMUD
essentially it creates its own #THREAD to run in
_________________
Discord: Shalimarwildcat
Reply with quote
Daern
Sorcerer


Joined: 15 Apr 2011
Posts: 809

PostPosted: Tue Nov 13, 2012 1:43 am   
 
Zoticus wrote:
I'm not sure how I could use #wait here to insert a delay between the sending of activation commands, given how forall works.

Like this:
Code:
#if (%ismember( defense, @Auto) and !%ismember( Deffing, @MyFlags)) {#Forall @BalanceDefs {#if (!%ismember( %i, @MyDefs) and %ismember( %i, @DefsOn)) {#exec @DefMap.%i;#wait 1000}}
Reply with quote
Zoticus
Beginner


Joined: 16 Jan 2010
Posts: 24

PostPosted: Tue Nov 13, 2012 2:33 am   
 
That wouldn't stop it from sending all six possible defs at once, the first time around. It'd just wait a little before sending the next five. At least, I don't think it would.

I found my answer here.

This is what I've ended up with:

Code:
#if (%ismember( defense, @Auto)) {#Forall @BalanceDefs {#if (!%ismember( %i, @MyDefs) and %ismember( %i, @DefsOn)) {#ADDI DefsRequired %i}}
#if (%ismember( defense, @Auto) and @DefsRequired>%null) {#Forall (@DefsRequired.1) {#exec %db( @DefMap, %i);#Call %pop( DefsRequired);#T+ BalDefAlarm}}


The BalDefAlarm adds a thing to my scanning that tells it to check the balance scan again in a second or so, so that it'll loop through the defenses in defsrequired until the variable reads null.
Reply with quote
Daern
Sorcerer


Joined: 15 Apr 2011
Posts: 809

PostPosted: Tue Nov 13, 2012 5:36 am   
 
Adding the wait absolutely would put a delay between each one, since the wait runs every time you loop through the forall. This simple example shows that:
Code:
$test = {1|2|3|4}
#forall $test {#print %i;#wait 1000}

Glad you got it working though :)
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