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


Joined: 06 Feb 2004
Posts: 17
Location: USA

PostPosted: Sun Feb 15, 2004 7:05 am   

Small DB Questions for Large Minds
 
Before I ask anything i would just like to say I have used the search command and the help within ZMUD itself. Both I find to be EXTREMELY helpful as the Guru's try to make clear.

I am working on a DB for the mud I play on.
While I was searching for some guidance in this task i came across lots of information like trobadours finished DB script for RoD.
My mud, MateriaMagica, has an auction channel that people can sell items over. when an item is being sold I can use the "auction info" command to call up info on the current item up for auction. It works just like casting idenify on the item.

I have the fields I need set up and defined, and I have triggers I need to capture all the info into variables. Where I am stuck is on actually doing the DB side of things.

I will start by showing an average display I get when I get info on the item:

Item 'a ring of shielding' is type jewelry, alignment -100, made of iron,
has keywords 'ring shielding', and can be equipped on the finger.
This item weighs 0 stones and 10 pebbles, and is valued at 9,750 gp.
This level 30 item has the attributes: blessed none
A ring of shielding is in excellent condition.
Can be used to cast the level 14 spell, 'shield'.
*This item may be repaired 6 more times.

Now as you can see there are more than one keyword for the item, as well the possibility of more than one attribute.

*First I would like to capatalize the entire item name, in this case "a ring of shielding".

*Second where the attributes are given the word none always appears no matter what, I want to make sure that it doest list none as an attribute since that is pointless.

*Third if there is more than one word in a field, like in the keywords field usually I would like to know how to have it capture the individual words and reformat them in a word,word,word format.

*Fourth I want to be able to search through the DB to see if the item already exists, and if not add it without any input from me. If it does Exist I want it to ignore the whole thing and wait for the next auction item to be put up.

*Fifth I am having trouble understanding the way Trobadour has his DB get opened,searched and then how to add the items in.

Phew i think thats enough info to give someone an idea, any help is great.
Reply with quote
megamog75
Enchanter


Joined: 20 Nov 2002
Posts: 627
Location: USA

PostPosted: Sun Feb 15, 2004 8:31 am   
 
Like you said, the help files are a key source in this research your doing, let me help you with some small examples to your question.

quote:
First I would like to capitalize the entire item name, in this case "a ring of shielding"

%upper(string)
%upper(a ring of shielding) = A RING OF SHIELDING

quote:
where the attributes are given the word none always appears, I want to make sure that it doest list none as an attribute

#trigger {^This level (%d) item has the attributes~: (%w) none$} {#addkey varname attributes %1}

quote:
Third if there is more than one word in a field, like in the keywords field usually I would like to know how to have it capture the individual words and reformat them in a word,word,word format

#trigger {has keywords '(*)', and can be equipped on the (%w)} {#addkey varname keywords %replace(%1," ","|")}

quote:
Fourth I want to be able to search through the DB to see if the item already exists, and if not add it without any input from me. If it does Exist I want it to ignore the whole thing and wait for the next auction item to be put up

#if %find("%1",all)=0 {yes}
yes = add the item like you already do

Your fifth question I do not understand as i do not really use his script. I wrote my own for RoD.
#DBLOAD eq #NEW All @newRecord #DBRESET
is what he uses and i added a #dbclose to mine.

I would like to say that I did make my script bassed of of his, but at the time at which I downloaded his, RoD had just went through the shattering and the script had to be revised.
Reply with quote
Vijilante
SubAdmin


Joined: 18 Nov 2001
Posts: 5182

PostPosted: Sun Feb 15, 2004 9:10 am   
 
MegaMog did a good job of answering your specific questions so I will give you the generic answer I give to all questions of this sort.

Here is my script. It isn't perfect, a few #DBRESETs could probably be elimnated and I could probably do some other things to make it faster. It hooks into my inventory tracking script so you would have to find and replace that part, but if you study it and work with the help I am sure it will give you many ideas.

