My first meta function experiment, problems.

I´m currently experimenting a bit with meta functions, I have never used it before but am quite interested in learning how to add some simple commands like AddExperience(‘amount’).

I’m using SQLite to retrieve the information.

I’ve currently setup a test table in the SQLite database called “PlayerData”.

[SteamID] [WalkExperience]

The inserting of the players SteamID works fine, default WalkExperience is 0.


function NewPlayer(ply)

local SID = ply:SteamID()
local querystring = “INSERT INTO PlayerData(SteamID, WalkExperience) VALUES(’”…SID…"’, ‘0’)"


hook.Add(“PlayerAuthed”, “NewPlayer”, NewPlayer)


Now my AddExperience meta function.


local CSN = FindMetaTable(“Player”)

function CSN:RetrieveExperience()
local SID = self:SteamID()
local EXP = sql.QueryValue(“SELECT WalkExperience FROM PlayerData WHERE SteamID = '”…SID…"’")

return tonumber(EXP)


function CSN:AddExperience(amount)
local SID = self:SteamID()
local CurrentEXP = self:RetrieveEXP()
local NewEXP = CurrentEXP + amount

sql.Query(“UPDATE PlayerData SET WalkExperience = '”…NewEXP…"’ WHERE SteamID = ‘"…SID…"’")



And my test script hooked on PlayerDeath which would add 10 experience.


function TestMetaFunctions(ply)
hook.Add(“PlayerDeath”, “TestMetaFunctions”, TestMetaFunctions)


As I said, I’ve never touched these meta functions, and this is an experiment. But I am keen on learning how to use them, from what I’ve seen they are very handy.

Could someone give me out a few pointers, or am I like doing things totally wrong. :frowning:


Noticed an error in my script. :open_mouth:


Sorry guys got it working. :slight_smile: