Clan Saving(Accessing Tables)

I made this clan system, however since I don’t have a whole lot of knowledge of sql the system is very limited. It was my first time messing with sql and I made data save to each individual player, booleans to the player if they were the leader and then I would just check for players that had the same clan name as each other when viewing the clan menu. I realize there is obviously a way better way of saving them( like I could show offline clan members in the menu ), but I am uncertain of what’s the best way. Would I create a table for a clan when it’s created and then add players to that table or what?

Decided to pick this up again now that I have more time to work on something like this and it was also never answered. All I’m asking for is like a route I would take to get something like this working efficiently(As I am very inexperienced with any kind of data saving, but wish to learn how to do it) with a large amount of capabilities I could add to it, Thanks!

Well I hate to self-advertise, but Gray Box has built in data saving functionality.

Make a single big table with all the clans and smaller tables within that table with all the clans’ info and then save it with config.AddItem(“Clans”, CLAN_TABLE). Of course, you’d have to be using Gray Box as a base for your gamemode.

You can then retrieve that table with config.GetItem(“Clans”, {}).

Okay that would work great, but another question. Say I have a table structure like this(assuming this would be the best way to structure the table)


	Players = { "Gaming_Unlim", "Bob" },
	Rank = {10},
	Cash = {199990}
	Players = { "SomeGuy", "Joe" },
	Rank = {7},
	Cash = {12490}


I was wondering…wouldn’t I have to save at least something to the player like what clan he belongs to so I know where to find him? If I didn’t wouldn’t I have to loops through all the clans when he joins so I know what clan he’s assigned to?

ply:SetPData(“Clan”, “ClanName”) on the server. You can’t GetPData on clientside, so you’ll have to send that info to the client with a usermessage.

PData is persistent as well. Saved to a little database per server.

Unfortunately you can only SetPData on players entities, otherwise you could just setPdata that table.

Probably a dumb question and bump, but I am just having the worst time figuring out dynamically constructing tables. Like for instance say I have a empty table like this

Clan_Table = {}

I can not insert other tables into that like I showed above; if someone could really help me figure this out that would be great!

You can.
Clan_Table = {}
Clan_Table[1] = {}
Clan_Table[1][1] = “hi”
Clan_Table[1][“Stuff”] = 1

Or you can make a table and use table.insert(Clan_Table, YourNewTable).

Yeah, but table.insert doesn’t add keys, it only does values.

table.insert() adds the second argument to the first table at the next available numerical key.

local tbl = {1=“se”, 2=“haha”, hi=“boop”}
table.insert(tbl, “penis”)
That would print:
tbl = {
1 = se
2 = haha
3 = penis
hi = boop

If you want to know what key you are putting your table into because it might be important, add the item yourself with TABLE[KEY] = VALUE.

Okay, I think I understand how I will go about working it all out now thanks to you, I really appreciate your help!