#CLASS {ID}
#ALIAS StoreID {#DBRESET;CapturingID=%query((&Name=@IDedItem.Name));#DBRESET;Affects="";#FORALL @CapturingID {#DBGET {%i};#IF ((&TStats=@IDedItem.TStats)&(&Affects=@IDedItem.Affects)) {#ADDITEM Affects {%i}}};#IF (@Affects="") {#DBRESET;CapturingID=%query(&Where="New Item");#DBRESET;#IF (@CapturingID) {#DBGET {%item(@CapturingID,1)}} {#NEW All {Where=New Item};#DBRESET;CapturingID=%query(&Where="New Item");#DBRESET;#IF (@CapturingID) {#DBGET {%item(@CapturingID,1)}} {#ECHO Failed to make/find new record in database}};#IF (%rec) {#LOOPDB {@IDedItem} {#ADDKEY %rec {%key} {%val}};#ADDKEY %rec {Where} {Unknown};#DBSAVE}} {#ECHO Item appears to duplicate records @Affects.}}
#VAR CapturingID {} {}
#VAR Affects {} {}
#VAR IDedItem {} {}
#VAR IDsPending {}
#TRIGGER "IDCapture" {^Object '*' is type *, usable by *.$} {CapturingID=%line} "" {case}
#COND {} {#IF (%begins(%line,"-")=0) {CapturingID=%concat(@CapturingID,%cr,%line)} {#STATE IDCapture 2;#SET IDCapture 2 1}} {looplines|param=99}
#COND {} {CapturingID=%subchar(@CapturingID,"()","");CapturingID=%replace(@CapturingID,%cr,"|");CapturingID=%replace(@CapturingID,"Object '","KeyWords=");CapturingID=%replace(@CapturingID,"' is type ","|Type=");CapturingID=%replace(@CapturingID,"Wear Location: ","Wear=");CapturingID=%replace(@CapturingID,"Weapon type","WType");CapturingID=%replace(@CapturingID," usable","Usable");CapturingID=%replace(@CapturingID,"Extra flags ","Flags=");CapturingID=%replace(@CapturingID," value","Value");CapturingID=%replace(@CapturingID," level","Level");CapturingID=%replace(@CapturingID," is ","=");CapturingID=%replace(@CapturingID," by ","=");CapturingID=%replace(@CapturingID,"Armor class","TStats=AC");CapturingID=%replace(@CapturingID," pierce, ","-");CapturingID=%replace(@CapturingID," bash, ","-");CapturingID=%replace(@CapturingID," slash, and ","-");CapturingID=%replace(@CapturingID," vs. magic","");CapturingID=%replace(@CapturingID,"Damage","TStats=Dam");CapturingID=%replace(@CapturingID," to ","-");CapturingID=%replace(@CapturingID," average ","A");CapturingID=%subchar(@CapturingID,".,","||");#DELITEM CapturingID {};Affects="";#FORALL @CapturingID {#IF ((%begins( "%i", "Affects"))|(%begins( "%i", "Causes"))) {CapturingID=%delitem("%i",@CapturingID);Affects=%additem(%trim(%remove(%word("%i",1),"%i")),@Affects)} {#IF (%begins("%i","Has")) {CapturingID=%delitem("%i",@CapturingID);Affects=%additem(%concat(%word("%i",3)," of L",%word("%i",7)," ",%copy("%i", %pos(%word("%i",8),"%i"),255)),@Affects)}}};#IF (@Affects) {CapturingID=%concat(@CapturingID,"|(Affects=",@Affects,")")};IDedItem="";#ADDKEY IDedItem {@CapturingID};Affects="";#WHILE (@Affects="") {#LOOPDB @ItemsOnHand {#IF (%word(%val,1)) {#ADDITEM Affects {%key}}};#FORALL @Affects {#IF (%pos(%lower(%word(%db(@IDedItem,"KeyWords"),1)),%lower("%i"))) {#DELITEM Affects {%i};Affects=%push("%i",@Affects)}};Affects=%pick("p:Item Name","o:1",%replace(@Affects,",",%char(254)))};#ADDKEY IDedItem Name {%replace(@Affects,%char(254),",")};#ADDKEY IDedItem {Wear} {%replace(@IDedItem.Wear," ",",")};#DBLOAD ID;#VIEW All;#DBFIRST;#IF (%rec!="") {StoreID} {CapturingID=%concat( "ID", %secs);#VAR @CapturingID @IDedItem {_nodef} {ID};#ADDITEM IDsPending @CapturingID}} {manual}
#BUTTON 200 "IDsPending:%if(%btnenable(StoreIDs,%numitems(@IDsPending)),%numitems(@IDsPending),0)" {#DBLOAD ID;#VIEW All;#DBFIRST;#IF (%rec="") {#MENU {Windows|Database};#WHILE (%rec="") {#DBLOAD ID;#VIEW All;#DBFIRST}};IDedItem=@{%item(@IDsPending,1)};#UNVAR %pop(IDsPending) ID;StoreID} {} {} {%numitems(@IDsPending)} {} {} {} {} {} {Pos} {1} {880} {32800} {} {Gauge||10|5|0|11} {} "" {} {} {StoreIDs}
#CLASS 0

