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


Joined: 21 Sep 2010
Posts: 22

PostPosted: Wed Dec 15, 2010 2:41 am   

Need help with an database.
 
Hi again, I posted a question a few days back but it hasn't received any responses. I think the script I was looking for was unrealistic in nature.

I wanted to know if someone could help me with a simpler task

I want to make a script that categorizes npc's and what they have on them.

My goal is to make a database that can be searchable when looking for a specific item.

I would like it to create a new item if I perform the command exa %1 <-%1 being npc name
Here are a few output examples.

>exa garrik
A male human named Garrik.
Garrik retired from adventuring many years ago - long before you started. Now
he just hangs out in Candera, telling longwinded stories of battles fought,
places explored, and items found. He would only be too happy to tell you about
Candera. Just listen to what he chats about - he'll be only too happy to <talk
about> any of these topics.
He is a large human.
He is in excellent condition.
Garrik is using:
<wielded with both hands> Walking Stick
<worn on head> ring mail coif
<worn on body> scale mail jacket
<worn on hands> pair of leather gloves
<worn on feet> pair of leather boots
> exa commander
This Canderan soldier guards the city against enemy ambushes and intrusions.
Skilled in the art of desert warfare, he has pledged to defend the city with
his life and honor. On his arm is tattooed the red seal of the army.
He is a large human.
He is in excellent condition.
Commander is using:
<wielded with both hands> Desert Bastard Sword
<worn on legs> Golden Chain Leggings
> exa commander 2
This Canderan soldier guards the city against enemy ambushes and intrusions.
Skilled in the art of desert warfare, he has pledged to defend the city with
his life and honor. On his arm is tattooed the red seal of the army.
He is a large human.
He is in excellent condition.
Commander is using:
<wielded in right hand> Desert Skull Crusher
<worn on arms> Golden Chain Sleeves

As you can see there were two commanders in the room. If it is possible I would like to just have one record with multiple items. Then I can see that sometimes commander has a skull crusher, other times it could be a bastard sword etc.

As an added bonus if possible could I pull the room number and place it in a field? Any field is fine.
>exa %1 [Name: %1] (get RoomID to add to DB)
This Canderan soldier guards the city against enemy ambushes and intrusions.
Skilled in the art of desert warfare, he has pledged to defend the city with
his life and honor. On his arm is tattooed the red seal of the army.
He is a large [Race:].
He is in excellent condition.
Commander is using:
<wielded in right hand> [Right Hand:]
<worn on arms> [Arms:]


Given there are two commanders and the name is the same is it possible to just add the differences to the record without the redundancies of having two commands who both are wearing cloth sleeves but have different weapons. Something like this?

[Name: Commander]
[RoomID: (pulled from location of where I am on map)
[Race: Human]
[Right Hand: Desert Skull Crusher]
[Right Hand: Flaming Demonsbane]
[Right Hand: Predator Staff]
[Arms: Steel Sleeves]
[Arms: Cloth Sleeves]

The reference to commander will remain a constant but the eq may change so I just want to add items as they are identified.

I don't need a complex script to address all my needs. I'll gladly disect a simple script that just focuses on right hand and appropriate triggers from there by learning the basics.

Thanks and I appreciate it. I've tried three different scripts that ive seen posted on here but even after I rework the triggers to match those above it doesn't do anything. No errors, no new records it just goes through the motions as if I had just typed exa %1 even though the alias was tied to identify.


Thank you!
Reply with quote
Darkflame808
Beginner


Joined: 21 Sep 2010
Posts: 22

PostPosted: Thu Dec 16, 2010 7:52 pm   
 
I've been reading various posts on the forums regarding database usages and I am still stumped.

Here's an output i'm trying to parse.

Code:


Garrik retired from adventuring many years ago - long before you started. Now
he just hangs out in Candera, telling longwinded stories of battles fought,
places explored, and items found.  He would only be too happy to tell you about
Candera. Just listen to what he chats about - he'll be only too happy to <talk
about> any of these topics.
He is a medium human.
He is in excellent condition.
Garrik is using:
<wielded with both hands>   Walking Stick
<worn on head>              ring mail coif
<worn on body>              scale mail jacket
<worn on hands>             pair of leather gloves
<worn on feet>              pair of leather boots
>


For testing purposes I came up with this from reading on the forum.
Code:

#CLASS {identify}
#TRIGGER {&{np.Name} is using:}
#TRIGGER {<wielded with both hands>   &{np.Weapon} }


#TRIGGER {$} { #if (%find( @np.Name) = "") {#new "" @np}
np = ""
#t- identify
}
 
