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


Joined: 15 Nov 2004
Posts: 18

PostPosted: Thu Jun 30, 2005 2:00 am   

Checking inventory for items not in DB
 
I was wondering if it was possible for zmud to determine which items in my inventory had no entry in the database and then cast id on those and enter them. I see the logic of it but cant figure out how to do it.

Any help would be nice!

Thanks
Reply with quote
Aarlot
Adept


Joined: 30 Dec 2003
Posts: 226

PostPosted: Thu Jun 30, 2005 3:15 am   
 
If you'd give some mud output for looking at your inventory, as well as id-ing something, that'd be good. Also, if you have any existing scripts to add things to the database, that'd be nice to see. Essentially, more info needed :)
_________________
Everyone is entitled to their beliefs - until they die. Then only the truth matters.
Reply with quote
thalor42
Beginner


Joined: 15 Nov 2004
Posts: 18

PostPosted: Thu Jun 30, 2005 3:45 am   
 
INV Output
-------------

You are carrying:
( 2) a water canteen
a potion of cure disease
a potion of visegrip
cracked wanderer cap
cracked wooden spear
blunt full axe
Full Gladius
( 2) jewel
jewel of the Owl
jewel of Revival
Lurid jewel
jewel of Refuge
jewel of Rejuvenation
jewel of Briars
ring of Privilege
ring of the Dog
Distinct ring
(Humming) an Aettangi
a loaf of bread
( 4) chipped Sapphire
( 2) chipped Ruby
( 2) chipped Skull
( 2) chipped Diamond
( 2) amulet
chipped Topaz
( 4) chipped Opal
( 3) chipped Emerald
( 2) chipped Amethyst
ring
a sack made from the skin of the White Queen
(29) a potion of healing

Id Output
-----------

Edwin, Jack of all Trades says 'It is ring of Privilege.'
Object 'ring Privilege' is type armor, extra flags no_locate.
Weight is 0, value is 100, level is 18.
Worn: Finger Finger
Material: none
Armor Grade: Unarmored
Armor Bonus of 0 and , 0 vs. magic.
Affects hp steal by 1.
Affects strength by 2.
Edwin, Jack of all Trades says 'There you go.'


TRIGGERS To Add to DB
---------------------------

#TRIGGER {Edwin, Jack of all Trades says 'It is (*).'} {#t+ ident;#VAR ident %null;#ADDKEY ident Name {%1}}

#TRIGGER {Affects armor class by (%d)} {#ADDKEY ident ACBonus {%1}} "Ident"
#TRIGGER {Affects damage roll by (%d)} {#ADDKEY ident DamRoll {%1}} "Ident"
#TRIGGER {Affects dexterity by (%d)} {#ADDKEY ident DEX {%1}} "Ident"
#TRIGGER {Affects hit roll by (%d)} {#ADDKEY ident HitRoll {%1}} "Ident"
#TRIGGER {Affects hp by (%d)} {#ADDKEY ident HP {%1}} "Ident"
#TRIGGER {Affects hp steal by (%d)} {#ADDKEY ident HPSteal {%1}} "Ident"
#TRIGGER {Affects intelligence by (%d)} {#ADDKEY ident INT {%1}} "Ident"
#TRIGGER {Affects mana by (%d)} {#ADDKEY ident Mana {%1}} "Ident"
#TRIGGER {Affects mana steal by (%d)} {#ADDKEY ident ManaSteal {%1}} "Ident"
#TRIGGER {Affects saves by (%d)} {#ADDKEY ident Saves {%1}} "Ident"
#TRIGGER {Affects strength by (%d)} {#ADDKEY ident STR {%1}} "Ident"
#TRIGGER {Armor Bonus of (%d)} {#ADDKEY ident ACBonus {%1}} "Ident"
#TRIGGER {Armor Grade: (*)} {#ADDKEY ident AG {%1}} "Ident"
#TRIGGER {Damage is (%a) ~(average (%d)~).} {#ADDKEY ident Dmgdice {%1};#ADDKEY ident Avedmg {%2}} "Ident"
#TRIGGER {Edwin, Jack of all Trades says 'There you go.'} {#IF !%null( %find( @ident.Name, All, Name)) {#YESNO "A duplicate item already exists, add anyway?" {#NOOP} {#ABORT 1}};#new @Type @ident;@ident = "";#T- ident} "Ident"
#TRIGGER {Material: (*)} {#ADDKEY ident material {%1}} "Ident"
#TRIGGER {Object '(*)' is type (%w), extra flags (*).} {#ADDKEY ident DBName {%1};#ADDKEY ident Kind {%2};#ADDKEY ident flags {%3};@type = %2} "Ident"
#TRIGGER {Weapon type is (*).} {#ADDKEY ident wtype {%1}} "Ident"
#TRIGGER {Weapons flags: (*)} {#ADDKEY ident WFlag {%1}} "Ident"
#TRIGGER {Weight is (%d), value is (%d), level is (%d).} {#ADDKEY ident weight {%1};#ADDKEY ident cost {%2};#ADDKEY ident level {%3}} "Ident"
#TRIGGER {Worn:(*)} {#ADDKEY ident wear {%1}} "Ident"
Reply with quote
Aarlot
Adept


