Re: [CODE] Restringing objects...

From: JonB (
Date: 12/01/98

At 12:15 AM 12/2/98 +0100, you wrote:
>Hmm .. good question would be if someone has coded it so it is loaded
after a reboot, or when a player quits >and reenters. I was thinking
simthing in a line of makeing a proto-type obj and loading that, replacing
the >data from the restringed item. But thats only a thought :)

   Well actually, I was coding this as these e-mails were coming in.  I
only allowed for the restring of the obj->short_description variable. The
new name is also added to the end of obj->name variable so the char could
use the new name to interact with the item.
   I implemented tagged ascii files, so making this save was no problem at
all, but it is still rather easy if you use the obj_file_elem variable(only
problem being: player obj wipe).  What you need to do is add a restring
variable to obj_file_elem and then fill that variable in Obj_to_store() in
obj_save.c.  You only want to fill the restring variable if the obj name is
different from the obj_proto name.

Add this to obj_file_elem:
  // Use whatever size buffer u thinkis good, MA_STRING_LENGTH is prolly a
bit too big.
  char restring[MAX_STRING_LENGTH];

So the check in Obj_to_store() would look something like:
  if (obj->short_description !=
      strcpy(object.restring, obj->short_description);
      object.restring = '\0';

That should save it just fine. Then when loading, str_dup the restring
variable if it's not NULL.

So in Obj_from_store() in obj_save.c add:
  if (object.restring != NULL)
      obj->short_description = str_dup(object.restring);

You may have to add the external declaration of *obj_proto at the top of
obj_save.c.  Also I am pretty sure that there already is aline in
free_obj() that will free the restrung variable, so dont worry about
freeing it.

That should do it; I dont think I am forgetting anything.  This will need a
player obj wipe and is just an example, so don't yell at me if it doesn't
work. :P  Hope it points you in the right direction though.


     | Ensure that you have read the CircleMUD Mailing List FAQ:  |
     | |

This archive was generated by hypermail 2b30 : 12/15/00 PST