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) San Andreas Utopia RPG (SAUR) Owner & Developer. Education is the most powerful weapon which you can use to change the world.
dzek (varez) Posted May 18, 2010 Posted May 18, 2010 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)!
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! San Andreas Utopia RPG (SAUR) Owner & Developer. Education is the most powerful weapon which you can use to change the world.
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