An example of my mud output is:
Object 'well crafted sword slender bm' is type weapon, usable by blademaster.
Wear Location: take wield
Weight is 10, value is 175, level is 36.
Weapon type is sword.
Damage is 5d8 (average 22).
Affects damage roll by 2.
- 973/973H 1555/2189S 2865 600

You can use that example to see how it works.
Reply with quote
neo2083
Beginner


Joined: 06 Feb 2004
Posts: 17
Location: USA

PostPosted: Sun Feb 15, 2004 10:37 am   
 
First off, thanks a bunch for the answers mega, they helped to show me the way faster than I could have found the answers myself.
I have one more question in addition to your answer about the "none" always showing up. If an item has no attributes on it, for some reason the mud ALWAYS lists "none" twice. What can I do to accomodate for this?

Also as you can see numbers larger than 999 have commas to seperate by thousands EX.1,750

I know how to capture the number, ignoring the comma but what I wanna know is how can I have the comma be put back in when it is put into the Db OR how can I capture it with the comma in it from the begining?

Thanks again
Reply with quote
nexela
Wizard


Joined: 15 Jan 2002
Posts: 1644
Location: USA

PostPosted: Sun Feb 15, 2004 10:52 am   
 
*Untested*
#trigger {^This level (%d) item has the attributes~: (*) none$} {#if (%2!=none) {#loop %numwords(%2) #addkey varname attributes %item(%i)}}}

I believe would be the correct way to capture All Attributes except None None. and None

This level 1 item has the attributes~: blessed nursed none
will add Blessed and Cursed to the Attr record

This level (%d) item has the attributes~: none none
will not add none
Reply with quote
nexela
Wizard


Joined: 15 Jan 2002
Posts: 1644
Location: USA

PostPosted: Sun Feb 15, 2004 10:55 am   
 
For your Second Question I believe instead of %d try %n but Im notsure
Reply with quote
megamog75
Enchanter


Joined: 20 Nov 2002
Posts: 627
Location: USA

PostPosted: Sun Feb 15, 2004 12:44 pm   
 
The #if stament is probably the best way to go for excluding the none repeter.

as for 12,576 getting added
#tr {This item weighs (%d) stones and (%d) pebbles, and is valued at (*) gp.}
could be one way with no other programming needed, what is the cance that a word would be used.

You could also use %format and or %insert to correct any problems in the %n
example:
you get 12,500
#tr {you get (%n} {#echo %format("&0.0n",%1)}
could also save to db like so: #addkey varname worth %format("&0.0n",%1)
Reply with quote
LightBulb
MASTER


Joined: 28 Nov 2000
Posts: 4817
Location: USA

PostPosted: Sun Feb 15, 2004 7:15 pm   
 
It's actually better to leave the commas out, so that zMUD will treat the values as numbers rather than strings. Commas should only be inserted when the number is to be displayed for you (or other people) to read, and that should be done by the display script not the database.
Reply with quote
neo2083
Beginner


Joined: 06 Feb 2004
Posts: 17
Location: USA

PostPosted: Sun Feb 15, 2004 7:49 pm   
 
Thanks for all of the help you guys, still implemnting and tweaking the DB.

Thanks for the advice as well lightbulb.
Reply with quote
neo2083
Beginner


Joined: 06 Feb 2004
Posts: 17
Location: USA

PostPosted: Sun Feb 15, 2004 9:58 pm   
 
Ok got a bit of a more advanced feature i would like to add if its possible.

Where I have the DB searched for an existing record of the same name, I want to have it also do something if an existing record is already in the DB. If it finds that a record exists for the item I would like to know if it can go beyond that to search the fields of that record. My reasoning for this is because items that have affects or various types can lose an affect as it is worn down. I am trying to make a DB of the items in the mud as they are when having all the affects they were designed to have. Since I am getting confused just writing this I will provide an example:

Lets say the imm on the mud have made a ring. This ring normally has a +50 to hp affect, and a +25 to st affect on it.
Lets say that the first time this ring is seen by me it only has one affect on it because it somehow lost the other one. When I see the ring a second or third time I want the DB to compare all the fields and see if there are any changes, if there are I want the changes to be input into the existing record.

Hope it makes sense, and I know it might be a complex operation to do but if some of the more advanced scripters could help me find a direction towards doing this I can do the work myself.

Thanks again for all your help.
Reply with quote
Kjata
GURU


Joined: 10 Oct 2000
Posts: 4379
Location: USA

PostPosted: Mon Feb 16, 2004 1:23 pm   
 
What if the situation is reversed? What would you want to do then? What I mean is, what if the first time you see the ring it has all stats on it, but the second time you see it, it has only one? Should it still update the db record?
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