Graal Forums  

Go Back   Graal Forums > Development Forums > NPC Scripting
FAQ Members List Calendar Today's Posts

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 01-06-2008, 09:17 PM
DustyPorViva DustyPorViva is offline
Will work for food. Maybe
DustyPorViva's Avatar
Join Date: Sep 2003
Location: Maryland, USA
Posts: 9,589
DustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond repute
Send a message via AIM to DustyPorViva Send a message via MSN to DustyPorViva
MUD's

I think it's time I've learned how to work with MUD databases/scripts... and I'm looking for someone to teach me. You can reach me whichever way possible, but I suppose an IM would be the best way to teach(and what I'd prefer). If you're willing to sit down with me and teach me the basics of how to work with MUD's and .ini's, go ahead and initiate here or in an IM. After that I will most likely always refer back to you for questions.
Thanks in advance!
Reply With Quote
  #2  
Old 01-06-2008, 09:30 PM
Chompy Chompy is offline
¯\(º_o)/¯
Chompy's Avatar
Join Date: Sep 2006
Location: Norway
Posts: 2,815
Chompy is just really niceChompy is just really niceChompy is just really nice
Send a message via MSN to Chompy
Well, there's different ways to make MUD's, but Inverness have taught me alot of what I can of MUDs :o

Well, for Ini files..

