Jump to content

saving skin


Recommended Posts

Posted

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)

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted

any errors?

its saving ok, but not loading, or both not working?

Multi theft auto tools - replace cars and peds, move your map or compile your Lua files online!

programista php rzeszów

Need free webhosting for your small site? PM me. Need help with portforwarding? PM me. Do not PM me asking for help with scripting.

Having problems with port forwarding? Send me pm, I can do whole thing for you using TeamViewer (already helped about 20 people, no worries)!

Posted
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. :)

Posted
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!

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

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...