DarkxD Posted February 16, 2017 Share Posted February 16, 2017 (edited) Hallo, please help me! Spoiler db_name = "mta_save" host = "127.0.0.1" user = "root" password = "" database = dbConnect( "mysql", "dbname="..db_name..";host="..host, user, password ) if database then outputDebugString ('Connect') else outputDebugString ("Trouble") end function saveAccounts () local serial = getPlayerSerial ( source ) local x,y,z = getElementPosition( source ) local i = getElementInterior( source ) local d = getElementDimension( source ) local skin = getPedSkin ( source ) local money = getPlayerMoney ( source ) local health = getElementHealth ( source ) local armor = getPedArmor ( source ) local wanted = getPlayerWantedLevel ( source ) local team = getPlayerTeam ( source ) local name = getPlayerName ( source ) local q = dbQuery(database,"SELECT * FROM accounts WHERE serial = ?", serial) local poll, rows = dbPoll(q, -1) if(rows == 0) then dbExec( database, "INSERT INTO accounts ( serial , x, y, z, intterior, demension, skin, money, health, armor, wanted, team, name ) VALUES ( '" .. serial .. "', " .. x .. ", " .. y .. ", " .. z .. "," .. i .. ", " .. d .. "," .. skin .. "," .. money .. ", ".. health ..", ".. armor ..", " .. wanted .. ", " .. team .. ", " .. name .. " )" ) else dbExec ( database, "UPDATE accounts SET x = ".. x ..", y = ".. y ..", z = ".. z ..", intterior = ".. i ..", demension = ".. d ..", skin = ".. skin ..", money = ".. money ..", health = ".. health ..", armor = ".. armor ..", wanted = ".. wanted ..", team = ".. team ..", name = ".. name .." WHERE `serial` = '"..serial.."'") end end function loadAccounts () local row = dbPoll(result) setElementPosition ( source, row.x, row.y, row.z) setElementInterior ( source, row.intterior ) setElementDimension ( source, row.demension ) setPedSkin ( source, row.skin ) setPlayerMoney ( source, row.money ) setElementHealth ( source, row.health) setPedArmor ( source, row.armor ) setPlayerWantedLevel ( source, row.wanted ) setPlayerTeam ( source, row.team ) local result = dbQuery ( database ,"SELECT * FROM accounts WHERE serial = ?", serial) local poll, rows = dbPoll(result, -1) if rows == 1 then setPlayerMoney ( source, poll[1]["money"] ) end end addEventHandler ( "onPlayerJoin", getRootElement(), loadAccounts ) addEventHandler ( "onPlayerQuit", getRootElement(), saveAccounts ) Edited February 16, 2017 by DarkxD Link to comment
mint3d Posted February 17, 2017 Share Posted February 17, 2017 (edited) What errors do you have? Edited February 17, 2017 by mint3d Link to comment
Infinity# Posted February 17, 2017 Share Posted February 17, 2017 function loadAccounts() if source then local serial = getPlayerSerial(source) local result = dbQuery(database, "SELECT * FROM accounts WHERE serial = ?", serial) if result then local row = dbPoll(result) setElementPosition(source, row.x, row.y, row.z) setElementInterior(source, row.intterior) setElementDimension(source, row.demension) setElementModel(source, row.skin) setElementHealth(source, row.health) setPedArmor(source, row.armor) setPlayerWantedLevel(source, row.wanted) setPlayerTeam(source, row.team) local poll, rows = dbPoll(result, -1) if rows == 1 then setPlayerMoney(source, poll[1]["money"]) end end end end addEventHandler("onPlayerJoin", getRootElement(), loadAccounts) addEventHandler("onPlayerQuit", getRootElement(), saveAccounts) Try this. Link to comment
Infinity# Posted February 17, 2017 Share Posted February 17, 2017 2 hours ago, SARSRPG said: function loadAccounts() if source then local serial = getPlayerSerial(source) local result = dbQuery(database, "SELECT * FROM accounts WHERE serial = ?", serial) if result then local row = dbPoll(result) setElementPosition(source, row.x, row.y, row.z) setElementInterior(source, row.intterior) setElementDimension(source, row.demension) setElementModel(source, row.skin) setElementHealth(source, row.health) setPedArmor(source, row.armor) setPlayerWantedLevel(source, row.wanted) setPlayerTeam(source, row.team) local poll, rows = dbPoll(result, -1) if rows == 1 then setPlayerMoney(source, poll[1]["money"]) end end end end addEventHandler("onPlayerJoin", getRootElement(), loadAccounts) addEventHandler("onPlayerQuit", getRootElement(), saveAccounts) Try this. Also, I noticed something. Do you have a separate spawning system? Because if you do, I would understand. But upon player joining the game, if they aren't being spawned from another script, then it should be doing it from this one. Let me know Link to comment
DarkxD Posted February 25, 2017 Author Share Posted February 25, 2017 (edited) The problem http://www.kephost.com/image/wsVT Script Edited February 25, 2017 by DarkxD Link to comment
Ayush Rathore Posted February 26, 2017 Share Posted February 26, 2017 (edited) function loadAccounts() if source then local serial = getPlayerSerial(source) local result = dbQuery(database, "SELECT * FROM accounts WHERE serial = ?", serial) if result then local row = dbPoll(result,-1) setElementPosition(source, row.x, row.y, row.z) setElementInterior(source, row.intterior) setElementDimension(source, row.demension) setElementModel(source, row.skin) setElementHealth(source, row.health) setPedArmor(source, row.armor) setPlayerWantedLevel(source, row.wanted) setPlayerTeam(source, row.team) if #row > 0 then setPlayerMoney(source, poll[1]["money"]) end end end end addEventHandler("onPlayerJoin", getRootElement(), loadAccounts) try this it will work error is : you haven't read function returning values and calling same function two times Read this : https://wiki.multitheftauto.com/wiki/DbPoll Edited February 26, 2017 by Ayush Rathore Well i havent used the lua insert function for reply 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