#CLASS 0
#ALIAS identify {
 #t+ identify
exa %1
}


Ok, I created my NPC database, inside has two fields. One is Name (record) and the other Weapon (memo)

I run identify garrik and it parses and inside the DB shows a record containing

Name: <blank>
Weapon: Walking

I can't get it to parse the name. Nor can I figure out why it only shows Walking and not Walking Cane.

I've been tinkering around with the script for the last 2 days and have managed to get it to do either.

1. nothing
2. Blank names and one worded weapons
3. I don't know what went wrong but occasionally I got a....
Name: Walking Cane
Weapon: Walking Cane

Once but I couldn't repeat it.

Any help would be greatly appreciated. I purchased cmud with the hopes of cataloging this mud but havn't been able to work out anything aside from using simple aliases :( I'm capable of disecting and learning but not too smart when it comes to building from the ground up.

Thank you very much I am very grateful.

Aloha,
Darkflame
Reply with quote
Rahab
Wizard


Joined: 22 Mar 2007
Posts: 2320

PostPosted: Fri Dec 17, 2010 3:06 pm   
 
The reason it is capturing only a single word is because your pattern is only trying to match a single word.

I'm not sure that the & pattern in a trigger will work for a database variable. It certainly won't work for the complicated db variable that you need. What you need to do is capture the values and insert them into the db variable within the trigger. And since the Weapon name is not on the same line as the Character name, you will have to set up some method of remembering what the current Character name is.

What you are looking for is pretty complicated. Essentially, what you will need is multidimensional table in which the character name is the key, and the value is a subtable matching a body location to a stringlist of objects. Using your example, you would have:
np.Commander.RoomID = 5001
np.Commander.Race = Human
np.Commander.{Right Hand} = {Desert Skull Crusher|Flaming Demonsbane|Predator Staff}
np.Commander.Arms = {Steel Sleeves|Cloth Sleeves}
np.SomeoneElse.RoomID = 5002
np.SomeoneElse.Race = Elf
...

Does that match what you are looking for?

If that works, then here is a start toward what you need. I don't have Cmud installed here, so this is untested, but may give you the idea. These triggers would go in your identify class:
Code:

#TRIGGER {(*) is using:} {#var exatarget %1}
#TRIGGER {<{wielded in|wielded with|worn on} (*)>%s(*)} {$location = %proper(%1);$list = %db(@np.@exatarget,$location);#additem $list %2;#addkey np.@exatarget $location $list}
Reply with quote
MattLofton
GURU


Joined: 23 Dec 2000
Posts: 4834
Location: USA

PostPosted: Fri Dec 17, 2010 7:57 pm   
 
If you use multistate triggers, the %t1...%t99 variables are used to refer to the master list of captured subpatterns throughout all states:

Quote:

this is a test
of the multistate %t1...%t99 variable feature
as demonstrated in CMud

Code:
#trigger {this is a (%w)} {#print %1}
#condition {of the (*) feature} {#print %1}
#condition {as demonstrated in ({ZMud|CMud})} {
  #print %1
  #print %format("t1: &s t2: &s t3: &s",%t1,%t2,%t3)
}
_________________
EDIT: I didn't like my old signature
Reply with quote
Darkflame808
Beginner


Joined: 21 Sep 2010
Posts: 22

PostPosted: Fri Dec 17, 2010 8:42 pm   
 
Hi there, I managed to test out your script and from looking at the variable, it looks amazing!

I ran around a small square in town and ID'd everyone.

Here's the results.

Code:

  <?xml version="1.0" encoding="ISO-8859-1" ?>
- <cmud>
- <var name="np" type="Record">
  <value>Garrik="Both hands=Walking Stick|Head=ring mail coif|Body=scale mail jacket|Hands=pair of leather gloves|Feet=pair of leather boots"|Laborer="Arms=pair of leather sleeves|Right hand=A shovel"|Undead orc raider="Both hands=Spear"|Undead wall guard="Right hand=Jagged blade|Head=scale mail coif"|Canderan wall guard="Right hand=""Flail|Scimitar""|Body=superior breastplate|Left hand=Hatchet"|Xidishen="Undead left arm=Broad mace|Undead right arm=Thin dirk|Right hand=Thin long sword|Left hand=Thin tomahawk"</value>
  <json>{"Xidishen":{"Right hand":["Thin long sword"],"Undead right arm":["Thin dirk"],"Left hand":["Thin tomahawk"],"Undead left arm":["Broad mace"]},"Undead orc raider":{"Both hands":["Spear"]},"Canderan wall guard":{"Right hand":["Flail","Scimitar"],"Body":["superior breastplate"],"Left hand":["Hatchet"]},"Garrik":{"Hands":["pair of leather gloves"],"Both hands":["Walking Stick"],"Head":["ring mail coif"],"Feet":["pair of leather boots"],"Body":["scale mail jacket"]},"Undead wall guard":{"Right hand":["Jagged blade"],"Head":["scale mail coif"]},"Laborer":{"Right hand":["A shovel"],"Arms":["pair of leather sleeves"]}}</json>
  </var>
  </cmud>


