Kenix Posted August 24, 2011 Share Posted August 24, 2011 (edited) function create_tables() executeSQLCreateTable ( "users", "user STRING, health INT, armor FLOAT, money INT, x FLOAT, y FLOAT, z FLOAT, wanted INT, skin INT, dim INT, int INT, r INT, g INT, b INT, jailtime INT" ) end addEventHandler("onResourceStart",resourceRoot,create_tables) function save_general() local health = getElementHealth(source) local Armor = getPedArmor(source) local money = getPlayerMoney(source) local x,y,z = getElementPosition(source) local wanted = getPlayerWantedLevel(source) local skin = getElementModel(source) local dim = getElementDimension (source) local int = getElementInterior (source) local r, g, b = getPlayerNametagColor ( source ) local playername = getPlayerName ( source ) local jailtime = getElementData(source,"jailtime") executeSQLUpdate( "users", "user = '" .. getAccountName( getPlayerAccount( source ) ) .. "', health = '" .. health .. "', armor = '" .. armor .. "', money = '" .. money .. "', x = '" .. x .. "', y = '"..y.."'z = '" .. z .."',wanted = '".. wanted .."',skin = '".. skin .."',dim = '".. dim .. "',int = '".. int .."',r = '".. r .. "',g = '".. g .."',b = '".. b .. "',jailtime = '".. jailtime .."'") end addEventHandler("onPlayerQuit",root,save_general) function save_setData() local userTable = executeSQLSelect ( "users", "user","user = '" .. getAccountName( getPlayerAccount( source ) ) .. "'", "health", "armor", "money", "x", "y", "z", "wanted","skin","dim","int","r","g","b","jailtime" ) setElementHealth(source,userTable[3]) setPedArmor(source,userTable[4]) setPlayerMoney(source,userTable[5]) setElementPosition( source, userTable[6], userTable[7], userTable[8] ) setPlayerWantedLevel(source,userTable[9]) setElementModel(source,userTable[10]) setElementDimension (source,userTable[11]) setElementInterior (source,userTable[12]) setPlayerNametagColor ( source, userTable[13], userTable[14], userTable[15] ) setElementData(source,"jailtime",userTable[16) end addEventHandler( "onPlayerLogin", root, save_setData ) Debug says on login: [2011-08-24 11:29:54] WARNING: save_system\account_s.lua:26: Bad argument @ 'setElementHealth' [2011-08-24 11:29:54] WARNING: save_system\account_s.lua:27: Bad argument @ 'setPedArmor' [2011-08-24 11:29:54] WARNING: save_system\account_s.lua:28: Bad argument @ 'setPlayerMoney' [2011-08-24 11:29:54] WARNING: save_system\account_s.lua:29: Bad argument @ 'setElementPosition' [2011-08-24 11:29:54] WARNING: save_system\account_s.lua:30: Bad argument @ 'setPlayerWantedLevel' [2011-08-24 11:29:54] WARNING: save_system\account_s.lua:31: Bad argument @ 'setElementModel' [2011-08-24 11:29:54] WARNING: save_system\account_s.lua:32: Bad argument @ 'setElementDimension' [2011-08-24 11:29:54] WARNING: save_system\account_s.lua:33: Bad argument @ 'setElementInterior' [2011-08-24 11:29:54] WARNING: save_system\account_s.lua:34: Bad argument @ 'setPlayerNametagColor' thx in advance Edited August 26, 2011 by Guest Link to comment
CrazyDude Posted August 24, 2011 Share Posted August 24, 2011 executeSQLSelect returns 2-dimensional table. You are using 1-dimensional table. So try this one: function create_tables() executeSQLCreateTable ( "users", "user STRING, health INT, armor FLOAT, money INT, x FLOAT, y FLOAT, z FLOAT, wanted INT, skin INT, dim INT, int INT, r INT, g INT, b INT, jailtime INT" ) end addEventHandler("onResourceStart",resourceRoot,create_tables) function save_general() local health = getElementHealth(source) local Armor = getPedArmor(source) local money = getPlayerMoney(source) local x,y,z = getElementPosition(source) local wanted = getPlayerWantedLevel(source) local skin = getElementModel(source) local dim = getElementDimension (source) local int = getElementInterior (source) local r, g, b = getPlayerNametagColor ( source ) local playername = getPlayerName ( source ) local jailtime = getElementData(source,"jailtime") executeSQLUpdate( "users", "user = '" .. getAccountName( getPlayerAccount( source ) ) .. "', health = '" .. health .. "', armor = '" .. armor .. "', money = '" .. money .. "', x = '" .. x .. "', y = '"..y.."'z = '" .. z .."',wanted = '".. wanted .."',skin = '".. skin .."',dim = '".. dim .. "',int = '".. int .."',r = '".. r .. "',g = '".. g .."',b = '".. b .. "',jailtime = '".. jailtime .."'") end addEventHandler("onPlayerQuit",root,save_general) function save_setData() local userTable = executeSQLSelect ( "users", "user","user = '" .. getAccountName( getPlayerAccount( source ) ) .. "'", "health", "armor", "money", "x", "y", "z", "wanted","skin","dim","int","r","g","b","jailtime" ) setElementHealth(source,userTable[1][3]) setPedArmor(source,userTable[1][4]) setPlayerMoney(source,userTable[1][5]) setElementPosition( source, userTable[1][6], userTable[1][7], userTable[1][8] ) setPlayerWantedLevel(source,userTable[1][9]) setElementModel(source,userTable[1][10]) setElementDimension (source,userTable[1][11]) setElementInterior (source,userTable[1][12]) setPlayerNametagColor ( source, userTable[1][13], userTable[1][14], userTable[1][15] ) setElementData(source,"jailtime",userTable[1][16) end addEventHandler( "onPlayerLogin", root, save_setData ) Link to comment
Kenix Posted August 24, 2011 Author Share Posted August 24, 2011 not working i check database not adding data Link to comment
LoveFist Posted August 24, 2011 Share Posted August 24, 2011 not workingi check database not adding data First you must insert something in table. Use executeSQLInsert when creating account. Link to comment
Kenix Posted August 24, 2011 Author Share Posted August 24, 2011 not workingi check database not adding data First you must insert something in table. Use executeSQLInsert when creating account. So i create it it work adding data. but Debug says on login: [2011-08-24 11:29:54] WARNING: save_system\account_s.lua:26: Bad argument @ 'setElementHealth' [2011-08-24 11:29:54] WARNING: save_system\account_s.lua:27: Bad argument @ 'setPedArmor' [2011-08-24 11:29:54] WARNING: save_system\account_s.lua:28: Bad argument @ 'setPlayerMoney' [2011-08-24 11:29:54] WARNING: save_system\account_s.lua:29: Bad argument @ 'setElementPosition' [2011-08-24 11:29:54] WARNING: save_system\account_s.lua:30: Bad argument @ 'setPlayerWantedLevel' [2011-08-24 11:29:54] WARNING: save_system\account_s.lua:31: Bad argument @ 'setElementModel' [2011-08-24 11:29:54] WARNING: save_system\account_s.lua:32: Bad argument @ 'setElementDimension' [2011-08-24 11:29:54] WARNING: save_system\account_s.lua:33: Bad argument @ 'setElementInterior' [2011-08-24 11:29:54] WARNING: save_system\account_s.lua:34: Bad argument @ 'setPlayerNametagColor' Link to comment
SDK Posted August 24, 2011 Share Posted August 24, 2011 So, we can assume the data is correctly in the database (you checked with sqlitebrowser/functions/...) Do a for key, value in pairs(userTable) do loop, output the key and the value, and you'll see what you did wrong. Link to comment
Kenix Posted August 24, 2011 Author Share Posted August 24, 2011 output Key: 1 Value: 0 Link to comment
LoveFist Posted August 24, 2011 Share Posted August 24, 2011 Try: function save_setData() local userTable = executeSQLSelect ( "users", "*","user = '" .. getAccountName( getPlayerAccount( source ) ) .. "'") setElementHealth(source,userTable[1]['health']) setPedArmor(source,userTable[1]['armor']) setPlayerMoney(source,userTable[1]['money']) setElementPosition( source, userTable[1]['x'], userTable[1]['y'], userTable[1]['z']) setPlayerWantedLevel(source,userTable[1]['wanted']) setElementModel(source,userTable[1]['skin']) setElementDimension (source,userTable[1]['dim']) setElementInterior (source,userTable[1]['int']) setPlayerNametagColor ( source, userTable[1]['r'], userTable[1]['g'], userTable[1]['b'] ) setElementData(source,"jailtime",userTable[1]['jailtime']) end addEventHandler( "onPlayerLogin", root, save_setData ) Link to comment
Kenix Posted August 24, 2011 Author Share Posted August 24, 2011 So not spawn player but errors not write. Link to comment
SDK Posted August 24, 2011 Share Posted August 24, 2011 What do you mean not spawn, did you add spawnPlayer() ? Link to comment
Kenix Posted August 25, 2011 Author Share Posted August 25, 2011 What do you mean not spawn, did you add spawnPlayer() ? yes Link to comment
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