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


Joined: 31 Jan 2006
Posts: 55

PostPosted: Sat Feb 11, 2006 11:44 am   

Database, is this possible
 
Hello, I am working on a script that I am afraid will need databases. I know nothing about them.

This is what I need to do. Store the following three informations in a database. I would enter them in manually, with an alias:
Mob name (which often contain spaces)
Area name mob is in (also contain spaces)
And directions to get to it (e;w;n;n;n; ....etc)

Then, I want to be able to type an alias, for instance: "goto <exact mob name>" and travel there. I want it to get the directions for where this mob is at, and its area too, from the database.

Before I wrack my brain trying to figure these databases out, I wondered if someone could tell me: Is it possible to do this with databases in zmud?

Lastly, I wonder if someone knows of a very good database tutorial to start with. Thanks
Reply with quote
MattLofton
GURU


Joined: 23 Dec 2000
Posts: 4834
Location: USA

PostPosted: Sat Feb 11, 2006 7:26 pm   
 
Yep, definitely possible. Populating the database is really easy:

1)make sure the DB window is open (none of the database functionality works without it)

2)within said window, create all the fields and whatnot for the database (ZMud doesn't allow creation of databases via code)

2)#DBLOAD to ensure your database is open

3)#NEW to add a new record, #DBPUT to update an old one

4)#DBGET to pull up a specific record (loads the whole record into the %rec system variable); %db() if you need to pass a specific value of a specific record

5)#FIND/%find() and #QUERY/%query() to search the database

6)#DBFIRST, #DBNEXT, and #DBPREV to step through the database (strangely, no #DBLAST)

7)#DBSAVE to save the database to a file

8)#DBCLOSE to remove the database from memory

Moving around from a specific fixed location is similarly easy, but will require an outside trigger to determine that you are in fact in the right room. If you are using a map that includes the rooms you travel through, you can instead use mapper commands to travel to your destination from literally any other mapped room. Delays in your travel will have to be handled separately via triggers/aliases contained either in your map or in your settings file.
_________________
EDIT: I didn't like my old signature
Reply with quote
mo24
Wanderer


Joined: 31 Jan 2006
Posts: 55

PostPosted: Sat Feb 11, 2006 8:12 pm   
 
Thank you, that was a great help.
Reply with quote
mo24
Wanderer


Joined: 31 Jan 2006
Posts: 55

PostPosted: Sun Feb 12, 2006 12:51 pm   
 
I seem to have run into a simple problem I can not seem to solve. I've tried and read many examples, but out of ideas.

I created the database, and its fields, four different fields for what I wanted, in the Databse editor. Two fields are named "Mob" and "Area".

Now I try to create a test record, but I cannot seem to be able to. I have this in script:

#DBLOAD ar
#ADDKEY atest {Mob=Barney|Area=Home}
#NEW All @atest

ar is ar.db I named the database. I use this in the script, but when I check the database, nothing is added. I've tried many syntaxes for #NEW.. also tried #NEW All Mob=Barney, etc. Does not work.

What could I be doing wrong? Database seems to be loaded. But nothing will add.
Reply with quote
mo24
Wanderer


Joined: 31 Jan 2006
Posts: 55

PostPosted: Sun Feb 12, 2006 12:51 pm   
 
Double post sorry.
Reply with quote
icedsun
Novice


Joined: 20 Jan 2006
Posts: 45
Location: Minnesota

PostPosted: Sun Feb 12, 2006 8:39 pm   
 
Quite honestly, this could be done rather easily without a database - but if you're going to have a HUGE amount of mobs in your list then maybe you should stick to trying to do a database. However, if you're going to have a manageable amount of them, then here's what I'd do:

Code:
#ALIAS HumpMonster {
   #IF (%1="Santa") {n;n;n;n;n;n;n;n;n;n;lick santa}
   #IF (%1="Satan") {d;d;d;d;d;d;d;d;d;d;d;hug satan}
   #IF (%1="Princess") {e;n;d;e;e;s;w;n;slap princess}
}

And to use it you'd type something like: HumpMonster Santa

And you could just add more mob names/directions directly hard-coded into the alias. This would only work if you were starting from a set beginning point, of course. And you would want to be careful about having enough movement points, making sure there weren't any agressive mobs on the way there, etc. But this would be a simple, basic way to get from point A to B.
_________________
"Build a man a fire and he's warm for a night. Light a man on fire and he's warm for the rest of his life." --My Mom
Reply with quote
mo24
Wanderer


Joined: 31 Jan 2006
Posts: 55

PostPosted: Mon Feb 13, 2006 11:16 am   
 
Unfortunately I will indeed probably have many many mobs in it. A database would probably be a necessity for me. I've considered an alias, but it would get enormously big and not as useful I think as a database.

Would you know what I am doing wrong in the above example, that is causing my records not to be added to the database?
Reply with quote
mo24
Wanderer


