Coding Exp system

Hello guys , im coding a exp system :slight_smile: i already code like the main file like ( skeleton of the exp system ) using tables… ( MYSQL )

—> I Just have a question…

( this is the BUY FUNCTION BASED ON A TEXT FILE VERSION OF THIS SYSTEM )



function MaxHpBuy(pl)
if pl:GetNWInt("SkillPoints") <= 0 then return false end
if pl:GetNWInt("Skill_HP") >= 30 then pl:PrintMessage(HUD_PRINTTALK, "You Reach The Max Level of HP") return false end
pl:SetNWInt("Skill_HP",pl:GetNWInt("Skill_HP") + 1)
pl:SetMaxHealth(pl:GetMaxHealth() + MaxHpGain)
pl:SetHealth(pl:Health() + MaxHpGain)
pl:SetNWInt("SkillPoints",pl:GetNWInt("SkillPoints") - 1)
file.Write("exp/"..pl:UniqueID().."_skill_hp.txt", pl:GetNWInt("Skill_HP"))
file.Write("exp/"..pl:UniqueID().."_skillpoints.txt", pl:GetNWInt("SkillPoints"))
end
concommand.Add( "skill1buy",MaxHpBuy )


as you can see there appera the file.Write



file.Write("exp/"..pl:UniqueID().."_skill_hp.txt", pl:GetNWInt("Skill_HP"))
file.Write("exp/"..pl:UniqueID().."_skillpoints.txt", pl:GetNWInt("SkillPoints"))


how i can change this file.Write to ( WRITE THE TABLE ? that im using ? )
Thanks. :slight_smile:

[editline]16th August 2012[/editline]

maybe if i use something like this




sql.Query("UPDATE player_skills SET Resistance = "..Resistance.." WHERE unique_id = '"..unique_id.."'")
sql.Query("UPDATE player_skills SET Puntos = "..Puntos.." WHERE unique_id = '"..unique_id.."'")



Why don’t you use PData? Player:SetPData(), Player:GetPData()

For example:

Player:SetPData(“resistance”, Player:GetPData(“resistance”) + 1)



function loadplydata(ply)
ply:SetNWInt("SkillPoints", ply:GetPData("resistance"))
end
hook.Add("PlayerInitialSpawn", "loaddata", loadplydata)


Or whatever, this seems easier, PData is stored in SQLite anyway, beating flatfile storage by miles.