ID:160136
 
I have several list in my game for different things (guild members, friends, parties, etc) and on my last game I had a lot of trouble with saving and having references to mobs so I add only the players name to the list to avoid this. But working on my guild system I found that its kinda a pain to deal with this way cause every time a name out i need to cycle through the players and and check for the same name and then use that mob.

I was wondering what would be an easier way to do that and not have it associated with the mob so i dont get save problems.

heres an example of what im talking about:this is my guild datum and one of the verbs
Guild
var/name
var/list/players
var/members=0
New(mob/M, nm)
name = nm
players = list()
Add(M)
Guilds += src
Del(mob/N)
Guilds -= src
N.guildowner=4
for(var/mob/M in players)
M << "[N] disbands [name]."
Remove(M)
..()
proc/Add(mob/M)
players << "[M.name] joins the guild."//like here i need to cycle through players in teh world to make it work
players["[M.name]"]="[M.key]"//this is how im currently adding them but would be easier if i could do this players[M]="[M.key]"
M << "You [(players.len>1)?"join":"form"] [name]."
M.guild = src
if(players.len==1)
usr.guildtitle="Leader"
usr.guildowner=4
else
M.guildtitle="Member"
M.guildowner=4
members++
proc/Remove(mob/M)
if(M.guild == src)
M.guild = null
players -= M.name
players << "[M.name] leaves the guild."
M << "You [(players.len)?"leave":"disband"] [name]."
if(!players.len)
del(src)

Guild_Say(msg as text)
for(var/M in usr.guild.players)
for(var/mob/N in Players)
if(N.name==M)
N<<"[usr.guildtitle]--[usr]: [msg]"
NightJumper88 wrote:
(...) I had a lot of trouble with saving and having references to mobs so I add only the players name to the list to avoid this. But working on my guild system I found that its kinda a pain to deal with this way cause every time a name out i need to cycle through the players and and check for the same name and then use that mob.

I was wondering what would be an easier way to do that and not have it associated with the mob so i dont get save problems.

Assuming that you're using the automatic safe system, maybe the use of tmp could ease your trouble with saving referenced objects?

That is without reading your code.
In response to Schnitzelnagler
the only problem is i want to save the list its intentional to save the list
In response to NightJumper88
NightJumper88 wrote:
the only problem is i want to save the list its intentional to save the list

Save a list of client ckeys rather than saving the mobs themselves. You'll have to add a bit of code to compare ckeys with guild membership when a player logs in, but it should solve your problem. You can also try storing a reference in the player's mob as to what guild they belong to. If guild names are unique, you could use that.

As an aside, using usr in your Add() proc isn't that good of an idea. Also, you don't need to keep track of a count of total members manually. You can check the length of the member list itself quite easily.
In response to Jon88
Yeah thats pretty much what im doing now i was just wondering so that I dont have to cycle through the mobs in the Players list, as for the usr thanks I missed that code I recently changed my interface and needed to change that as well and missed those usr (copy paste from another part whoops). Im thinking what I might do is create a temp list and add the mobs to that so ill have two list and just use the temp one to call any data so i dont have to cycle through