-- player character table chars = {} function playerexists (name) name = capitalize (name) if chars [name] then return true end -- exists and is online local dir = config.player_dir .. string.sub (name, 1, 1) -- see if file exists f = io.open (dir .. "/" .. name, "r") if f then f:close () return true end -- player file exists return false -- no such player end -- playerexists function SaveCharacter (name) name = capitalize (name) local char = chars [name] local dir = config.player_dir .. string.sub (name, 1, 1) -- open file to serialize into local f, err = io.open (dir .. "/" .. name, "w") -- too bad if we can't assert (f, err) -- don't want to serialize client table for various reasons local client = char.client char.client = nil -- save all player data ok, err = f:write (serialize (name, char)) -- put it back char.client = client -- done with file f:close () -- now check for errors assert (ok, err) end -- SaveCharacter function LoadCharacter (name) name = capitalize (name) local char = chars [name] local dir = config.player_dir .. string.sub (name, 1, 1) -- load the file, get a function to execute local f, err = loadfile (dir .. "/" .. name) -- oops, if not found assert (f, err) -- want to load this character into the chars table setfenv (f, chars) -- load it f () end -- LoadCharacter