Player "accounts"

Alright, so…

I have the whole concept down, but i’m a bit stumped on how to actually put it into my script.

What i want done is:

  1. The player joins the server
  2. Under the InitialSpawn function, it will look for the player’s SteamID in a table.
  3. If there is a value present (table[ply:SteamID()] != nil) it will restore other values that are specific to that player’s “account”

now this would look like this I would imagine…

function GM:InitialSpawn( ply )

if (table[ply.SteamID()] != nil) then
         //set the player's team accordingly, give them whatever
        //add the player's id into the table


I think I saw somewhere that you can create subtables within tables? So i was wondering if it was possible to do so, so that way each steamid would be a subtable and then i could set each value within each subtable. IE who they are, what was in their inventory, what weapons they had, ect.

The other half of this script would be:

  1. The player disconnects from the server.
  2. The player’s info gets saved in the corresponding subtable.

Any help would be appreciated.
Thanks in advance.

putting a table in another one is no problem at all (did you take your pil? ;~):
myTable = {“Hello World”, answer = 42, {“A table in a table?”, “Yes!”, 0100100001101001, {}}, nil}
Here we have three nested tables, including an empty one. As for saving the data, it won’t help to put the steam id in a table, since it’s only stored in RAM and not on disk, where you probably want it. To save it permanently, you’d want to write it in a file as plain text or via database (mySQL for instance), the first option being the far less complicated solution - generally speaking.

I only took about half of my pil.

So should i use UniqueID for my table then? Can i use a single UniqueID to forever represent a single player? Thats the only thing I’m afraid of…

And also, if i’m using sub-tables (as i call them :P), how might i go about writing a value to a specific subtable with table.insert or something like it?

From what the wiki says the Unique ID seems to be the way to go (the steam id of a player does not change and the unique id is derived from it; but I don’t know anything about that and might be terribly, terribly wrong, so why don’t you just try it?).

About accessing members of a table, I’d do it like this (but… see above ;~):
– let’s pretend we use this table to manage the players on our server
users =
{nick = “UberJaques”, ip = “localhost”, steamid = “STEAM_0:0:1234”, uber = “very”},
{nick = “b114attwhore”, ip = “”, steamid = “STEAM_0:0:1235”, uber = “nay”}

– now we’re going to change the uberness of UberJaques…
users[1].uber = “exceptionally”
– …add a value to b114attwhore…
users[2].lastvisit = “17/10/2009”
– …and add another user! (yay!)
users[3] = {nick = “hol11st”, ip = “”, steamid = “censored”, uber = “no”}

– did it work?
for i = 1, #users do
for key, value in pairs(users*) do print(key, value) end
– I hope so… (output is a bit messy, though :~)



S:\workbench\lua	emp>lua5.1 test.lua
uber    exceptionally
nick    UberJaques
steamid STEAM_0:0:1234
ip      localhost
steamid STEAM_0:0:1235
nick    b114attwhore
uber    nay
lastvisit       17/10/2009
uber    no
nick    hol11st
steamid censored

This is only for (self) educational purposes and not to show how you’d actually work with user data (not that I knew anything about that :~). Read the parts about tables again and look for good tutorials if you need more info on that. And play around with the interpreter, it’s a good way to answer simple questions instead of waiting patiently for someone to help you out.

UniqueID equals to util.CRC(“gm” … player:SteamID() … “gm”), from what I can remember.

That was very helpful, thank you.

I just took some Nyquil (green death flavor >:O) so i’m going to crash for tonight.
I’ll start working on the script tomorrow and we’ll see what happens.

It pretty much looks like your example is all i need.

Nope :l