ID:155790
 
Howdy.

So I was brainstorming on how to do a clansystem, and the structure seemed basic enough. You got a clan datum, setters/getters, New() to set leader/name/whatever, etc.

Now, the problems I am foreseeing have to do with saving.
  • members list containing mobs (rollback bugs)
  • loading/saving clans AND their properties in seperate files, as well as preferably a clan list
  • clans calling New() all over again when being loaded


So what's the idea way to implement saving/loading in a clan system without the above happening?

EDIT: So far I've managed to make everything functional by saving things as text, making the clans on world/New(), and on mob Login(), search if the clan with the name his clan var (which is now text) exists, if so, set that clan as his clan.

Bit messy, but it works.
The question isn't exactly clear. I'll try answering nonetheless.

members list containing mobs (rollback bugs)

If player names are exclusive, save a list of names. Otherwise associate character name with ckey and save that.

loading/saving clans AND their properties in seperate files, as well as preferably a clan list

You haven't told what properties a clan has so I don't understand your question. If you're asking how to associate a 'clan' with its respective 'clan datum': give each clan a unique identifier. Associate that identifier with respective clan savefile (or subdirectory, if you don't have separate savefiles). So for example ID "001" might point to "001.sav", which contains the information of the "Mega Ninjaz" clan.

Preferably, each /mob will have a "myClanID" property, so you only need to load clans whose players are currently online. If you use a clever hash, you can also associate clan id with clan name, so you can load clans directly by name, on demand. Alternatively you can save a table associating clan name => clan id.

clans calling New() all over again when being loaded

Unavoidable, but why is this a problem?
- You should not be adding mods to lists. Any variables that reference a mob should be a tmp variable, or should instead reference the player's key, and the mob retrieved through typecasting the client.mob variable.

- A single list containing all clan datums will suffice, and then looping through the list to re-attach the proper clans to the proper clients upon client.New().

- I don't know about you, but one workaround you could use, is to utilize the clan datum's New() to pass an argument on whether or not it should just return (since it's already created) or to continue about its normal business.
//such as...
clan
var
name
leader
New(n,mob/a)
if(!n || !a) return
src.name = n
src.leader = a

Now when the clans list is loaded, the New() will just return since no arguments are being passed to it, thus avoiding the runtime error.

I have done my own "guild" system and pretty much got it working 100% with no errors whatsoever. If you would like me to elaborate on specific points, I will.
In response to Spunky_Girl
Yep, what Spunky described is pretty much the system I'm using now. I do, however, add mobs to a list of the clan on Login() (for easy clan chat, see who's on, that sort of thing), but that simply doens't get saved.

It's been fully functional for a couple of days now with no errors. I love you, Strings.