Joined: 31 Jan 2006
Posts: 55

PostPosted: Mon Feb 13, 2006 11:47 am   
 
Well, I have got it working, but not in a very convenient way.

It seems it will only create records in the database IF I have the database window open already. This seems foolish. Is it supposed to work that way?
Reply with quote
Iceclaw
Apprentice


Joined: 11 Sep 2005
Posts: 124

PostPosted: Mon Feb 13, 2006 2:11 pm   
 
yup, my suggestion is to open and then minimize the window, or pull it up/roll it up out of the way somewhere.
Reply with quote
JQuilici
Adept


Joined: 21 Sep 2005
Posts: 250
Location: Austin, TX

PostPosted: Mon Feb 13, 2006 7:09 pm   
 
You don't really need the database for this application, though. If what you really care about is (a) getting to/from a room, and (b) looking up paths to/from a room, then the mapper will do everything you need. Check out the help pages for #walk, %roomnum, %pathfrom, etc. to get an idea of what you can do with it.

For such a scheme to work, of course, you need to have mapped your MUD - at least the parts of it you're going to speedwalk through. The advantage of doing things this way is that you can quickly and easily calculate paths from wherever you are (or any other room of interest) to the target room, even if you are not in the 'starting spot'.

For added convenience, you can set the short names of rooms and use them in place of room numbers (vnums). Or, with a bit more work, you can do something like my 'room alias' script below:

Code:

#CLASS {QLib|Mapping|Rooms} {setdef}
#NOOP -- NOTE: DELKEY doesn't understand scoped variables, so we make
#NOOP -- this class SETDEF and choose unlikely var names, then pray.
#AL SetRoomAlias {
  #IF {%iskey(@qlRoomAliases,%1)} {
    #VAR ./QLib/Mapping/Rooms/aliasNum {@roomAlias(%1)} {}
    #SAY '%1' is already room-aliased to '@{./QLib/Mapping/Rooms/aliasNum}' ~(%roomname(@{./QLib/Mapping/Rooms/aliasNum})~)
  } {
    #IF {%2} {
      qlRoomAliases.%1=%2
    } {
      qlRoomAliases.%1=%roomnum
    }
    ShowRoomAlias %1
  }
}
#Al rmal {
  #IF {%2} {
    SetRoomAlias %1 %2
  } {
    ShowRoomAlias
  }
}
#AL RemRoomAlias {
  #IF {%1} {
    #IF {%iskey(@qlRoomAliases,%1)} {
      #VAR ./QLib/Mapping/Rooms/aliasNum {@roomAlias(%1)} {}
      #SAY Removing room-alias '%1'='./QLib/Mapping/Rooms/aliasNum' ~(%roomname(./QLib/Mapping/Rooms/aliasNum)~)
      #DELKEY qlRoomAliases %1
    } {
      #SAY No room-alias for '%1' was defined
    }
  }
}
#AL unrmal {RemRoomAlias %1}
#FUNC roomAlias {%if(%iskey(@qlRoomAliases,%1),@qlRoomAliases.%1,%1)}
#AL ShowRoomAlias {
  #IF {%1} {
    #SAY %1"="@qlRoomAliases.%1" ~("%roomname(@qlRoomAliases.%1)"~)"
  } {
    #VAR ./QLib/Mapping/Rooms/aliasTxt {} {}
    #LOOPDB @qlRoomAliases {#ADDITEM ./QLib/Mapping/Rooms/aliasTxt {%key"="%val" ~("%roomname(%val)"~)"}}
    #PRI {
      #SAY -- Room Aliases --
      #FORALL %sort(@./QLib/Mapping/Rooms/aliasTxt) {#SAY %i}
      #SAY -- Done --
    }
  }
}
#AL UseRoomAlias {
  #IF {%2} {
    #VAR qlRoomNum {@roomAlias(%2)}
    #IF {@qlRoomNum} {
      #SAY Speedwalking to %roomname(@qlRoomNum)
      %1 @qlRoomNum
    } {
      #SAY Speedwalking to %2
      %1 %2
    }
  } {
    #SAY You must give a room-alias argument to this command
  }
}
#AL goto     {useRoomAlias #walk}
#AL showvn   {#say Vnum: %roomnum ~(%roomname~)}
#AL pathto   {#say %pathfrom(%roomnum,@roomAlias(%1))}
#AL pathfrom {#say %pathfrom(@roomAlias(%1),%roomnum)}
#AL pathtf   {#say %pathfrom(@roomAlias(%1),@roomAlias(%2))}
#CLASS 0


I have then gone through and aliased a bunch of rooms (walk to room, type 'rmal <name>', repeat). Then I can use 'goto <room>' to speedwalk to any of the rooms, or 'pathtf ms <room>' to get a path from room 'ms' (Market Square in the main town) to the target room, etc.
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