Make a wnpc or somewhere to store this script (To make custom objects):
PHP Code:
function onCreated()
{
  
this.scriptlogmissingfunctions false;
  
this.types NULL;
  
// Files
  
maketype("IniFile"0, {"file_ini"});
}
public function 
maketype(typenamesuperclasses)
{
  
temp.0;

  if (
makevar("T" typename) != null) {
    
makevar("T" typename).destroy();
  }
  
this.(@ "type_" typename) = new TStaticVar("T" typename);
  if (
super.type() == 2) {
    
this.(@ "type_" typename).joinedclasses super.joinedclasses;
  }
  for (
iclasses) {
    
this.(@ "type_" typename).join(i);
  }
  if (
this.types.index("T" typename) < 0) {
    
this.types.add("T" typename);
  }

And I usually put this in a class name that I used when creating the TIniFile custom object above:

("file_ini" as used above)
PHP Code:
// Loads an INI File into the object.
public function load(filename) {
  
// Declaring the temp variables
  
temp.file 0;
  
temp.0;
  
temp.key 0;
  
temp.0;
  
temp.var = 0;
  
temp.val 0;
  
  
// Load all the lines from the file.
  
file.loadlines(filename);
  
// Stop the loading if the file has no lines.
  
if (file.size() < 1) {
    return;
  }
  for (
0file.size(); ++) {
    
// If the line starts with a semi-colon, skip it. (For comments)
    
if (file[i].starts(";"))
      continue;
    
// Checking if the line is an INI section header (key)
    
if (!file[i].starts("[") && !file[i].ends("]")) {
      
// Check to see if a section has been found, can't load variables without one.
      
if (key == null)
        continue;
      
// Get the position of the equal sign on the line.
      
file[i].pos("=");
      
// Skip the line if it doesn't exist
      
if (0)
        continue;
      
// If the line starts with an equal sign, append to last variable loaded.
      // This is good for long multi-line amounts of text.
      
if (== && var != null) {
        
val file[i].substring(1, -1);
        
this.(@ key).(@ var) @= val;
      }
      
// If the equal sign isn't at the beginning, set a variable in the right section
      // <varname>=<value>
      
else {
        var = 
file[i].substring(0e);
        
val file[i].substring(e+1, -1);
        
this.(@ key).(@ var) = val;
      }
    }
    else {
      
// Set the INI section.
      
key file[i].substring(1file[i].length() - 2);
    }
  }
}
// Saves this object as an INI file
public function save(filename) {
  
// Declaring temp variables, and getting dynamic variables in the object
  
temp.output 0;
  
temp.0;
  
temp.0;
  
temp.keys this.getdynamicvarnames();
  
temp.vars 0;
  
  for (
0keys.size(); ++) {
    
// If the dynamic variable is actually a value, skip it
    
if (this.(@ keys[i]).type() != -1)
      continue;
    
// Write the section header
    
output.add("[" keys[i] @ "]");
    
// Get the dynamic variables for the section
    
vars this.(@ keys[i]).getdynamicvarnames();
    for (
0vars.size(); ++) {
      
// Add a line for the variable if its not zero.
      
if (this.(@ keys[i]).(@ vars[e]) != null) {
        
output.add(vars[e] @ "=" this.(@ keys[i]).(@ vars[e]));
      }
    }
  }
  
// write the lines
  
output.savelines(filename0);
}
// Clears all values for a certain INI section.
public function clearkey(keyname) {
  
temp.0;
  
temp.vars 0;
  
  
// Stop the function if its an actual object.
  
if (this.(@ keyname).type() != -1)
    return;
  
vars this.(@ keyname).getdynamicvarnames();
  for (
0vars.size(); ++) {
    
this.(@ keyname).(@ vars[i]) = null;
  }
}
// Copies variables from an INI section to an object (like object.loadvars())
public function copyvars(keynameobject) {
  
// Stop the function if 'object' isn't an actual object.
  
if (object.type() != 2)
    return;
  
// Stop the function if this.keyname is an object.
  
if (this.(@ keyname).type() != -1)
    return;
  for (
temp.ithis.(@ keyname).getdynamicvarnames()) {
    
object.(@ i) = this.(@ keyname).(@ i);
  }

Then you can load an ini file by doing:

PHP Code:
function onCreated() {
  
temp.foo = new TIniFile();
  
temp.foo.load("mud/test.ini");

  echo(
temp.foo.section1.var1); // readed -> object.section.var
  // output = value1

And "mud/test.ini"

NPC Code:

[section1]
var1=value1
var2=value2



All credits to Inverness though

And I would suggest you to check out his two mudlibs that he released, it's worth learning from
__________________

Last edited by Chompy; 01-06-2008 at 09:46 PM..
Reply With Quote
  #3  
Old 01-06-2008, 10:25 PM
DustyPorViva DustyPorViva is offline
Will work for food. Maybe
DustyPorViva's Avatar
Join Date: Sep 2003
Location: Maryland, USA
Posts: 9,589
DustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond repute
Send a message via AIM to DustyPorViva Send a message via MSN to DustyPorViva
Well I plan on going through and making the ini objects manually... I just needed to know how to load data from them. Thanks!
Reply With Quote
  #4  
Old 01-07-2008, 12:34 AM
Kyranki Kyranki is offline
Freelance Coder
Join Date: Aug 2007
Location: At the end of the rainbow, in the pot of gold.
Posts: 202
Kyranki is on a distinguished road
Send a message via AIM to Kyranki Send a message via MSN to Kyranki
Dusty, you still make the ini objects from scratch when using what Chompy posted here...it's just a database of sorts with which instances of objects can be copied from.

So what Chompy has there joins the class to blank object and you copy in script like so...

PHP Code:
temp.file = new TIniFile();
temp.file.load("filepath"); 
__________________
Stan.
Reply With Quote
  #5  
Old 01-07-2008, 11:24 AM
Inverness Inverness is offline
Incubator
Inverness's Avatar
Join Date: Aug 2004
Location: Houston, Texas
Posts: 3,613
Inverness is a jewel in the roughInverness is a jewel in the rough
My maketype function was just to see if I could replicate object instancing like how its built-in.

It would probably be more manageable to do something like:
PHP Code:
temp.file = new TStaticVar();
temp.file.joinedclasses serverr.classes_inifile;
temp.file.load("stuff"); 
That should prevent you from having to worry about the base object being uncreated as the time your script runs. It would also allow you to update the class list for a type without going to change the script that creates it.

Also one can define public function objecttype().

I'd really like if there was a function onJoined() you could define just for classes that would be run the instant the class is joined and before the next class is joined. I'd also like a function onLeaving() that would be run when an object leaves the class; including when the object is destroyed. Graal would wait until onJoin() or onLeave() are completed before continuing();

Example:
PHP Code:
//A random weapon
function onCreated() {
  
temp.obj 0;

  
obj = new TStaticVar();
  
obj.joinedclasses = {"class1""class2""class3"};
  
// onJoined is called in order starting with first class in list, graal waits while these are finished.
  
obj.stuff(); // you do your stuff
  
obj.destroy();
  
// onLeaving is called starting with class3 and moving to class1 then when they're all complete, the object is destroyed.
}
// onCreated() would be called in the object if it still existed or no sleep() had been used in the above function. 
Quote:
Originally Posted by DustyPorViva View Post
Well I plan on going through and making the ini objects manually... I just needed to know how to load data from them. Thanks!
I just use loadlines() and parse the lines.
Quote:
Originally Posted by Chompy View Post
And I would suggest you to check out his two mudlibs that he released, it's worth learning from
I don't really like those, too overdone, its better just to have a universal MudObject that has all the features and has a single save file per object.

I currently don't even use an object for each item anymore as arrays are easier to handle, though I may change that if I find a performance difference.
__________________

Last edited by Inverness; 01-07-2008 at 11:40 AM..
Reply With Quote
  #6  
Old 01-07-2008, 10:40 PM
Chompy Chompy is offline
¯\(º_o)/¯
Chompy's Avatar
Join Date: Sep 2006
Location: Norway
Posts: 2,815
Chompy is just really niceChompy is just really niceChompy is just really nice
Send a message via MSN to Chompy
Quote:
Originally Posted by Inverness View Post
I currently don't even use an object for each item anymore as arrays are easier to handle, though I may change that if I find a performance difference.
Still a way to learn how to make MUDs
__________________
Reply With Quote
  #7  
Old 01-08-2008, 03:44 AM
Inverness Inverness is offline
Incubator
Inverness's Avatar
Join Date: Aug 2004
Location: Houston, Texas
Posts: 3,613
Inverness is a jewel in the roughInverness is a jewel in the rough
Quote:
Originally Posted by Chompy View Post
Still a way to learn how to make MUDs
Best to learn with the better way.
__________________
Reply With Quote
  #8  
Old 01-08-2008, 04:24 PM
Chompy Chompy is offline
¯\(º_o)/¯
Chompy's Avatar
Join Date: Sep 2006
Location: Norway
Posts: 2,815
Chompy is just really niceChompy is just really niceChompy is just really nice
Send a message via MSN to Chompy
Quote:
Originally Posted by Inverness View Post
Best to learn with the better way.
True, but learning something is better then nothing

Anyways, Dusty, how's it going with the MUD?
__________________
Reply With Quote
  #9  
Old 01-08-2008, 05:40 PM
DustyPorViva DustyPorViva is offline
Will work for food. Maybe
DustyPorViva's Avatar
Join Date: Sep 2003
Location: Maryland, USA
Posts: 9,589
DustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond repute
Send a message via AIM to DustyPorViva Send a message via MSN to DustyPorViva
Great! I had a talk with Andrew and I've started from scratch. Instead of worrying about indexing each item on the server in a database, I've instead appended timevar2 onto the player's clientr.var for the weapon, and added it into the data. That way the only way to create a duplicate weapon would be if the the same weapon is created in the very same second. Also eliminates the need for indexing. When the item is dropped, it'll drop its unique index with it. I want to create something more advanced than just a timevar2 ID... but since it's being stored in a clientr.var, I'm trying to keep the size down... :/ If Stefan would fix the RC bugs that wouldn't be a problem.
Reply With Quote
  #10  
Old 01-08-2008, 05:59 PM
Chompy Chompy is offline
¯\(º_o)/¯
Chompy's Avatar
Join Date: Sep 2006
Location: Norway
Posts: 2,815
Chompy is just really niceChompy is just really niceChompy is just really nice
Send a message via MSN to Chompy
Quote:
Originally Posted by DustyPorViva View Post
Great! I had a talk with Andrew and I've started from scratch. Instead of worrying about indexing each item on the server in a database, I've instead appended timevar2 onto the player's clientr.var for the weapon, and added it into the data. That way the only way to create a duplicate weapon would be if the the same weapon is created in the very same second. Also eliminates the need for indexing. When the item is dropped, it'll drop its unique index with it. I want to create something more advanced than just a timevar2 ID... but since it's being stored in a clientr.var, I'm trying to keep the size down... :/ If Stefan would fix the RC bugs that wouldn't be a problem.
What rc bugs? :o

And it's good to hear that it's going great
__________________
Reply With Quote
  #11  
Old 01-08-2008, 06:04 PM
DustyPorViva DustyPorViva is offline
Will work for food. Maybe
DustyPorViva's Avatar
Join Date: Sep 2003
Location: Maryland, USA
Posts: 9,589
DustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond repute
Send a message via AIM to DustyPorViva Send a message via MSN to DustyPorViva
Setting attr's in RC with long clientr.vars will cut the longer clientr.vars if they exceed a certain character limit.
Reply With Quote
  #12  
Old 01-08-2008, 06:24 PM
Chompy Chompy is offline
¯\(º_o)/¯
Chompy's Avatar
Join Date: Sep 2006
Location: Norway
Posts: 2,815
Chompy is just really niceChompy is just really niceChompy is just really nice
Send a message via MSN to Chompy
Quote:
Originally Posted by DustyPorViva View Post
Setting attr's in RC with long clientr.vars will cut the longer clientr.vars if they exceed a certain character limit.
Ah,, the stupid 255 chars limit? I've made several posts about it
To bad that Stefan didn't do anything about it back then..
__________________
Reply With Quote
  #13  
Old 01-08-2008, 07:29 PM
Inverness Inverness is offline
Incubator
Inverness's Avatar
Join Date: Aug 2004
Location: Houston, Texas
Posts: 3,613
Inverness is a jewel in the roughInverness is a jewel in the rough
I simply used a serverr.muditemcounter integer to give items IDs. However I just index items per object like you would in an array. I suggest you just do it like that unless you have a reason why every item in existence needs its own ID.

Fancy IDing systems are just a hassle.
__________________
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 05:29 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2026, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.