Wyll_ Posted October 20, 2022 Share Posted October 20, 2022 Bom Minha duvida é a seguinte estou tentando obter os dados salvo da data-base, que eu fiz para treinar mas a questão e que no final só consigo retornar table não o valor dentro dela local db = dbConnect("sqlite","db/savesystem.db") function loaddb() dbExec(db,"CREATE TABLE IF NOT EXISTS SaveSystem(Account TEXT, Serial TEXT, Money REAL, POS TEXT, Skin TEXT )") print("DATA BASE CRIADA") end addEventHandler("onResourceStart",getRootElement(getThisResource()),loaddb) addEventHandler("onPlayerQuit",root,function() local result = dbPoll(dbQuery(db,"SELECT * FROM SaveSystem WHERE Account = ?",getAccountName(getPlayerAccount(source))),-1) if #result < 1 then local posx, posy,posz = getElementPosition(source) local skin = getElementModel(source) local serial = getPlayerSerial(source) local money = getPlayerMoney(source) local acc = getAccountName(getPlayerAccount(source)) local pos = {posx,posy,posz} dbExec(db,"INSERT INTO SaveSystem(Account,Serial,Money,POS,Skin) VALUES(?,?,?,?,?)",acc,serial,money,toJSON(pos),skin) print("DATA BASE INSERIU") else local posx, posy,posz = getElementPosition(source) local skin = getElementModel(source) local serial = getPlayerSerial(source) local money = getPlayerMoney(source) local acc = getAccountName(getPlayerAccount(source)) local pos = {posx,posy,posz} dbExec(db,"UPDATE SaveSystem SET Account=?,Serial=?,Money=?,POS=?,Skin=?",acc,serial,money,toJSON(pos),skin) print("DATA ATUALIZOU") end end) addEventHandler("onPlayerLogin",root,function() local result = dbPoll(dbQuery(db,"SELECT * FROM SaveSystem WHERE Account = ?",getAccountName(getPlayerAccount(source))),-1) if #result > 0 then setPlayerMoney(source,result[3]["SaveSystem"] ) --setPlayerMoney(source,dbPoll(dbQuery(db,"SELECT * FROM SaveSystem WHERE Money = ?",-1))) tentei dessa forma mas retorna table tb else return print("N tem info") end end) Link to comment
kingsmi Posted October 21, 2022 Share Posted October 21, 2022 function data() local result = dbPoll(dbQuery(db,"SELECT * FROM SaveSystem "), -1) if not result or #result > 0 then for i,v in ipairs(result) do outputChatBox ( ""..v["Account"].."", getRootElement(), 255, 255, 255, true ) end end end addCommandHandler("valor", data) Link to comment
kingsmi Posted October 21, 2022 Share Posted October 21, 2022 41 minutes ago, kingsmi said: function data() local result = dbPoll(dbQuery(db,"SELECT * FROM SaveSystem "), -1) if not result or #result > 0 then for i,v in ipairs(result) do outputChatBox ( ""..v["Account"].."", getRootElement(), 255, 255, 255, true ) end end end addCommandHandler("valor", data) function setMoney() local select = dbQuery(db, "SELECT * FROM SaveSystem WHERE Account=?", getAccountName(getPlayerAccount(source))) local sql = dbPoll(select, -1) if #sql > 0 then setPlayerMoney(source, sql[1].Money) end end addEventHandler ('onPlayerLogin', root, setMoney) 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