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


Joined: 04 Apr 2003
Posts: 94
Location: United Kingdom

PostPosted: Sun Jan 21, 2007 3:18 am   

Capturing multiple items from a mud list
 
Ok im having trouble with trying to capture my potions and then being able to use them .... I did get some help from a friend on the mud but his file only partly works. I decided to do my own so;-

1. I try to learn and understand it and

2. I get it to work properly

Ok here is what happens if i type potionlist

"black potion6418" Type: Health Restoration Sips: 54.
"black potion10130" Type: Immunity Sips: 12.
"pink potion10873" Type: Adrenalin Sips: 14.
"vermillion potion15406" Type: Immunity Sips: 37.
"mauve potion32243" Type: Blinding Sips: 32.
"black potion35974" Type: Vigour Sips: 54.
"vermillion potion39220" Type: Immunity Sips: 51.
"red potion41809" Type: Physical Well-Being Sips: 38.
"black potion45401" Type: Health Restoration Sips: 54.
"black potion46461" Type: Cure Sips: 15.
"red potion46952" Type: Fire Sips: 51.
"red potion48800" Type: Physical Well-Being Sips: 48.
"black potion49579" Type: Health Restoration Sips: 5.
"black potion50274" Type: Immunity Sips: 36.
"vermillion potion61077" Type: Immunity Sips: 40.
"green potion63793" Type: Speed Sips: 45.
"black potion65446" Type: Strength Sips: 52.
"indigo potion67098" Type: Antidote Sips: 49.
"black potion69791" Type: Speed Sips: 17.
"grey potion71550" Type: Resurrection Sips: 46.
"red potion73076" Type: Physical Well-Being Sips: 43.
"black potion74229" Type: Speed Sips: 27.
"black potion76077" Type: Strength Sips: 50.
"black potion80422" Type: Cure Sips: 52.
"black potion80425" Type: Allheale Sips: 54.
"black potion80446" Type: Immunity Sips: 51.
"brown potion81892" Type: Strength Sips: 50.
"pink potion85028" Type: Cure Sips: 40.
"clear potion85423" Type: Holy Water Sips: 45.
"pink potion85952" Type: Adrenalin Sips: 51.
"milky potion86420" Type: Invisibility Sips: 6.
"black potion88431" Type: Vigour Sips: 54.
"purple potion89615" Type: Vigour Sips: 49.
"mauve potion93775" Type: Speed Sips: 54.


Ok I would like to do this once when I buy new potions get refills etc

I need the above information to be able to do a number of things

sip health

i need this to sip health potion if it returns health is empty then move to health 2 etc - if you note in the above example the colour is not important and not consistent - the numbers relate to specific item and type so health becomes potion6418 (not sure if the sips things makes any difference apart from telling me how much i got in general) when i sipped all that potion I will get

There is naught in an empty potion bottle worth supping.

if try to sip it or I can run a count on it if that is not imposible to run efficiently eg use sips

Last i suppose I would if possibe like to have an empty bottle move into a refill state eg potion6418 is sipped till its empty then becomes something like @healthrefill1 @healthrefill2

I suppose before I start to try and get this working I need your help working out how to go about this type of function first.
Reply with quote
Fang Xianfu
GURU


Joined: 26 Jan 2004
Posts: 5155
Location: United Kingdom

PostPosted: Sun Jan 21, 2007 4:14 am   
 
First thing you need to do si record which potions relate to which numbers. Have a trigger like this enabled by your potionlist alias:

#trig {~"%w(%d)~" Type: (%w) Sips: %d} {#additem Potions.%2 %1}

This will create a string list of potion numbers in a key with the name of the potion. Then your sip alias will be something like this:

#alias sip {~sip %item(Potions.%1,1);#var LastSip %1}

You could also just use something like this:

#alias sh {sip %item(Potions.health,1);#var LastSip %1}

The LastSip variable is important because finally you have a trigger like this:

#trig {There is naught in an empty potion bottle worth supping.} {#delnitem {Potions.@LastSip} 1}

Hope this helps.

PS: If the forums ate some spaces from your pattern, you'll have to add %s into the first trigger I listed here.
Reply with quote
gamma_ray
Magician


Joined: 17 Apr 2005
Posts: 496

PostPosted: Sun Jan 21, 2007 5:47 am   
 
This looks really complicated at first but in reality it is a really simple capture and then a straight forward but very tedious data structure.

Code:
#ALIAS sip {
  #if !%null( @{potions.%1}) {
;see if we can figure out what you want to sip
    #if (%begins( @{potions.%1}, "(")) {
;check if you've got several of a potion or only one (special case)
      ~sip @{potions.%1.1.1}
;send the command to sip the correct potion
      #if (@{potions.%1.1.2} <= 1) {#addkey potions %1 %delnitem( @{potions.%1}, 1)} {#addkey potions %1 %replaceitem( %replaceitem( %eval( @{potions.%1.1.2}-1), 2, @{potions.%1.1}), 1, @{potions.%1})}
;check for an empty potion, this is where you would want to add something to keep track of which ones are empty if there isn't an easier way
;if it's not empty, then subtract a sip off of the variable representing whatever you just sipped
      } {
      ~sip @{potions.%1.1}
      #if (@{potions.%1.2} <= 1) {#addkey potions %1 %null} {#addkey potions %1 %replaceitem( %eval( @{potions.%1.2} - 1), 2, @{potions.%1})}
;a second version of sipping, checking for empty potions, etc., when there is only one potion of a type remaining
      }
    } {~sip %1}
;if there is no reference to that type of potion in the variable, then it just sends whatever you originally entered instead
  }

#VAR potions {}

#ONINPUT {^potionlist$} {
  #var potions %null
;reset everything
  } "" {regex}

#REGEX {^~".* (potion\d+)~" Type: (.*) Sips: (\d+)\.$} {
;simple trigger which matches the line telling you what kind of potion you've got
;stores potion#### in %1, the type (e.g. speed, cure..) in %2, and the number of sips left in %3
  #addkey potions %2 %additem( (%1|%3), @{potions.%2})
;adds the bottle and sips to a string list, puts the string list in potions.TypeOfPotion
;string list is like such: (bottle|sips)|(bottle|sips)...
  }


Minimally tested and never with live data, use at your own risk, let me know how it breaks. I've added comments in so you can figure some of what it does out for yourself, ask if you've got questions...data structures tend to be very useful for storing stuff so it's good to learn how they work in ZMud (it's a bit odd).

Some thoughts... I've marked where you could reasonably easily add in empty tracking, but if you can refill any empty potion with any type of potion then it would be easier to just put them all in a single var. Especially if they're shown on potion list, because then you could just put them all in the @potion var anyway.

You might also want to add in some spoof checking--make it so that potionlist only toggles the capture trigger on for x number of lines/seconds, or if you get a specific end-of-list line then go by that. Otherwise it's possible that someone could exploit this to mess up your curing.

Edit: OK, so I'm slow. I spent like half an hour figuring out why the bloody thing wouldn't work, only to realize that I hadn't put a space between the closing paren for the #if and the opening paren for the else part...and then I failed to see that someone had already posted. :(
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