Jump to content

saving skin


Recommended Posts

uhm so i started to learn sql and i got stuck when i want to save player skin and then load it, maybe someone can check my code and tell me what i did wrong :)

local playerstbl = "skin"
 
function start ()
executeSQLCreateTable(playerstbl, "accountname TEXT, skin INT")
outputDebugString ( "Resource loaded.", 3 )
end
addEventHandler("onResourceStart", getResourceRootElement(getThisResource()), start)
 
function login1(prev, account, autologin)
local result = executeSQLSelect(playerstbl, "skin", "accountname = '"..getAccountName(account).."'")
if result and #result > 0 then
setElementModel(source, tonumber(result[1]))
else
outputDebugString(tostring(executeSQLInsert(playerstbl, "'0', '"..getAccountName(account).."'", "skin, accountname")))
end
end
addEventHandler("onPlayerLogin", getRootElement(), login1)
 
function onPlayerQuit()
local acc = getPlayerAccount(source)
if not isGuestAccount(acc) then
outputDebugString(tostring(executeSQLUpdate(playerstbl, "skin = '"..getElementModel(source).."'", "accountname = '"..getAccountName(acc).."'")))
end
end
addEventHandler("onPlayerQuit", getRootElement(), onPlayerQuit)

Link to comment
local playerstbl =  "skin"
 
function start ()
executeSQLCreateTable(playerstbl, "accountname TEXT, skin INT")
outputDebugString ("Resource loaded.", 3)
end
addEventHandler("onResourceStart", getResourceRootElement(getThisResource()), start)
 
function login1(prev, account, autologin)
local result = executeSQLQuery("SELECT skin FROM skin WHERE accountname='" .. getAccountName(account) .. "'")
if result and #result > 0 then
for k, v in ipairs(result) do
setElementModel(source, v.skin)
end
else
outputDebugString(tostring(executeSQLInsert(playerstbl, "'0', '"..getAccountName(account).."'", "skin, accountname")))
end
end
addEventHandler("onPlayerLogin", getRootElement(), login1)
 
function onPlayerQuit()
local acc = getPlayerAccount(source)
if not isGuestAccount(acc) then
outputDebugString(tostring(executeSQLUpdate(playerstbl, "skin = '"..getElementModel(source).."'", "accountname = '"..getAccountName(acc).."'")))
end
end
addEventHandler("onPlayerQuit", getRootElement(), onPlayerQuit)

Try that. :)

Link to comment
local playerstbl =  "skin"
 
function start ()
executeSQLCreateTable(playerstbl, "accountname TEXT, skin INT")
outputDebugString ("Resource loaded.", 3)
end
addEventHandler("onResourceStart", getResourceRootElement(getThisResource()), start)
 
function login1(prev, account, autologin)
local result = executeSQLQuery("SELECT skin FROM skin WHERE accountname='" .. getAccountName(account) .. "'")
if result and #result > 0 then
for k, v in ipairs(result) do
setElementModel(source, v.skin)
end
else
outputDebugString(tostring(executeSQLInsert(playerstbl, "'0', '"..getAccountName(account).."'", "skin, accountname")))
end
end
addEventHandler("onPlayerLogin", getRootElement(), login1)
 
function onPlayerQuit()
local acc = getPlayerAccount(source)
if not isGuestAccount(acc) then
outputDebugString(tostring(executeSQLUpdate(playerstbl, "skin = '"..getElementModel(source).."'", "accountname = '"..getAccountName(acc).."'")))
end
end
addEventHandler("onPlayerQuit", getRootElement(), onPlayerQuit)

Try that. :)

yay, it works thanks you!

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...