Joined: 30 Dec 2003
Posts: 226

PostPosted: Thu Jun 30, 2005 8:26 am   
 
Ok, this *should* work, from what I've tested, if your mud works like most muds do as far as item targetting. You'll need to change the "idnext" alias to reflect the syntax your mud has, I assumed "cast 'identify' itemname" as the syntax for now. This script does not take into account running out of mana, etc, so if that's a problem there might need to be some changes. Anyway, normal command line input for below:


Code:

#CLASS {Inventory Id}
#ALIAS identinv {
  #T+ invstart
  inventory
  }
#ALIAS idnext {cast 'identify' %pop( idnames)}
#VARIABLE numitem {}
#VARIABLE invitems {}
#VARIABLE iditems {}
#VARIABLE idnames {}
#VARIABLE outername {}
#VARIABLE wordcount {}
#TRIGGER "invstart" {You are carrying:} {
  #VARIABLE iditems {}
  #VARIABLE idnames {}
  #VARIABLE invitems {}
  #T+ invcap
  #T+ invcap2
  #T+ invend
  } "" {disable}
#TRIGGER "invcap" {^(*)$} {#IF ((!%pos( "(", "%1")) AND (!%pos( "You are carrying", "%1"))) {#ADDKEY invitems {%1} {1}}} "" {disable}
#TRIGGER "invend" {^$} {
  #T- invcap
  #T- invcap2
  #T- invstart
  #VARIABLE iditems {}
  #VARIABLE idnames {}
  #LOOPDB @invitems {#IF %null( %find( "%key", All, Name)) {#ADDITEM iditems {%key}}}
  #FORALL @iditems {
    #VARIABLE wordcount {1}
    #VARIABLE outername {%i}
    #LOOPDB @invitems {#IF (%key=@outername) {#ADDITEM idnames {@wordcount~.%word( %key, %numwords( %key))}} {#IF (%pos( %word( @outername, %numwords( @outername)), %key)) {#ADD wordcount %val}}}
    }
  idnext
  #T+ idall
  #T- invend
  } "" {disable}
#TRIGGER "invcap2" {^~((*)~) (*)$} {
  #VARIABLE numitem {}
  #CALL %match(%trim(%1),"(%d)",numitem)
  #IF (@numitem>0) {#ADDKEY invitems {%2} {@numitem}} {#ADDKEY invitems {%2} {1}}
  } "" {disable}
#TRIGGER "idall" {Edwin, Jack of all Trades says 'There you go.'} {
  #IF (@idnames) {idnext} {
    #SAY Identification Complete
    #T- idall
    }
  } "" {disable}
#CLASS 0


Write back here if you have problems, without access to your mud/db there might be something I missed.

EDIT - ok, after thinking about it for a minute, I realize there is a slight problem. Unfortunately, as far as I can see, there is no way to query a db other than the mapper using SQL syntax. The closest I can get is the %find, which I use to determine whether an item needs to be identified or not. But the %find just checks to see if any of the items in the db have that particular phrase/word in them, not that exact phrase/word for the field. So the just plain "ring" would never get identified, even if you didn't have an item called "ring" in the database, because any other item with "ring" anywhere in the name will come back as true for the %find. This is one limitation I'm not sure how I can get around, but other than that I think it should be good.
_________________
Everyone is entitled to their beliefs - until they die. Then only the truth matters.
Reply with quote
Vijilante
SubAdmin


Joined: 18 Nov 2001
Posts: 5182

PostPosted: Thu Jun 30, 2005 9:13 am   
 
You can replace the use of %find with %query. Check the help page for syntax.
_________________
The only good questions are the ones we have never answered before.
Search the Forums
Reply with quote
Orang
Apprentice


Joined: 22 Jul 2004
Posts: 118
Location: USA

PostPosted: Thu Jun 30, 2005 6:45 pm   
 
i know this doesnt have much to do with this post but um..
how do you set up a DB in the first place?
Reply with quote
Aarlot
Adept


Joined: 30 Dec 2003
Posts: 226

PostPosted: Thu Jun 30, 2005 7:36 pm   
 
Oooh, thanks vigilante, that works great. Revised script below:


Code:

#CLASS {Inventory Id}
#ALIAS identinv {
  #T+ invstart
  inventory
  }
#ALIAS idnext {cast 'identify' %pop( idnames)}
#VARIABLE numitem {}
#VARIABLE invitems {}
#VARIABLE iditems {}
#VARIABLE idnames {}
#VARIABLE outername {}
#VARIABLE wordcount {}
#TRIGGER "invstart" {You are carrying:} {
  #VARIABLE iditems {}
  #VARIABLE idnames {}
  #VARIABLE invitems {}
  #T+ invcap
  #T+ invcap2
  #T+ invend
  } "" {disable}
#TRIGGER "invcap" {^(*)$} {#IF ((!%pos( "(", "%1")) AND (!%pos( "You are carrying", "%1"))) {#ADDKEY invitems {%1} {1}}} "" {disable}
#TRIGGER "invend" {^$} {
  #T- invcap
  #T- invcap2
  #T- invstart
  #VARIABLE iditems {}
  #VARIABLE idnames {}
  #LOOPDB @invitems {#IF %null( %query(&Name=%key, All)) {#ADDITEM iditems {%key}}}
  #FORALL @iditems {
    #VARIABLE wordcount {1}
    #VARIABLE outername {%i}
    #LOOPDB @invitems {#IF (%key=@outername) {#ADDITEM idnames {@wordcount~.%word( %key, %numwords( %key))}} {#IF (%pos( %word( @outername, %numwords( @outername)), %key)) {#ADD wordcount %val}}}
    }
  idnext
  #T+ idall
  #T- invend
  } "" {disable}
#TRIGGER "invcap2" {^~((*)~) (*)$} {
  #VARIABLE numitem {}
  #CALL %match(%trim(%1),"(%d)",numitem)
  #IF (@numitem>0) {#ADDKEY invitems {%2} {@numitem}} {#ADDKEY invitems {%2} {1}}
  } "" {disable}
#TRIGGER "idall" {Edwin, Jack of all Trades says 'There you go.'} {
  #IF (@idnames) {idnext} {
    #SAY Identification Complete
    #T- idall
    }
  } "" {disable}
#CLASS 0




To Orang:

There have been several very good explanations here on these boards, which you could search for, or you can try this site: http://www.silverbridge.org/~varmel/zmud/tutorials/zmuddb.htm which gives a pretty good explanation of databases.
_________________
Everyone is entitled to their beliefs - until they die. Then only the truth matters.
Reply with quote
thalor42
Beginner


Joined: 15 Nov 2004
Posts: 18

PostPosted: Fri Jul 01, 2005 5:50 pm   
 
It seems to work but still ID's things I have in my db. Are you checking to see if it is there before adding it to the db or id'ing it?
Reply with quote
Aarlot
Adept


Joined: 30 Dec 2003
Posts: 226

PostPosted: Fri Jul 01, 2005 8:35 pm   
 
*sigh* It was working with the testing I did... Yes, it does check to see if the item is already in your database, that's what the #LOOPDB @invitems {#IF %null( %query(&Name=%key, All)) {#ADDITEM iditems {%key}}} does. It loops through all the items in your inventory, checks with the %query to see if they're in your db, and if they're not (%null) it will add them to the list of items to be ID'd. There is probably some matter of syntax that is causing the problem, like perhaps your db name does not include words like "a" at the beginning ("a potion of visegrip" being "potion of visegrip"). Other than that, I can't think of anything that would cause a problem like that.
_________________
Everyone is entitled to their beliefs - until they die. Then only the truth matters.
Reply with quote
Vijilante
SubAdmin


Joined: 18 Nov 2001
Posts: 5182

PostPosted: Sat Jul 02, 2005 12:52 am   
 
Aarlot's script is looking for a field of "Name" in your database. You have no such field; you are storing the 'keywords' for the item in a field of "DBName". Since you never store the 'short description', which is displayed in your inventory list, of the items you will have to have much more complex code to try to match the name. Usually the keywords are present in the short description, but not always. In short your database needs another field to do this properly. You can provide additional checks to detect items that were identified prior to adding this field and update them properly using #DBGET, #ADDKEY with %rec, and #DBSAVE.
_________________
The only good questions are the ones we have never answered before.
Search the Forums
Reply with quote
Aarlot
Adept


Joined: 30 Dec 2003
Posts: 226

PostPosted: Sat Jul 02, 2005 2:40 am   
 
Vigilante, he does save the short description. From his db script:

#TRIGGER {Edwin, Jack of all Trades says 'It is (*).'} {#t+ ident;#VAR ident %null;#ADDKEY ident Name {%1}}


And as far as I could see from his example, this is the same name as the one that shows up in the inventory.
_________________
Everyone is entitled to their beliefs - until they die. Then only the truth matters.
Reply with quote
thalor42
Beginner


Joined: 15 Nov 2004
Posts: 18

PostPosted: Thu Jul 07, 2005 2:47 am   
 
I'm not saying it didnt work for you and I appreciate the effort. It works nicely except I blow some mana and have to hit NO to the popbox....no biggie...thanks for the script!
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