Every time I connect to my server it creates a new row for my MySQL database.
Im using MySQLoo and changed PointShop's MySQL addon to work as with my gamemode(credits there)
Im obvious a noob with MySQL thats why I copied PointShops system.
Please don't write how to solve it as you need to check for dat in MySQL etc etc as I have zero knowledge of how a MySQL database really works.
tl;dr I prefer if you solve it for me but do it in steps so I can understand. Not just HERES THE CODE: [CODE] as I need to learn :).
Thats what I mean by creating a new row every time I join (as the same player)
[img]http://i.gyazo.com/24fb509763abaa89cd621b2b44b69368.png[/img]
Code calling the safe and loading function:
[lua]function savePlayerData(ply, hp,xp,lvl,walk,run,stamina,money,points,armor)
MySQLSetData(ply,hp,xp,lvl,walk,run,stamina,money,points,armor)
end
hook.Add("PlayerDisconnected", "savePlayerData", savePlayerData)
function getPlayerData(ply, callback)
MySQLGetData(ply, function(hp,xp,lvl,walk,run,stamina,money,points,armor)
callback(
ply:SetNWInt("Health",tonumber(hp)),
ply:SetNWInt("xp", tonumber(xp)),
ply:SetNWInt("lvl", tonumber(lvl)),
ply:SetNWInt("Walk speed", tonumber(walk)),
ply:SetNWInt("Run speed", tonumber(run)),
ply:SetNWInt("Stamina", tonumber(stamina)),
ply:SetNWInt("expPoints", tonumber(points)),
ply:SetNWInt("Armor", tonumber(armor))
)
end)
end
hook.Add("PlayerInitialSpawn", "givePlayerData", getPlayerData)[/lua]
Code for saving:
[lua]function MySQLSetData(ply, hp, xp, lvl, walk, run, stamina, money, points, armor)
if not shouldmysql then return; end
local qs = [[
INSERT INTO `deathmatch_player` (uniqueid, hp,xp,lvl,walk,run,stamina,money,points, armor)
VALUES ('%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s')
ON DUPLICATE KEY UPDATE
hp = VALUES(hp),
xp = VALUES(xp),
lvl = VALUES(lvl),
walk = VALUES(walk),
run = VALUES(run),
stamina = VALUES(stamina),
money = VALUES(money),
points = VALUES(points),
armor = VALUES(armor)
]]
qs = string.format(qs, ply:UniqueID(), hp or 0, xp or 0, lvl or 0, walk or 0, run or 0, stamina or 0, money or 0, points or 0, armor or 0)
local q = db:query(qs)
function q:onError(err, sql)
if db:status() ~= mysqloo.DATABASE_CONNECTED then
db:connect()
db:wait()
if db:status() ~= mysqloo.DATABASE_CONNECTED then
ErrorNoHalt("Re-connection to database server failed.")
return
end
end
MsgN('[Operation Strike] MySQL Query Failed: ' .. err .. ' (' .. sql .. ')')
q:start()
end
q:start()
end[/lua]
Sorry, you need to Log In to post a reply to this thread.