ID:1476153
 
(See the best response by Albro1.)
I'm making a PVP game and i want people to make their own guilds but how do i start? I read the guide already.
Best response
Create a datum for guilds and store the members in a list variable contained in the datum.
Guild
var
list
Members = list()


What else?
I'm not going to walk you step-by-step through how to create a game-specific feature that you can probably find by using the search feature.

If you create a new guild datum, give it a name or something to distinguish it, and assign it members, you have a basic "team" functionality and what you do with it is entirely up to you.
Here is an example for you..

Guild
var
name
tmp
list/online = list()
list/members
owner
level = 1
proc
GuildInvite(var/mob/inviter,var/mob/invited)
if(inviter.guild==src&&invited.guild==null)
switch(alert("[inviter] invites you to join the guild [name].","Yes","No"))
if("No") return
if("Yes")
Joined(invited)

Joined(var/mob/m)
m.guild = src
m.guild_name = src.name
src.online += m
src.members += m.name

Login(var/mob/player/m)
online += m
m.guild = src

Logout(var/mob/player/m)
online -= m
if(src.online.len==0)
del src

Create(var/mob/player/m)
owner = m.name
members += m.name

while(src.name==null)
src.name = input("What will you name your guild?") as text|null
if(fexists("saves/guilds/[ckey(src.name)].sav"))
src.name = null

var/savefile/F = new/savefile("saves/guilds/[ckey(src.name)].sav")
F << src
guilds[src.name] = src
Read(var/savefile/F)
. = ..()
if(src.name)
guilds[src.name] = src
Del()
if(src.name)
var/savefile/F = new/savefile("saves/guilds/[ckey(src.name)].sav")
F << src
guilds -= src.name
return ..()

var
list
guilds = list()

proc
getGuild(var/name)
if(name==null) return null
if(name in guilds)
return guilds[name]
else if(fexists("saves/guilds/[ckey(src.name)].sav"))
var/savefile/F = new/savefile("saves/guilds/[ckey(src.name)].sav")
var/Guild/g
f >> g
return g
else
return null

mob/player
var
guild_name = null
tmp
Guild/guild
Login()
. = ..()
src.guild = getGuild(src.guild_name)
if(src.guild)
src.guild.Login(src)
Logout()
if(src.guild)
src.guild.Logout(src)
. = ..()


Note; Credits goes to Ter13
Should probably be passing the correct value to the first argument of input() and alert(), otherwise you're not gonna get them sent to the right place.
In response to Atol Soldier
This one looks promising but when you leave the guild does the save delete?
In response to Dimensive
Well, I traced the code and I don't really see a leave proc. You'll probably have to design that yourself. It's really simple.

We'll take the Create() proc as a base:
        Create(var/mob/player/m)
owner = m.name
members += m.name

while(src.name==null)
src.name = input("What will you name your guild?") as text|null
if(fexists("saves/guilds/[ckey(src.name)].sav"))
src.name = null
//Creates the savefile destination
var/savefile/F = new/savefile("saves/guilds/[ckey(src.name)].sav")
//Writes to that destination
F << src
guilds[src.name] = src


If we basically understand those two lines that I commented, then you can go about doing something like this:
        Leave(var/mob/player/m)
if(m in members)
members -= m
if(members.len<=0)
//del(src), fdel() the savefile, and do all sorts of other stuff to make sure it obliterated
else
var/savefile/F = new/savefile("saves/guilds/[ckey(src.name)].sav")
F << src
guilds[src.name] = src
@xirre; no. Just no. Bad bad bad.

The system ter made, seems to be more of a party guild. When everyone leaves it auto-disbands.

I remember when I couldn't understand how to create a clan system or party system.. now I laugh cause it's so easy.

Practice pays off.
In response to Flysbad
Flysbad wrote:
@xirre; no. Just no. Bad bad bad.

The system ter made, seems to be more of a party guild. When everyone leaves it auto-disbands.

I remember when I couldn't understand how to create a clan system or party system.. now I laugh cause it's so easy.

Practice pays off.

It was hard? When?

And don't tell me no, punk. D: I skimmed through it. Pardon me. I didn't see the Logout() part thoroughly.
In response to Flysbad
Flysbad wrote:
@xirre; no. Just no. Bad bad bad.

The system ter made, seems to be more of a party guild. When everyone leaves it auto-disbands.

Actually, Xirre is spot on with his example.

The reason that you are thinking it's a party-based thing where when everyone logs out that's in the guild, it disbands, is because you aren't paying close enough attention to how the guilds save.

Basically, when everyone in the guild goes offline, we don't need to keep the guild datum in memory, so we delete the guild from the loaded guilds global list.

The guild still exists in the file structure even though it's no longer in memory. We just don't want to keep objects around in memory that aren't being used, because if none of the members are online, we obviously won't be doing anything with the guild.

This introduces some complications, like searching for guild information when everyone in the guild is offline. My solution doesn't account for this, but adding it would be somewhat trivial.
In response to Flysbad
Guild
var
name
tmp
list/online = list()
list/members
owner
level = 1
proc
GuildInvite(var/mob/inviter,var/mob/invited)
if(inviter.guild==src&&invited.guild==null)
switch(alert("[inviter] invites you to join the guild [name].","Yes","No"))
if("No") return
if("Yes")
Joined(invited)

Joined(var/mob/m)
m.guild = src
m.guild_name = src.name
src.online += m
src.members += m.name
//you should save the player here too.
Save()

//remove a player by reference. (This is probably only going to be called by the player themselves)
Leave(var/mob/player/m)
if(owner==m.name)
if(members.len>1)
. = null
while(!(. in members))
. = ChooseLeader(m)
if(.==null)
return
owner = .
else
owner.guild_name = null
owner.guild = null
fdel("saves/guilds/[ckey(src.name)].sav")
guilds -= src.name
src.name = null
del src
src.members -= m.name
m.guild_name = null
m.guild = null
src.Logout(m)
Save() //if logout didn't trigger a save during deletion, this will force the save to happen.

//remove a player by name (If they are offline, or by using a kick command, for instance.)
Remove(var/player)
if(player in members)
for(var/mob/player/p in online)
if(p.name==player)
Leave(p)
return

if(owner==player)
return 0
members -= player
Save()

ChooseLeader(var/mob/player/m)
var/list/l = src.members.Copy(1,0)
l -= owner
return input(m,"Change leader","Who should become owner of [src.name]?") as text|null in l

Login(var/mob/player/m)
if(m.name in members)
online += m
m.guild = src
else
m.guild_name = null
m.guild = null
if(src.online.len==0)
//avoid saving, and undo loading guild
guilds -= src.name
src.name = null
del src

Logout(var/mob/player/m)
online -= m
if(src.online.len==0)
del src

Create(var/mob/player/m)
owner = m.name
members += m.name

while(src.name==null)
src.name = input("What will you name your guild?") as text|null
if(fexists("saves/guilds/[ckey(src.name)].sav"))
src.name = null

Save()
guilds[src.name] = src

Save()
var/savefile/F = new/savefile("saves/guilds/[ckey(src.name)].sav")
F << src

Read(var/savefile/F)
. = ..()
if(src.name)
guilds[src.name] = src
Del()
if(src.name)
Save()
guilds -= src.name
return ..()

var
list
guilds = list()

proc
getGuild(var/name)
if(name==null) return null
if(name in guilds)
return guilds[name]
else if(fexists("saves/guilds/[ckey(name)].sav"))
var/savefile/F = new/savefile("saves/guilds/[ckey(name)].sav")
var/Guild/g
F >> g
return g
else
return null

mob/player
var
guild_name = null
tmp
Guild/guild
Login()
. = ..()
src.guild = getGuild(src.guild_name)
if(src.guild)
src.guild.Login(src)
Logout()
if(src.guild)
src.guild.Logout(src)
. = ..()


I've taken the liberty of fixing this snippet I hastily typed out for Atol Soldier in a private chat. You will find that there are now commands that allow people to leave the guild, as well as people to be kicked from the guild. I also fixed a small number of bugs in the implementation, and some oversights, such as what happens when someone is kicked from the guild when they are offline. Note that the player's guild_name variable can be inaccurate on initial load, hence we check to see if the player is actually in the guild after initial login and loading of the old guild information. If that player was kicked, and the only person in that guild to come online, the guild will automatically unload itself immediately, and won't save anything, because the guild information is always up-to-date.

You should of course, always save the player after a change in guild status, because every time we invite a person to the guild, or kick a person from the guild, we are saving the guild information. If you don't save the player, you can potentially wind up with desynchronized guild information. This is particularly bad when you don't save the player after they join a guild, because there's no way to figure out which guild the player belongs to without searching through the contents of every guild on the server, thus loading every guild on the server to do it. It's better to just ensure that the player's information is saved any time that the player's guild status changes.

You'll have to write a lot of your own behaviors for actually allowing people to access them, but it should be pretty simple to do all of that.