hi i am trying to re-write a player profile save function for a gamemode that is out-dated and corrently i have the following code,
for the save function:
function SavePlayer( ply )
if not ply or not ply:IsValid() or ply.profile["Level"] == 0 then return end
--save stuff!
if !file.IsDir( "Zombified World" ) then file.CreateDir( "Zombified World" ) end
if !file.IsDir( "Zombified World/Players/" ) then file.CreateDir( "Zombified World/Players/" ) end
if !file.Exists( "Zombified World/Players/ProfileSave.txt" )
then file.Write( "Zombified World/Players/ProfileSave.txt", "Player Profiles" ) end
local savetable = {}
savetable["SteamID"] = SteamID( ply )
savetable["Level"] = ply.profile['Level']
savetable["Points"] = ply.profile['Points']
savetable["XP"] = ply.profile['XP']
savetable["Money"] = ply.profile['Money']
savetable["Hunger"] = ply.profile['Hunger']
savetable["Sleep"] = ply.profile['Sleep']
savetable["Infection"] = ply.profile['Infection']
savetable["Armor"] = ply.profile['Armor']
savetable["ArmorStatus"] = ply.profile['ArmorStatus']
savetable["StatKnowledge"] = ply.profile['StatKnowledge']
savetable["StatRepair"] = ply.profile['StatRepair']
savetable["StatHealth"] = ply.profile['StatHealth']
savetable["StatSalvage"] = ply.profile['StatSalvage']
savetable["StatEndurance"] = ply.profile['StatEndurance']
savetable["StatSpeed"] = ply.profile['StatSpeed']
savetable["StatMedSkill"] = ply.profile['StatMedSkill']
savetable["StatDamage"] = ply.profile['StatDamage']
savetable["StatDefense"] = ply.profile['StatDefense']
savetable["StatStrength"] = ply.profile['StatStrength']
savetable["StatBarter"] = ply.profile['StatBarter']
savetable["PlayerModel"] = ply.playermodel
SaveMe = glon.encode( savetable )
file.Write( "Zombified World/Players/ProfileSave.txt", SaveMe )
end
and for the load function:
function LoadPlayer( ply )
if not ply or not ply:IsValid() then return end
if !file.IsDir( "Zombified World" ) then file.CreateDir( "Zombified World" ) end
if !file.IsDir( "Zombified World/Players/" ) then file.CreateDir( "Zombified World/Players/" ) end
if !file.Exists( "Zombified World/Players/ProfileSave.txt" )
then file.Write( "Zombified World/Players/ProfileSave.txt", "Player Profiles" ) end
--check for player
local Load_Table = file.Read( "Zombified World/Players/ProfileSave.txt" )--if player, load
local datatable = glon.decode(Load_Table)
if #datatable > 0 then
ply.profile = {}
ply.profile["Level"] = datatable["Level"]
ply.profile["Points"] = datatable["Points"]
ply.profile["XP"] = datatable["XP"]
ply.profile["Money"] = datatable["Money"]
ply.profile["Hunger"] = datatable["Hunger"]
ply.profile["Sleep"] = datatable["Sleep"]
ply.profile["Infection"] = datatable["Infection"]
ply.profile["Armor"] = datatable["Armor"]
ply.profile["ArmorStatus"] = datatable["ArmorStatus"]
ply.profile["StatKnowledge"] = datatable["StatKnowledge"]
ply.profile["StatRepair"] = datatable["StatRepair"]
ply.profile["StatHealth"] = datatable["StatHealth"]
ply.profile["StatSalvage"] = datatable["StatSalvage"]
ply.profile["StatEndurance"] = datatable["StatEndurance"]
ply.profile["StatSpeed"] = datatable["StatSpeed"]
ply.profile["StatMedSkill"] = datatable["StatMedSkill"]
ply.profile["StatDamage"] = datatable["StatDamage"]
ply.profile["StatDefense"] = datatable["StatDefense"]
ply.profile["StatStrength"] = datatable["StatStrength"]
ply.profile["StatBarter"] = datatable["StatBarter"]
ply.playermodel = datatable["PlayerModel"]
else
ply.profile = {}
ply.profile["Money"] = 3000
ply.profile["XP"] = 0
ply.profile["Level"] = 1
ply.profile["Points"] = 1
ply.profile["Armor"] = "Male Civilian Gear"
ply.profile["Hunger"] = 100
ply.profile["Sleep"] = 100
ply.profile["Infection"] = 0
ply.profile["ArmorStatus"] = 100
ply.playermodel = "models/player/kleiner.mdl"
--stats
for k, v in pairs( Stats ) do
ply.profile[k] = 0
end
SavePlayer( ply )
print( "Created data file for " .. ply:Nick() .. "\n" )
--show f1
umsg.Start( "StartMenu", ply )
umsg.End()
end
end
i wish to know...
A. if this will work, and if not what is wrong with it.
B. how to make it load and save a person specific profile using their Steam ID to a single file
thanks
[lua ][/lua] lua tags are cool
Zombified World is broken. Try actually learning Lua before wrecking our gamemode further.
Sorry, you need to Log In to post a reply to this thread.