Castillo Posted May 18, 2010 Posted May 18, 2010 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)
dzek (varez) Posted May 18, 2010 Posted May 18, 2010 any errors? its saving ok, but not loading, or both not working?
KingMofo Posted May 18, 2010 Posted May 18, 2010 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.
Castillo Posted May 18, 2010 Author Posted May 18, 2010 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!
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now