Wananazo Posted June 11, 2022 Share Posted June 11, 2022 (edited) Hello, my language is Spanish and the tutorial videos that I have seen are in other languages, it has been difficult for me to understand so I chose to post here it turns out that I am learning to create a sqlite database or at least trying and I have a problem with this script that does not have a database, I am trying to make one in sqlite with dbbrowser but I do not understand how the queries would be in sqlite since it throws me an error if someone can guide me I want to learn addEventHandler("onResourceStart", getResourceRootElement(getThisResource()), function () for i,v in ipairs(getElementsByType("player")) do bindKey(v, config.BindAbrirNormal, 'down', AbrirPainel) end db = dbConnect("mysql", "dbname=s288_teste;host=HIDDEN BY STAFF;charset=utf8", "", "") if db then outputDebugString("[DB-MySQL] Conectado com sucesso!") else outputDebugString("[DB-MySQL] Não foi possível fazer a conexão") end elseif config["Database"].SQLite then db = dbConnect("sqlite", "base.db") dbExec(db, 'CREATE TABLE IF NOT EXISTS LogsGroup (Logs, Date, Grupo)') dbExec(db, 'CREATE TABLE IF NOT EXISTS InfoGrupos(Conta, NomeGrupo, Cargo, InfosApreensoes, Renda, UltimoLogin)') dbExec(db, 'CREATE TABLE IF NOT EXISTS Grupos(Tag, Nome, LimiteMembros, Lider, InfosApreensoes, Tipo, Saldo)') dbExec(db, 'CREATE TABLE IF NOT EXISTS RendaGrupos(NomeGrupo, Rendas)') if db then outputDebugString("[DB] Banco de dados conectado com sucesso!") else outputDebugString("[DB] Banco de dados não conseguiu se conectar!") end end local result = dbPoll(dbQuery(db, 'SELECT * FROM Grupos'), -1) addEvent("JOAO.limparHistorico", true) addEventHandler("JOAO.limparHistorico", root, function(player, grupo) dbExec(db, "DELETE FROM LogsGroup WHERE Grupo=?", grupo) dbExec(db, "INSERT INTO LogsGroup(Logs, Date, Grupo) VALUES(?,?,?)", exports["cuentapersonaje"]:getPlayerNameFromConta(getAccountName(getPlayerAccount(player))).."("..(getElementData(player, 'ID') or 0)..") limpou o histórico!", getRealTime().monthday.."/"..(getRealTime().month+(1)).."/"..(getRealTime().year+(1900)).." às "..getRealTime().hour..":"..getRealTime().minute, grupo) local resultarlogs = dbPoll(dbQuery(db, 'SELECT * FROM LogsGroup WHERE Grupo = ?', grupo), -1) triggerClientEvent(player, 'JOAO.resultLogsGroupC', player, resultarlogs) end) function AbrirPainel(thePlayer) local sql = dbPoll(dbQuery(db, "SELECT * FROM InfoGrupos WHERE Conta=?", getAccountName(getPlayerAccount(thePlayer))), -1) if #sql > 0 and sql[1].Cargo then local sqlgp = dbPoll(dbQuery(db, "SELECT * FROM Grupos WHERE Nome=?", sql[1].NomeGrupo), -1) sqlgp[1].NomeP = exports["cuentapersonaje"]:getPlayerNameFromConta(sqlgp[1].Lider) local rendas = dbPoll(dbQuery(db, "SELECT * FROM RendaGrupos WHERE NomeGrupo=?", sql[1].NomeGrupo), -1) sqlmembro = dbPoll(dbQuery(db, "SELECT * FROM InfoGrupos WHERE NomeGrupo=?", sql[1].NomeGrupo), -1) tablecalculo = {} for i,v in ipairs(sqlmembro) do if v.Cargo then tablecalculo[v.Conta] = fromJSON(v.InfosApreensoes).presos + fromJSON(v.InfosApreensoes).drogas + fromJSON(v.InfosApreensoes).armas else sqlmembro[i] = nil end end table.sort ( tablecalculo, function ( a, b ) return a > b end ) for i,v in pairs(tablecalculo) do sqlmembro2 = dbPoll(dbQuery(db, "SELECT * FROM InfoGrupos WHERE Conta=?", i), -1) sqlmembro2[1].NomeP = exports["cuentapersonaje"]:getPlayerNameFromConta(sqlmembro2[1].Conta) break end for i,v in pairs(sqlmembro) do sqlmembros = dbPoll(dbQuery(db, "SELECT * FROM InfoGrupos WHERE Conta=?", v.Conta), -1) v.Online = getAccountPlayer(getAccount(v.Conta)) v.NomeP = exports["cuentapersonaje"]:getPlayerNameFromConta(v.Conta) end triggerClientEvent(thePlayer, "MeloSCR:AbrirPainelGrupo", thePlayer, "home", sqlmembro, sqlgp[1], sqlmembro2[1], (sql[1].Cargo == "Lider" and true or false), rendas, getRealTime().timestamp) local resultarlogs = dbPoll(dbQuery(db, 'SELECT * FROM LogsGroup WHERE Grupo = ?', sqlgp[1].Nome), -1) triggerClientEvent(thePlayer, 'JOAO.resultLogsGroupC', thePlayer, resultarlogs) else grupos[thePlayer] = {} for i,v in ipairs(sql) do local sqlgp = dbPoll(dbQuery(db, "SELECT * FROM Grupos WHERE Nome=?", v.NomeGrupo), -1) if #sqlgp > 0 then sqlgp[1].NomeP = exports["cuentapersonaje"]:getPlayerNameFromConta(sqlgp[1].Lider) table.insert(grupos[thePlayer], sqlgp) end end triggerClientEvent(thePlayer, "MeloSCR:AbrirPainelGrupo", thePlayer, "convites", sql, grupos[thePlayer]) end end addEventHandler("onPlayerLogin", root, function () bindKey(source, config.BindAbrirNormal, 'down', AbrirPainel) end) notifyS = function (thePlayer, message, type) if config.Notify.export then call(getResourceFromName(config.Notify.nomescriptouevento), config.Notify.funcaoexport, thePlayer,message, type) else triggerEvent(config.Notify.nomescriptouevento, thePlayer, message, type) end end addEvent("MeloSCR:ConvidarMembroGrupo", true) addEventHandler("MeloSCR:ConvidarMembroGrupo", root, function (IDMembro, NomeGrupo) serial, conta = exports.vanish_id:getSerialByID(tonumber(IDMembro)) local sql1 = dbPoll(dbQuery(db, "SELECT * FROM InfoGrupos WHERE Conta=?", conta), -1) if #sql1 > 0 and sql1[1].Cargo then return notifyS(source, "Este jogador ja pertence a um grupo!", "error") end dbExec(db, "INSERT INTO InfoGrupos(Conta, NomeGrupo, Cargo, InfosApreensoes, Renda, UltimoLogin) VALUES(?,?,?,?,?,?)", conta, NomeGrupo, _, _, _, getRealTime().timestamp) notifyS(source, "Membro convidado com sucesso!", "success") end) addEvent("MeloSCR:ExpulsarMembroGrupo", true) addEventHandler("MeloSCR:ExpulsarMembroGrupo", root, function (conta, NomeGrupo) dbExec(db, "DELETE FROM InfoGrupos WHERE Conta=? AND NomeGrupo=?", conta, NomeGrupo) notifyS(source, "Membro expulso com sucesso!", "success") end) addEvent("MeloSCR:AceitarGrupo", true) addEventHandler("MeloSCR:AceitarGrupo", root, function (grupo) dbExec(db, "DELETE FROM InfoGrupos WHERE Conta=?", getAccountName(getPlayerAccount(source))) dbExec(db, "INSERT INTO InfoGrupos(Conta, NomeGrupo, Cargo, InfosApreensoes, Renda, UltimoLogin) VALUES(?,?,?,?,?,?)", getAccountName(getPlayerAccount(source)), grupo.Nome, "Recruta", toJSON({presos = 0, drogas = 0, armas = 0}), 0, getRealTime().timestamp) notifyS(source, "Você agora faz parte do: "..grupo.Nome.."!", "success") end) addEvent("MeloSCR:DepositarDinheiroGrupo", true) addEventHandler("MeloSCR:DepositarDinheiroGrupo", root, function (grupo, quantia) local sql = dbPoll(dbQuery(db, "SELECT * FROM Grupos WHERE Nome=?", grupo), -1) if #sql > 0 then if getPlayerMoney(source) >= quantia then takePlayerMoney(source, quantia) dbExec(db, "UPDATE Grupos SET Saldo=? WHERE Nome=?", sql[1].Saldo + quantia, grupo) else notifyS(source, "Você não tem dinheiro suficiente!", "error") end end end) addEvent("MeloSCR:SacarDinheiroGrupo", true) addEventHandler("MeloSCR:SacarDinheiroGrupo", root, function (grupo, quantia) local sql = dbPoll(dbQuery(db, "SELECT * FROM Grupos WHERE Nome=?", grupo), -1) if #sql > 0 then if sql[1].Saldo >= quantia then givePlayerMoney(source, quantia) dbExec(db, "UPDATE Grupos SET Saldo=? WHERE Nome=?", sql[1].Saldo - quantia, grupo) Edited June 11, 2022 by Vinyard Hiding personal information. Link to comment
Moderators Vinyard Posted June 11, 2022 Moderators Share Posted June 11, 2022 Moved to the Scripting section. Also removed any pesonal data from the post. 1 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