A nicer view is this.
#showdb @np results in
Code:

Garrik: Both hands=Walking Stick|Head=ring mail coif|Body=scale mail jacket|Hands=pair of leather gloves|Feet=pair of leather boots
Laborer: Arms=pair of leather sleeves|Right hand=A shovel
Undead orc raider: Both hands=Spear
Undead wall guard: Right hand=Jagged blade|Head=scale mail coif
Canderan wall guard: Right hand="Flail|Scimitar"|Body=superior breastplate|Left hand=Hatchet
Xidishen: Undead left arm=Broad mace|Undead right arm=Thin dirk|Right hand=Thin long sword|Left hand=Thin tomahawk

Ok so it would seem that everything is adding up perfectly,

My question if I may ask is how do I convert this into a database file?

I've tried creating a npc.db, np.db and when executing #new @np or new Garrik @np it just creates a new database with 0 being the first item and blanks the rest of the way.

I've manually created fields for body, both hands or whatever else I could see was being shown in the both hands= etc

I have a script working now that does basic things like head, body, feet etc but it doesn't parse information as efficiently and cleanly as your script does.

In my script the final trigger was
Code:

#trigger ^ {#IF (%QUERY((&Name = @np.Name)))
{#Echo @np.Name is found in database; #DBRESET}
{#Echo @np.Name is a new item; #DBRESET
    #IF (!%null(@np.Name))
      {#Echo Data is present;#NEW All|Database @np
      #Echo Added @np.Name}
      {#Echo Null Name }
} }

Set to trigger on a new line only when prompt was shown (to make sure all fields were populated first)

If I ran your script along with this one, an ID would result in " is a new item" followed by Null Name:

Nothing ever gets written to the database this way but #show

Is it possible to execute a command that would do these steps?

take @np and create a mirrored db from it.

It would make Garrik the record and add tables for Both hands, Head, Body, Hands, etc?

I've tried #new @np but it just results in 0 as a new record under RoomID and blanks the rest of the way.

It looks perfect as is in @np I just fear that my entire work running around the mud cataloging can be easily wiped out during testing if I ever #var @np "" while writing some other script. leaving all my data in a @ variable seems too "temporaryish" for me.

Thank you very much for helping me tackle this task!
Reply with quote
Rahab
Wizard


Joined: 22 Mar 2007
Posts: 2320

PostPosted: Fri Dec 17, 2010 9:20 pm   
 
Are you sure you need a database? That db variable should be able to do anything you need. If there is no specific need for a Cmud database, I would just use the db variable, myself. In fact, that's exactly what I am doing (with different keys, of course :) So far, I have over 2000 item weights, values, and descriptions, 200 crafting recipes, and numerous other things stored in db variables.

You are correct that a variable is easier to wipe out than a database. If you want to do it in a database, then do what works for you. It will be trickier to get the stringlists into the database. I'll have to think about it some more.
Reply with quote
Darkflame808
Beginner


Joined: 21 Sep 2010
Posts: 22

PostPosted: Fri Dec 17, 2010 9:41 pm   
 
Rahab,

I can always export the variables weekly to prevent anything catastrophic from happening :) so I think i'll be safe from any possible wipes.

I don't want you to go out of your way just to make a db if you yourself have that much confidence in using variables :) I think once I get the basics down i'll just leave that variable alone and make a new one should I ever feel the need to catalog something else.

Thank you very much!
Reply with quote
Rahab
Wizard


Joined: 22 Mar 2007
Posts: 2320

PostPosted: Sat Dec 18, 2010 1:16 am   
 
I must admit that eventually I will probably move my larger db variables into an external SQLite database, or into the internal database once Zugg rewrites it. For now, the db variables (new! improved! now with json!) are working fine.
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