MRXBBC Posted September 11, 2019 Share Posted September 11, 2019 erro é esse local sql = dbConnect( 'sqlite', 'MrxSQL.db' ) addEventHandler("onResourceStart", resourceRoot, function() dbExec(sql, "CREATE TABLE IF NOT EXISTS dinheiroatm ( conta TEXT, quantidade INT )") for k, v in ipairs(getElementsByType("player")) do local accounts = getPlayerAccount ( v ) if not isGuestAccount(accounts) then local conta = getAccountName(accounts) local target = getPlayerFromAccountName(conta) local qh = dbQuery(sql, "SELECT quantidade FROM dinheiroatm WHERE conta=?", conta) local result = dbPoll(qh, -1) if #result ~= 0 then setElementData(target,"Mrx:moneyatm",result[1]["quantidade"]) else dbFree(dbQuery(sql, "INSERT INTO dinheiroatm ( conta, quantidade ) VALUES ( '"..conta.."', '0' )")) setElementData(target,"Mrx:moneyatm",0) end end end end ) addEventHandler("onPlayerLogin", root, function(_, theCurrentAccount) local conta = getAccountName(theCurrentAccount) local target = getPlayerFromAccountName(conta) if isElement(target) then local qh = dbQuery(sql, "SELECT * FROM dinheiroatm WHERE conta=?", conta) local result = dbPoll(qh, -1) if #result ~= 0 then setElementData(target,"Mrx:moneyatm",result[1]["quantidade"]) else dbFree(dbQuery(sql, "INSERT INTO dinheiroatm ( conta, quantidade ) VALUES ( '"..conta.."', '0' )")) setElementData(target,"Mrx:moneyatm",0) end end end ) addEventHandler("onPlayerQuit", root, function() local conta = getPlayerAccount(source) if not isGuestAccount(conta) then local qh = dbQuery(sql, "SELECT quantidade FROM dinheiroatm WHERE conta=?", getAccountName(conta)) local result = dbPoll(qh, -1) if #result ~= 0 then local money = getElementData(source,"Mrx:moneyatm") dbExec(sql, "UPDATE dinheiroatm SET quantidade=? WHERE conta=?", money, getAccountName(conta)) else dbFree(dbQuery(sql, "INSERT INTO dinheiroatm ( conta, quantidade ) VALUES ( '"..getAccountName(conta).."', 0 )")) end end end ) addEvent("Mrx:depositoatm", true) addEventHandler("Mrx:depositoatm", root, function (valor) local valor = tonumber(valor) if (not valor or valor == " " or valor == "" or (valor and (tostring(valor):sub(1,1) == "-"))) then return end if not isGuestAccount(getPlayerAccount(source)) then if tonumber(getPlayerMoney(source)) >= valor then local money = getElementData(source,"Mrx:moneyatm") or 0 setElementData(source, "Mrx:moneyatm", money + valor) takePlayerMoney ( source, valor ) else outputChatBox("#7cc576[BANCO]#FFFFFF Você não possui essa quantidade para depositar.", source, 255, 0, 0,true) end end end ) addEvent("Mrx:saqueoatm", true) addEventHandler("Mrx:saqueoatm", root, function (valor) local valor = tonumber(valor) if (not valor or valor == " " or valor == "" or (valor and (tostring(valor):sub(1,1) == "-"))) then return end if not isGuestAccount(getPlayerAccount(source)) then if tonumber(getElementData(source,"Mrx:moneyatm")) >= tonumber(valor) then local money = getElementData(source,"Mrx:moneyatm") or 0 setElementData(source, "Mrx:moneyatm", money - valor) givePlayerMoney(source, valor) else outputChatBox("#7cc576[BANCO]#FFFFFF Você não possui essa quantidade para sacar.", source, 255, 0, 0,true) end end end ) addEvent("Mrx:transfere", true) addEventHandler("Mrx:transfere", root, function (valor, name) local valor = tonumber(valor) if (not valor or valor == " " or valor == "" or (valor and (tostring(valor):sub(1,1) == "-"))) then return end if name then target = getPlayerFromPartialName(name) if target == false or target == nil then outputChatBox("#7cc576[BANCO]#FFFFFF Jogador não localizado.", source, 255, 255, 255, true) return end if not isGuestAccount(getPlayerAccount(source)) then if (source) ~= (target) then if tonumber(getElementData(source,"Mrx:moneyatm")) >= (valor) then local money = getElementData(source,"Mrx:moneyatm") or 0 local quant = getElementData(target,"Mrx:moneyatm") or 0 setElementData(source, "Mrx:moneyatm", money - valor) setElementData(target, "Mrx:moneyatm", quant + valor) outputChatBox("#7cc576[BANCO]#FFFFFF O jogador "..getPlayerName(source).."#FFFFFF transferiu para sua conta $"..convertNumber(valor)..".", target, 255, 255, 255, true) outputChatBox("#7cc576[BANCO]#FFFFFF Você transferiu $"..convertNumber(valor).."#FFFFFF para a conta do jogador "..getPlayerName(target).."#FFFFFF.", source, 255, 255, 255, true) else outputChatBox("#7cc576[BANCO]#FFFFFF Você não possui essa quantidade para transferir.", source, 255, 0, 0,true) end end end end end ) function convertNumber ( number ) local formatted = number while true do formatted, k = string.gsub(formatted, "^(-?%d+)(%d%d%d)", '%1,%2') if ( k==0 ) then break end end return formatted end addEventHandler("onPlayerLogout", root, function() setElementData(source,"Mrx:moneyatm",0) end ) function getPlayerFromPartialName(name) local name = name and name:gsub("#%x%x%x%x%x%x", ""):lower() or nil if name then for _, player in ipairs(getElementsByType("player")) do local name_ = getPlayerName(player):gsub("#%x%x%x%x%x%x", ""):lower() if name_:find(name, 1, true) then return player end end end end function getPlayerFromAccountName(name) local acc = getAccount (name) if name and acc and not isGuestAccount (acc) then return getAccountPlayer (acc) else return false end end Link to comment
Furzy Posted September 12, 2019 Share Posted September 12, 2019 Ta dizendo que sua db ta trancada, tenta excluir ela Link to comment
Other Languages Moderators Lord Henry Posted September 12, 2019 Other Languages Moderators Share Posted September 12, 2019 Faça a conexão ser global em vez de local e coloque ela junto do onResourceStart. Dessa forma: addEventHandler("onResourceStart", resourceRoot, function() sql = dbConnect( "sqlite", "MrxSQL.db" ) dbExec(sql, "CREATE TABLE IF NOT EXISTS dinheiroatm ( conta TEXT, quantidade INT )") for k, v in ipairs(getElementsByType("player")) do local accounts = getPlayerAccount ( v ) if not isGuestAccount(accounts) then local conta = getAccountName(accounts) local target = getPlayerFromAccountName(conta) local qh = dbQuery(sql, "SELECT quantidade FROM dinheiroatm WHERE conta=?", conta) local result = dbPoll(qh, -1) if #result ~= 0 then setElementData(target,"Mrx:moneyatm",result[1]["quantidade"]) else dbFree(dbQuery(sql, "INSERT INTO dinheiroatm ( conta, quantidade ) VALUES ( '"..conta.."', '0' )")) setElementData(target,"Mrx:moneyatm",0) end end end end ) addEventHandler("onPlayerLogin", root, function(_, theCurrentAccount) local conta = getAccountName(theCurrentAccount) local target = getPlayerFromAccountName(conta) if isElement(target) then local qh = dbQuery(sql, "SELECT * FROM dinheiroatm WHERE conta=?", conta) local result = dbPoll(qh, -1) if #result ~= 0 then setElementData(target,"Mrx:moneyatm",result[1]["quantidade"]) else dbFree(dbQuery(sql, "INSERT INTO dinheiroatm ( conta, quantidade ) VALUES ( '"..conta.."', '0' )")) setElementData(target,"Mrx:moneyatm",0) end end end ) addEventHandler("onPlayerQuit", root, function() local conta = getPlayerAccount(source) if not isGuestAccount(conta) then local qh = dbQuery(sql, "SELECT quantidade FROM dinheiroatm WHERE conta=?", getAccountName(conta)) local result = dbPoll(qh, -1) if #result ~= 0 then local money = getElementData(source,"Mrx:moneyatm") dbExec(sql, "UPDATE dinheiroatm SET quantidade=? WHERE conta=?", money, getAccountName(conta)) else dbFree(dbQuery(sql, "INSERT INTO dinheiroatm ( conta, quantidade ) VALUES ( '"..getAccountName(conta).."', 0 )")) end end end ) addEvent("Mrx:depositoatm", true) addEventHandler("Mrx:depositoatm", root, function (valor) local valor = tonumber(valor) if (not valor or valor == " " or valor == "" or (valor and (tostring(valor):sub(1,1) == "-"))) then return end if not isGuestAccount(getPlayerAccount(source)) then if tonumber(getPlayerMoney(source)) >= valor then local money = getElementData(source,"Mrx:moneyatm") or 0 setElementData(source, "Mrx:moneyatm", money + valor) takePlayerMoney ( source, valor ) else outputChatBox("#7cc576[BANCO]#FFFFFF Você não possui essa quantidade para depositar.", source, 255, 0, 0,true) end end end ) addEvent("Mrx:saqueoatm", true) addEventHandler("Mrx:saqueoatm", root, function (valor) local valor = tonumber(valor) if (not valor or valor == " " or valor == "" or (valor and (tostring(valor):sub(1,1) == "-"))) then return end if not isGuestAccount(getPlayerAccount(source)) then if tonumber(getElementData(source,"Mrx:moneyatm")) >= tonumber(valor) then local money = getElementData(source,"Mrx:moneyatm") or 0 setElementData(source, "Mrx:moneyatm", money - valor) givePlayerMoney(source, valor) else outputChatBox("#7cc576[BANCO]#FFFFFF Você não possui essa quantidade para sacar.", source, 255, 0, 0,true) end end end ) addEvent("Mrx:transfere", true) addEventHandler("Mrx:transfere", root, function (valor, name) local valor = tonumber(valor) if (not valor or valor == " " or valor == "" or (valor and (tostring(valor):sub(1,1) == "-"))) then return end if name then target = getPlayerFromPartialName(name) if target == false or target == nil then outputChatBox("#7cc576[BANCO]#FFFFFF Jogador não localizado.", source, 255, 255, 255, true) return end if not isGuestAccount(getPlayerAccount(source)) then if (source) ~= (target) then if tonumber(getElementData(source,"Mrx:moneyatm")) >= (valor) then local money = getElementData(source,"Mrx:moneyatm") or 0 local quant = getElementData(target,"Mrx:moneyatm") or 0 setElementData(source, "Mrx:moneyatm", money - valor) setElementData(target, "Mrx:moneyatm", quant + valor) outputChatBox("#7cc576[BANCO]#FFFFFF O jogador "..getPlayerName(source).."#FFFFFF transferiu para sua conta $"..convertNumber(valor)..".", target, 255, 255, 255, true) outputChatBox("#7cc576[BANCO]#FFFFFF Você transferiu $"..convertNumber(valor).."#FFFFFF para a conta do jogador "..getPlayerName(target).."#FFFFFF.", source, 255, 255, 255, true) else outputChatBox("#7cc576[BANCO]#FFFFFF Você não possui essa quantidade para transferir.", source, 255, 0, 0,true) end end end end end ) function convertNumber ( number ) local formatted = number while true do formatted, k = string.gsub(formatted, "^(-?%d+)(%d%d%d)", '%1,%2') if ( k==0 ) then break end end return formatted end addEventHandler("onPlayerLogout", root, function() setElementData(source,"Mrx:moneyatm",0) end ) function getPlayerFromPartialName(name) local name = name and name:gsub("#%x%x%x%x%x%x", ""):lower() or nil if name then for _, player in ipairs(getElementsByType("player")) do local name_ = getPlayerName(player):gsub("#%x%x%x%x%x%x", ""):lower() if name_:find(name, 1, true) then return player end end end end function getPlayerFromAccountName(name) local acc = getAccount (name) if name and acc and not isGuestAccount (acc) then return getAccountPlayer (acc) else return false end end 1 Link to comment
DNL291 Posted September 12, 2019 Share Posted September 12, 2019 O recomendado é você deixar a dbConect ativa uma vez que o resource iniciar, e exportar as funções dbQuery e dbExec e chamar as funções com a função exportada, sem ficar sempre fazendo a conexão na database antes. 1 Link to comment
MRXBBC Posted September 14, 2019 Author Share Posted September 14, 2019 Muito obrigado 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