Jump to content

AJUDA COM BANCO DE DADOS


Recommended Posts

º Estou ajustando uma concessionaria , consegui fazer a tabela coletar os dados de tunagem.spacer.png

º Para Setar os Dados Estou usando a função abaixo:

 

function setDadosVeh (carro, table)
 	
	for _, upgrades in ipairs(table.Tunagem) do
		addVehicleUpgrade(carro, tonumber(upgrades))
	end

end


º Ai Chamo ela na Garagem a hora que vai spawnar o veiculo no exemplo abaixo:

 

local table = fromJSON(result[1]['Tunagem'])
setDadosVeh(carro, table)		
			


º Se eu guarda o veiculo tunado ela funciona perfeitamente, agora quando eu compro um veiculo direto da loja que vai pra garagem sem tunning a hora que eu vou tirar, ele da o seguinte erro abaixo:

spacer.png

º Segue exemplo de como fica o carro na tabela Supra Guardado Tunado e o Honda Comprado sem Tunning.
cYTHzte.png

º Teria alguma maneira de eu setar algum valor na hora da compra do veiculo para ele vir com alguma tunagem aleatoria ou cria uma verificação para que, ele nao use o setDados quando veiculo nao tiver valores de tunagem ?


Segue o codigo completo Abaixo:

 

addEventHandler ("onResourceStart", resourceRoot,
function ()
    db = dbConnect ("sqlite", "veiculos.sqlite")
    dbExec (db, "CREATE TABLE IF NOT EXISTS player (Login, Veiculo, Modelo, Gas, Saude, Status, R, G, B, Valor, Placa, Multas, Wheels, Tunagem TEXT)")
    if db then
        print("[Concessionaria] - Banco de dados conectado com sucesso")
    else
        print("[Concessionaria] - Erro ao conectar no banco de dados!")
    end
 
    dbExec(db, "UPDATE player SET Status = ? WHERE Status = ?", "Guardado", "Em Rua")
 
end)
 
local teclas = {"a", "b", "c", "d", "e", "f", "g", "h", "i" , "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "1", "2", "3", "4", "5", "6", "7", "8", "9"}
 
function generatePlate (len)
    if type(len) == "number" and len >= 1 then
        String = ""
        n = 0
        while true do
            n = n + 1
            local random = math.random(1, #teclas)
            if #String == 4 then
                String = String
            end
            String = String..""..string.upper(teclas[random])..""
            if n == len then
                break
            end
        end
    end
    return String
end
 
function getFreePlate ()
    Placa = false
    local veiculos = dbPoll(dbQuery(db, "SELECT * FROM player"), -1)
    while true do
        local plate = generatePlate (9)
        local result = dbPoll(dbQuery(db, "SELECT * FROM player WHERE Placa = ?", plate), -1)
        if #result == 0 then
            Placa = plate
            break
        end
    end
    return Placa
end


 
function opendetran (source)
if getElementType(source) == "player" then
if not isPedInVehicle(source) then
    triggerClientEvent(source, "H3>OpenDETRAN", root)
end
end
end
 
for i,v in ipairs(Config["Detran"]["MarkerRetirar"]) do
    marker = exports["PlayNow_markers"]:createMarker("doc",Vector3(v[1], v[2], v[3]-0.9),0)
    --marker = createMarker(v[1], v[2], v[3]-1, "cylinder", 1.5, Config.colormarker[1][1], Config.colormarker[1][2],Config.colormarker[1][3], 90)
    addEventHandler("onMarkerHit", marker, opendetran)
end
 
function openconce (source)
    if getElementType(source) == "player" then
        if not isPedInVehicle(source) then
            triggerClientEvent(source, "H3>OpenCONCE", resourceRoot)
        end
    end
end
 
for i,v in ipairs (Config["Concessionarias"]) do
    marker = exports["PlayNow_markers"]:createMarker("carshop",Vector3(v.x, v.y, v.z-0.9),0)
    blip = createBlipAttachedTo(marker, 55)
    setElementData(blip, "blipName", "Concessionaria")
    --marker = createMarker(v.x, v.y, v.z -1, "cylinder", 1.5, Config.colormarker[1][1], Config.colormarker[1][2],Config.colormarker[1][3], 90)
    addEventHandler("onMarkerHit", marker, openconce)
 
end
 
function openapreender (source)
    if getElementType(source) == "player" then
    if isPedInVehicle(source) then
        --print(Config["Detran"].ACL[1][1])
        local accName = getAccountName ( getPlayerAccount ( source ) )
        if isObjectInACLGroup("user."..accName, aclGetGroup(Config["Detran"].ACL[1][1])) then
            triggerClientEvent(source, "H3>OpenDETRAN1", root)
        else
            addNotification(source, "Apenas DETRANS podem rebocar veiculos!", 'error')
        end
    else
        addNotification(source, "Você precisa estar em um veiculo para rebocar!", 'error')
    end
    end
end
 
for i,v in ipairs(Config["Detran"]["MarkerApreender"]) do
    marker = exports["PlayNow_markers"]:createMarker("detran",Vector3(v[1], v[2], v[3]-0.9),0)
    addEventHandler("onMarkerHit", marker, openapreender)
end
 
function opengaragem (source)
if getElementType(source) == "player" then
if not isPedInVehicle(source) then
    triggerClientEvent(source, "H3>OpenGARAGEM", resourceRoot)
else
    local carro = getPedOccupiedVehicle(source)
    if getElementData(carro, "Owner") == getElementData(source, "ID") then
        triggerClientEvent(source, "H3>OpenGARAGEM2", resourceRoot)
    else
        addNotification(source, "Esse veiculo não é seu!", 'error')
       
    end
end
end
end
 
for i,v in ipairs (Config["Garagens"]) do
    marker = exports["PlayNow_markers"]:createMarker("garagem",Vector3(v[1], v[2], v[3]-0.9),0)
    addEventHandler("onMarkerHit", marker, opengaragem)
    blip = createBlipAttachedTo(marker, 35)
end
 
function passarInfoGaragem (source)
    if getElementType(source) == "player" then
        local result = dbPoll(dbQuery(db, "SELECT * FROM player"), -1)
        local conce = {}
        if (#result > 0) then
            for _, v in ipairs(result) do
                if v["Login"] == getAccountName(getPlayerAccount(source)) and #v["Login"] > 0 then
                    local dono = v["Login"]
                    local modelo = v["Modelo"]
                    local nomeveiculo = v["Veiculo"]
                    local status = v["Status"]
                    table.insert(conce, {Owner = dono, Model = modelo, Veiculo = nomeveiculo, Estado = status })
                   
                end
            end
        end
        if (#conce > 0) then
            triggerClientEvent(source, "H3>ShowGRID", root, conce)
        else
            return false
        end
    end
end
addEvent("H3>TransferInfo", true)
addEventHandler("H3>TransferInfo", resourceRoot, passarInfoGaragem)
 
function passarInfoDetran (source)
    if getElementType(source) == "player" then
        local result = dbPoll(dbQuery(db, "SELECT * FROM player"), -1)
        local conce = {}
        if (#result > 0) then
            for _, v in ipairs(result) do
                if v["Login"] == getAccountName(getPlayerAccount(source)) and #v["Login"] > 0 then
                    local dono = v["Login"]
                    local modelo = v["Modelo"]
                    local nomeveiculo = v["Veiculo"]
                    local status = v["Status"]
                    local valor = v["Valor"]
                    local multas = v["Multas"]
                    local Wheels = v["Wheels"]
                    table.insert(conce, {Owner = dono, Model = modelo, Veiculo = nomeveiculo, Estado = status, Preco = valor, multas = Multas, Wheels = Wheels, })
                end
            end
        end
        if (#conce > 0) then
            triggerClientEvent(source, "H3>ShowGRIDD", root, conce)
        else
            return false
        end
    end
end
addEvent("H3>TransferInfo2", true)
addEventHandler("H3>TransferInfo2", resourceRoot, passarInfoDetran)
 
function buyVehicle (player, modelo, tipo, preco, nome, r, g, b)
    local accName = getAccountName(getPlayerAccount(player))
    local checarcarro = dbPoll(dbQuery(db, "SELECT * FROM player WHERE Login = ? AND Modelo = ?", accName, tonumber(modelo)),-1)
    if #checarcarro == 0 then
        if tipo == "Money" then
            if getPlayerMoney(player) >= preco then
                dbExec (db, "INSERT INTO player VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?,?,10000)", accName, nome, modelo, 100, 1000, "Guardado", r, g, b,  tonumber(preco), getFreePlate(),  0)
                takePlayerMoney(player, preco)
 
                addNotification(player,  "Veiculo comprado com sucesso!", 'success')
                setElementPosition(player, 1099.566, -1790.223, 13.605)
            else
                addNotification(player, "Você não possui dinheiro suficiente!", 'error')
                setElementPosition(player, 1099.566, -1790.223, 13.605)
            end
        elseif tipo == "Pontos" then
            if getElementData(player, Config.ELEMENTPV) >= preco then
                local pontos = getElementData(player, ELEMENTPV) or 0
                dbExec (db, "INSERT INTO player VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?,?,?)", accName, nome, modelo, 100, 1000, "Guardado", r, g, b, tonumber(preco), getFreePlate(), 0)
                setElementData(player, ELEMENTPV, pontos - preco)
                addNotification(player, "Veiculo comprado com sucesso!", 'success')
                setElementPosition(player, 1099.566, -1790.223, 13.605)
            else
                addNotification(player,  "Você não possui pontos suficiente!", 'error')
                setElementPosition(player, 1099.566, -1790.223, 13.605)
            end
        end
    else
        addNotification(player, "Você já possui este veiculo.", 'info')
        setElementPosition(player, 1099.566, -1790.223, 13.605)
    end
end
addEvent("H3:ComprarVeiculo", true)
addEventHandler("H3:ComprarVeiculo", root, buyVehicle)
 
function tirarveiculo (player, veiculo)
local id = getElementData(player, "ID")
local accName = getAccountName(getPlayerAccount(player))
local x, y, z = getElementPosition( player )
local result = dbPoll(dbQuery(db, "SELECT * FROM player WHERE Login = ? AND Veiculo = ?", accName, tostring(veiculo)), -1)
 
if (#result ~= 0 and type(result) == 'table') then
        if result[1]["Status"] == "Guardado" then
            if result[1]["Status"] == "Detran" then return addNotification(player, "Você não pode tirar um veiculo que está no DETRAN!", 'error') end
            local carro = createVehicle( result[1]["Modelo"], x, y, z , 0, 0, 0, result[1]["Placa"])
            setElementHealth(carro, result[1]["Saude"])
            setElementData(carro, "Owner", id)
            setElementData(carro, "Nome", result[1]["Veiculo"])
            setVehicleColor(carro, result[1]["R"], result[1]["G"], result[1]["B"], result[1]["R"], result[1]["G"], result[1]["B"])
            setElementData(carro, "fuel", result[1]["Gas"])
            setElementData(carro, "Multas", result[1]["Multas"])
            setVehicleWheelStates(carro, result[1]["Wheels"])
            local table = fromJSON(result[1]['Tunagem'])
            setDadosVeh(carro, table[1])        
           
               
           
               
                warpPedIntoVehicle(player, carro)
                dbExec(db, "UPDATE player SET Status = ? WHERE Login = ? AND Veiculo = ?", "Em Rua", accName, tostring(veiculo))
                setVehiclePlateText(carro, result[1]["Placa"])
            end
        end
    end
 
addEvent("H3>TirarVeiculo", true)
addEventHandler("H3>TirarVeiculo", root, tirarveiculo)
 
function guardarveiculo (player, carro)
   
local id = getElementData(player, "ID")
local accName = getAccountName(getPlayerAccount(player))
local carro = getPedOccupiedVehicle(player)
local up1 = addVehicleUpgrade(carro, 1028)
local nomecarro = getElementData(carro, "Nome")
local donocarro = getElementData(carro, "Owner")
local saude = getElementHealth(carro)
local gasolina = getElementData(carro, "fuel") or 0
local multas = getElementData(carro, "Multas") or 0
local Wheels = getVehicleWheelStates(carro) or 0
local Tunagem = getVehicleUpgrades(carro)
local r1, g1, b1, r2, g2, b2, r3, g3, b3 = getVehicleColor(carro, true)
local result = dbPoll(dbQuery(db, "SELECT * FROM player WHERE Login = ? AND Veiculo = ?", accName, nomecarro), -1)
if isElement(carro) and (getElementType(carro) == 'vehicle') then
dados_veh = {  Tunagem = getVehicleUpgrades(carro)}
if donocarro == id then
    if #result > 0 then
        if result[1]["Status"] == "Em Rua" then
            dbExec(db, "UPDATE player SET Status = ? WHERE Login = ? AND Veiculo = ?", "Guardado", accName, nomecarro)
            dbExec(db, "UPDATE player SET Saude = ? WHERE Login = ? AND Veiculo = ?", saude, accName, nomecarro)
            dbExec(db, "UPDATE player SET R = ? WHERE Login = ? AND Veiculo = ?", r1, accName, nomecarro)
            dbExec(db, "UPDATE player SET G = ? WHERE Login = ? AND Veiculo = ?", g1, accName, nomecarro)
            dbExec(db, "UPDATE player SET B = ? WHERE Login = ? AND Veiculo = ?", b1, accName, nomecarro)
            dbExec(db, "UPDATE player SET Gas = ? WHERE Login = ? AND Veiculo = ?", gasolina, accName, nomecarro)
            dbExec(db, "UPDATE player SET Multas = ? WHERE Login = ? AND Veiculo = ?", multas, accName, nomecarro)
            dbExec(db, "UPDATE player SET Wheels= ? WHERE Login = ? AND Veiculo = ?", Wheels, accName, nomecarro)
            dbExec(db, "UPDATE player SET Tunagem = ? WHERE Login = ? AND Veiculo = ?", toJSON({dados_veh}),  accName, nomecarro)
            destroyElement(carro)
            addNotification(player, "Você guardou seu veiculo!", 'success')
           
            end
        end
    end
end
end
addEvent("H3>GuardarVeiculo", true)
addEventHandler("H3>GuardarVeiculo", root, guardarveiculo)
 
function fmultar (player, cmd, placa, valor)
local result = dbPoll(dbQuery(db, "SELECT * FROM player WHERE Placa = ?", tostring(placa)), -1)
if placa then
    if valor then
        if #result > 0 then
            local veiculo = getVehicleFromPlate(placa)
            local multas = getElementData(veiculo, "Multas")
            takePlayerMoney(player, tonumber(valor))
            local donodocarro = getPlayerFromAccountName(result[1]["Login"])
            addNotification(donodocarro, "O seu "..result[1]["Veiculo"].. " foi multado por R$"..tostring(valor), 'info')
        else
            addNotification(player, "Veiculo não encontrado!", 'error')
        end
    end
end
end
addCommandHandler("multar", fmultar)
 
function apreender (player)
local veiculo = getPedOccupiedVehicle(player)
local nome = getElementData(veiculo, "Nome")
local dono = getElementData(veiculo, "Owner")
local placa = getVehiclePlateText(veiculo)
    if isPedInVehicle(player) then
        local result = dbPoll(dbQuery(db, "SELECT * FROM player WHERE Placa = ? AND Veiculo = ? ", tostring(placa), nome), -1)
        if #result > 0 then
            dbExec(db, "UPDATE player SET Status = ? WHERE Placa = ? AND Veiculo = ?", "Detran", tostring(placa), nome)
            destroyElement(veiculo)
            end
        end
    end
addEvent("H3>Apreender", true)
addEventHandler("H3>Apreender", root, apreender)
 
function tirardetran (player, veiculo, valor)
local money = getPlayerMoney(player)
local accName = getAccountName(getPlayerAccount(player))
local result = dbPoll(dbQuery(db, "SELECT * FROM player WHERE Veiculo = ? AND Login = ?", tostring(veiculo), accName), -1)
if money >= tonumber(valor) then
    if #result > 0 then
        takePlayerMoney(player, tonumber(valor))
        dbExec(db, "UPDATE player SET Status = ? WHERE Veiculo = ? AND Login = ?", "Guardado", tostring(veiculo), accName)
        addNotification(player, "Você retirou seu veiculo do DETRAN com sucesso!", 'success')
    end
else
    addNotification(player, "Dinheiro insuficiente!", 'error')
end
end
addEvent("H3>TirarDETRAN", true)
addEventHandler("H3>TirarDETRAN", root, tirardetran)
 
--  local donodocarro = getPlayerFromAccountName(result[1]["Login"])
--  addNotification(donodocarro, "O seu "..result[1]["Veiculo"].. " foi multado por R$"..tostring(valor))
--
--
--function elementClicked( theButton, theState, thePlayer )
    --if theButton == "left" and theState == "down" then -- if left mouse button was pressed down
        --outputChatBox( "You clicked " .. getElementType( source ), thePlayer ) -- print the element type to players chatbox
   -- end
--end
--addEventHandler( "onElementClicked", root, elementClicked ) -- add a handler function for the event
 
addEventHandler("onElementClicked", root, function(button, state, jogador)
local x,y,z = getElementPosition(jogador)
local x2, y2, z2 = getElementPosition(source)
if getDistanceBetweenPoints3D(x, y, z, x2, y2, z2) <= 3 then
if not isPedInVehicle(jogador) then
    if button == "left" and state == "down" then
        if getElementType(source) == "vehicle" then
            if getElementData(source, "Owner") == getElementData(jogador, "ID") then
                triggerClientEvent(jogador, "H3>OpenDXFORAVEICULO", root, source, true)
            else
                triggerClientEvent(jogador, "H3>OpenDXFORAVEICULO", root, source, false)
            end
        end
    end
else
    if button == "left" and state == "down" then
        if getPedOccupiedVehicleSeat (jogador) == 0 then
        if getElementType(source) == "vehicle" then
            if getVehicleType(source) == "BMX" then return end
            if getElementData(source, "Owner") == getElementData(jogador, "ID") then
                triggerClientEvent(jogador, "H3>OpenDXDENTROVEICULO", root, source, true)
            else
                triggerClientEvent(jogador, "H3>OpenDXDENTROVEICULO", root, source, false)
            end
        end
        end
    end
end
end
end)
 
addEventHandler("onVehicleStartEnter", root, function(player)
    triggerClientEvent(player, "H3>CloseDXFORAVEICULO", root)
end)
 
addEventHandler("onVehicleEnter", root, function()
    if getVehicleType(source) == "BMX" then return end
        setVehicleEngineState(source, false)
end)
 
addEventHandler("onVehicleExit", root, function(player)
    triggerClientEvent(player, "H3>CloseDXDENTROVEICULO", root)
end)
 
addEvent("H3>StartVehicle", true)
addEventHandler("H3>StartVehicle", root, function(element)
    setVehicleEngineState(element, not getVehicleEngineState(element))
end)
 
addEvent("H3>CloseAndOpenVehicle", true)
addEventHandler("H3>CloseAndOpenVehicle", root, function(jogador, veiculo)
local x,y,z = getElementPosition(jogador)
    if getElementData(veiculo, "Owner") == getElementData(jogador, "ID") then
        if not isVehicleLocked(veiculo) then
            setVehicleLocked(veiculo, true)
            addNotification(jogador, "Veiculo trancado!", 'success' )
            triggerClientEvent(jogador, "playSound3D", root, "veh-lock.mp3", x, y, z)
            setPedAnimation(jogador, "SHOP", "ROB_Loop_Threat", true, false, false, false, 0, false)
            setTimer(function()
                setPedAnimation(jogador)
            end, 500, 1)
        else
            setVehicleLocked(veiculo, false)
            addNotification(jogador, "Veiculo destrancado!", 'error')
            setPedAnimation(jogador, "SHOP", "ROB_Loop_Threat", true, false, false, false, 0, false)
            triggerClientEvent(jogador, "playSound3D", root, "veh-lock.mp3", x, y, z)
            setTimer(function()
                setPedAnimation(jogador)
            end, 500, 1)
        end
    end
end)
 
function getPlayerFromAccountName(name)
    local acc = getAccount(name)
    if not acc or isGuestAccount(acc) then
        return false
    end
    return getAccountPlayer(acc)
end
 
function getVehicleFromPlate (plate)
    for _, v in ipairs(getElementsByType("vehicle")) do
    local placa = getVehiclePlateText(v)
        if placa == plate then
            return v
        end
    end
end


 
addEvent("H3>StartVehicle", false)
addEventHandler("H3>StartVehicle", root, function(element)
    if (getElementHealth (element) <= 351) then
        setVehicleEngineState(source, false)
        addNotification(source, "Seu veiculo quebrou, chame um mecanico", 'info')
    end
end)
 
addEvent("H3>StartVehicle", false)
addEventHandler("H3>StartVehicle", root, function(element)
    local gasolina = (tonumber (getElementData (element, 'fuel') ) or 0)
    if (gasolina <= 0) then
        addNotification(source, "Seu veiculo ficou sem gasolina", 'info')
        setVehicleEngineState(source, false)
    end
end)
 
function addNotification(playerSource, type, message)
    triggerClientEvent (playerSource, 'addBox', playerSource, type, message)
end
function setDadosVeh (carro, table)
   
    for _, upgrades in ipairs(table.Tunagem) do
        addVehicleUpgrade(carro, tonumber(upgrades))
    end
 
end
Edited by Trinityz
Link to comment
On 03/07/2022 at 19:38, Trinityz said:

º Estou ajustando uma concessionaria , consegui fazer a tabela coletar os dados de tunagem.

º Para Setar os Dados Estou usando a função abaixo:
 


function setDadosVeh (carro, table)
 	
	for _, upgrades in ipairs(table.Tunagem) do
		addVehicleUpgrade(carro, tonumber(upgrades))
	end

end



 


º Ai Chamo ela na Garagem a hora que vai spawnar o veiculo no exemplo abaixo:

 


local table = fromJSON(result[1]['Tunagem'])
setDadosVeh(carro, table)		
			


º Se eu guarda o veiculo tunado ela funciona perfeitamente, agora quando eu compro um veiculo direto da loja que vai pra garagem sem tunning a hora que eu vou tirar, ele da o seguinte erro abaixo:

spacer.png

º Segue exemplo de como fica o carro na tabela Supra Guardado Tunado e o Honda Comprado sem Tunning.
cYTHzte.png

º Teria alguma maneira de eu setar algum valor na hora da compra do veiculo para ele vir com alguma tunagem aleatoria ou cria uma verificação para que, ele nao use o setDados quando veiculo nao tiver valores de tunagem ?


Segue o codigo completo Abaixo:

 

addEventHandler ("onResourceStart", resourceRoot,
function ()
    db = dbConnect ("sqlite", "veiculos.sqlite")
    dbExec (db, "CREATE TABLE IF NOT EXISTS player (Login, Veiculo, Modelo, Gas, Saude, Status, R, G, B, Valor, Placa, Multas, Wheels, Tunagem TEXT)")
    if db then
        print("[Concessionaria] - Banco de dados conectado com sucesso")
    else
        print("[Concessionaria] - Erro ao conectar no banco de dados!")
    end
 
    dbExec(db, "UPDATE player SET Status = ? WHERE Status = ?", "Guardado", "Em Rua")
 
end)
 
local teclas = {"a", "b", "c", "d", "e", "f", "g", "h", "i" , "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "1", "2", "3", "4", "5", "6", "7", "8", "9"}
 
function generatePlate (len)
    if type(len) == "number" and len >= 1 then
        String = ""
        n = 0
        while true do
            n = n + 1
            local random = math.random(1, #teclas)
            if #String == 4 then
                String = String
            end
            String = String..""..string.upper(teclas[random])..""
            if n == len then
                break
            end
        end
    end
    return String
end
 
function getFreePlate ()
    Placa = false
    local veiculos = dbPoll(dbQuery(db, "SELECT * FROM player"), -1)
    while true do
        local plate = generatePlate (9)
        local result = dbPoll(dbQuery(db, "SELECT * FROM player WHERE Placa = ?", plate), -1)
        if #result == 0 then
            Placa = plate
            break
        end
    end
    return Placa
end


 
function opendetran (source)
if getElementType(source) == "player" then
if not isPedInVehicle(source) then
    triggerClientEvent(source, "H3>OpenDETRAN", root)
end
end
end
 
for i,v in ipairs(Config["Detran"]["MarkerRetirar"]) do
    marker = exports["PlayNow_markers"]:createMarker("doc",Vector3(v[1], v[2], v[3]-0.9),0)
    --marker = createMarker(v[1], v[2], v[3]-1, "cylinder", 1.5, Config.colormarker[1][1], Config.colormarker[1][2],Config.colormarker[1][3], 90)
    addEventHandler("onMarkerHit", marker, opendetran)
end
 
function openconce (source)
    if getElementType(source) == "player" then
        if not isPedInVehicle(source) then
            triggerClientEvent(source, "H3>OpenCONCE", resourceRoot)
        end
    end
end
 
for i,v in ipairs (Config["Concessionarias"]) do
    marker = exports["PlayNow_markers"]:createMarker("carshop",Vector3(v.x, v.y, v.z-0.9),0)
    blip = createBlipAttachedTo(marker, 55)
    setElementData(blip, "blipName", "Concessionaria")
    --marker = createMarker(v.x, v.y, v.z -1, "cylinder", 1.5, Config.colormarker[1][1], Config.colormarker[1][2],Config.colormarker[1][3], 90)
    addEventHandler("onMarkerHit", marker, openconce)
 
end
 
function openapreender (source)
    if getElementType(source) == "player" then
    if isPedInVehicle(source) then
        --print(Config["Detran"].ACL[1][1])
        local accName = getAccountName ( getPlayerAccount ( source ) )
        if isObjectInACLGroup("user."..accName, aclGetGroup(Config["Detran"].ACL[1][1])) then
            triggerClientEvent(source, "H3>OpenDETRAN1", root)
        else
            addNotification(source, "Apenas DETRANS podem rebocar veiculos!", 'error')
        end
    else
        addNotification(source, "Você precisa estar em um veiculo para rebocar!", 'error')
    end
    end
end
 
for i,v in ipairs(Config["Detran"]["MarkerApreender"]) do
    marker = exports["PlayNow_markers"]:createMarker("detran",Vector3(v[1], v[2], v[3]-0.9),0)
    addEventHandler("onMarkerHit", marker, openapreender)
end
 
function opengaragem (source)
if getElementType(source) == "player" then
if not isPedInVehicle(source) then
    triggerClientEvent(source, "H3>OpenGARAGEM", resourceRoot)
else
    local carro = getPedOccupiedVehicle(source)
    if getElementData(carro, "Owner") == getElementData(source, "ID") then
        triggerClientEvent(source, "H3>OpenGARAGEM2", resourceRoot)
    else
        addNotification(source, "Esse veiculo não é seu!", 'error')
       
    end
end
end
end
 
for i,v in ipairs (Config["Garagens"]) do
    marker = exports["PlayNow_markers"]:createMarker("garagem",Vector3(v[1], v[2], v[3]-0.9),0)
    addEventHandler("onMarkerHit", marker, opengaragem)
    blip = createBlipAttachedTo(marker, 35)
end
 
function passarInfoGaragem (source)
    if getElementType(source) == "player" then
        local result = dbPoll(dbQuery(db, "SELECT * FROM player"), -1)
        local conce = {}
        if (#result > 0) then
            for _, v in ipairs(result) do
                if v["Login"] == getAccountName(getPlayerAccount(source)) and #v["Login"] > 0 then
                    local dono = v["Login"]
                    local modelo = v["Modelo"]
                    local nomeveiculo = v["Veiculo"]
                    local status = v["Status"]
                    table.insert(conce, {Owner = dono, Model = modelo, Veiculo = nomeveiculo, Estado = status })
                   
                end
            end
        end
        if (#conce > 0) then
            triggerClientEvent(source, "H3>ShowGRID", root, conce)
        else
            return false
        end
    end
end
addEvent("H3>TransferInfo", true)
addEventHandler("H3>TransferInfo", resourceRoot, passarInfoGaragem)
 
function passarInfoDetran (source)
    if getElementType(source) == "player" then
        local result = dbPoll(dbQuery(db, "SELECT * FROM player"), -1)
        local conce = {}
        if (#result > 0) then
            for _, v in ipairs(result) do
                if v["Login"] == getAccountName(getPlayerAccount(source)) and #v["Login"] > 0 then
                    local dono = v["Login"]
                    local modelo = v["Modelo"]
                    local nomeveiculo = v["Veiculo"]
                    local status = v["Status"]
                    local valor = v["Valor"]
                    local multas = v["Multas"]
                    local Wheels = v["Wheels"]
                    table.insert(conce, {Owner = dono, Model = modelo, Veiculo = nomeveiculo, Estado = status, Preco = valor, multas = Multas, Wheels = Wheels, })
                end
            end
        end
        if (#conce > 0) then
            triggerClientEvent(source, "H3>ShowGRIDD", root, conce)
        else
            return false
        end
    end
end
addEvent("H3>TransferInfo2", true)
addEventHandler("H3>TransferInfo2", resourceRoot, passarInfoDetran)
 
function buyVehicle (player, modelo, tipo, preco, nome, r, g, b)
    local accName = getAccountName(getPlayerAccount(player))
    local checarcarro = dbPoll(dbQuery(db, "SELECT * FROM player WHERE Login = ? AND Modelo = ?", accName, tonumber(modelo)),-1)
    if #checarcarro == 0 then
        if tipo == "Money" then
            if getPlayerMoney(player) >= preco then
                dbExec (db, "INSERT INTO player VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?,?,10000)", accName, nome, modelo, 100, 1000, "Guardado", r, g, b,  tonumber(preco), getFreePlate(),  0)
                takePlayerMoney(player, preco)
 
                addNotification(player,  "Veiculo comprado com sucesso!", 'success')
                setElementPosition(player, 1099.566, -1790.223, 13.605)
            else
                addNotification(player, "Você não possui dinheiro suficiente!", 'error')
                setElementPosition(player, 1099.566, -1790.223, 13.605)
            end
        elseif tipo == "Pontos" then
            if getElementData(player, Config.ELEMENTPV) >= preco then
                local pontos = getElementData(player, ELEMENTPV) or 0
                dbExec (db, "INSERT INTO player VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?,?,?)", accName, nome, modelo, 100, 1000, "Guardado", r, g, b, tonumber(preco), getFreePlate(), 0)
                setElementData(player, ELEMENTPV, pontos - preco)
                addNotification(player, "Veiculo comprado com sucesso!", 'success')
                setElementPosition(player, 1099.566, -1790.223, 13.605)
            else
                addNotification(player,  "Você não possui pontos suficiente!", 'error')
                setElementPosition(player, 1099.566, -1790.223, 13.605)
            end
        end
    else
        addNotification(player, "Você já possui este veiculo.", 'info')
        setElementPosition(player, 1099.566, -1790.223, 13.605)
    end
end
addEvent("H3:ComprarVeiculo", true)
addEventHandler("H3:ComprarVeiculo", root, buyVehicle)
 
function tirarveiculo (player, veiculo)
local id = getElementData(player, "ID")
local accName = getAccountName(getPlayerAccount(player))
local x, y, z = getElementPosition( player )
local result = dbPoll(dbQuery(db, "SELECT * FROM player WHERE Login = ? AND Veiculo = ?", accName, tostring(veiculo)), -1)
 
if (#result ~= 0 and type(result) == 'table') then
        if result[1]["Status"] == "Guardado" then
            if result[1]["Status"] == "Detran" then return addNotification(player, "Você não pode tirar um veiculo que está no DETRAN!", 'error') end
            local carro = createVehicle( result[1]["Modelo"], x, y, z , 0, 0, 0, result[1]["Placa"])
            setElementHealth(carro, result[1]["Saude"])
            setElementData(carro, "Owner", id)
            setElementData(carro, "Nome", result[1]["Veiculo"])
            setVehicleColor(carro, result[1]["R"], result[1]["G"], result[1]["B"], result[1]["R"], result[1]["G"], result[1]["B"])
            setElementData(carro, "fuel", result[1]["Gas"])
            setElementData(carro, "Multas", result[1]["Multas"])
            setVehicleWheelStates(carro, result[1]["Wheels"])
            local table = fromJSON(result[1]['Tunagem'])
            setDadosVeh(carro, table[1])        
           
               
           
               
                warpPedIntoVehicle(player, carro)
                dbExec(db, "UPDATE player SET Status = ? WHERE Login = ? AND Veiculo = ?", "Em Rua", accName, tostring(veiculo))
                setVehiclePlateText(carro, result[1]["Placa"])
            end
        end
    end
 
addEvent("H3>TirarVeiculo", true)
addEventHandler("H3>TirarVeiculo", root, tirarveiculo)
 
function guardarveiculo (player, carro)
   
local id = getElementData(player, "ID")
local accName = getAccountName(getPlayerAccount(player))
local carro = getPedOccupiedVehicle(player)
local up1 = addVehicleUpgrade(carro, 1028)
local nomecarro = getElementData(carro, "Nome")
local donocarro = getElementData(carro, "Owner")
local saude = getElementHealth(carro)
local gasolina = getElementData(carro, "fuel") or 0
local multas = getElementData(carro, "Multas") or 0
local Wheels = getVehicleWheelStates(carro) or 0
local Tunagem = getVehicleUpgrades(carro)
local r1, g1, b1, r2, g2, b2, r3, g3, b3 = getVehicleColor(carro, true)
local result = dbPoll(dbQuery(db, "SELECT * FROM player WHERE Login = ? AND Veiculo = ?", accName, nomecarro), -1)
if isElement(carro) and (getElementType(carro) == 'vehicle') then
dados_veh = {  Tunagem = getVehicleUpgrades(carro)}
if donocarro == id then
    if #result > 0 then
        if result[1]["Status"] == "Em Rua" then
            dbExec(db, "UPDATE player SET Status = ? WHERE Login = ? AND Veiculo = ?", "Guardado", accName, nomecarro)
            dbExec(db, "UPDATE player SET Saude = ? WHERE Login = ? AND Veiculo = ?", saude, accName, nomecarro)
            dbExec(db, "UPDATE player SET R = ? WHERE Login = ? AND Veiculo = ?", r1, accName, nomecarro)
            dbExec(db, "UPDATE player SET G = ? WHERE Login = ? AND Veiculo = ?", g1, accName, nomecarro)
            dbExec(db, "UPDATE player SET B = ? WHERE Login = ? AND Veiculo = ?", b1, accName, nomecarro)
            dbExec(db, "UPDATE player SET Gas = ? WHERE Login = ? AND Veiculo = ?", gasolina, accName, nomecarro)
            dbExec(db, "UPDATE player SET Multas = ? WHERE Login = ? AND Veiculo = ?", multas, accName, nomecarro)
            dbExec(db, "UPDATE player SET Wheels= ? WHERE Login = ? AND Veiculo = ?", Wheels, accName, nomecarro)
            dbExec(db, "UPDATE player SET Tunagem = ? WHERE Login = ? AND Veiculo = ?", toJSON({dados_veh}),  accName, nomecarro)
            destroyElement(carro)
            addNotification(player, "Você guardou seu veiculo!", 'success')
           
            end
        end
    end
end
end
addEvent("H3>GuardarVeiculo", true)
addEventHandler("H3>GuardarVeiculo", root, guardarveiculo)
 
function fmultar (player, cmd, placa, valor)
local result = dbPoll(dbQuery(db, "SELECT * FROM player WHERE Placa = ?", tostring(placa)), -1)
if placa then
    if valor then
        if #result > 0 then
            local veiculo = getVehicleFromPlate(placa)
            local multas = getElementData(veiculo, "Multas")
            takePlayerMoney(player, tonumber(valor))
            local donodocarro = getPlayerFromAccountName(result[1]["Login"])
            addNotification(donodocarro, "O seu "..result[1]["Veiculo"].. " foi multado por R$"..tostring(valor), 'info')
        else
            addNotification(player, "Veiculo não encontrado!", 'error')
        end
    end
end
end
addCommandHandler("multar", fmultar)
 
function apreender (player)
local veiculo = getPedOccupiedVehicle(player)
local nome = getElementData(veiculo, "Nome")
local dono = getElementData(veiculo, "Owner")
local placa = getVehiclePlateText(veiculo)
    if isPedInVehicle(player) then
        local result = dbPoll(dbQuery(db, "SELECT * FROM player WHERE Placa = ? AND Veiculo = ? ", tostring(placa), nome), -1)
        if #result > 0 then
            dbExec(db, "UPDATE player SET Status = ? WHERE Placa = ? AND Veiculo = ?", "Detran", tostring(placa), nome)
            destroyElement(veiculo)
            end
        end
    end
addEvent("H3>Apreender", true)
addEventHandler("H3>Apreender", root, apreender)
 
function tirardetran (player, veiculo, valor)
local money = getPlayerMoney(player)
local accName = getAccountName(getPlayerAccount(player))
local result = dbPoll(dbQuery(db, "SELECT * FROM player WHERE Veiculo = ? AND Login = ?", tostring(veiculo), accName), -1)
if money >= tonumber(valor) then
    if #result > 0 then
        takePlayerMoney(player, tonumber(valor))
        dbExec(db, "UPDATE player SET Status = ? WHERE Veiculo = ? AND Login = ?", "Guardado", tostring(veiculo), accName)
        addNotification(player, "Você retirou seu veiculo do DETRAN com sucesso!", 'success')
    end
else
    addNotification(player, "Dinheiro insuficiente!", 'error')
end
end
addEvent("H3>TirarDETRAN", true)
addEventHandler("H3>TirarDETRAN", root, tirardetran)
 
--  local donodocarro = getPlayerFromAccountName(result[1]["Login"])
--  addNotification(donodocarro, "O seu "..result[1]["Veiculo"].. " foi multado por R$"..tostring(valor))
--
--
--function elementClicked( theButton, theState, thePlayer )
    --if theButton == "left" and theState == "down" then -- if left mouse button was pressed down
        --outputChatBox( "You clicked " .. getElementType( source ), thePlayer ) -- print the element type to players chatbox
   -- end
--end
--addEventHandler( "onElementClicked", root, elementClicked ) -- add a handler function for the event
 
addEventHandler("onElementClicked", root, function(button, state, jogador)
local x,y,z = getElementPosition(jogador)
local x2, y2, z2 = getElementPosition(source)
if getDistanceBetweenPoints3D(x, y, z, x2, y2, z2) <= 3 then
if not isPedInVehicle(jogador) then
    if button == "left" and state == "down" then
        if getElementType(source) == "vehicle" then
            if getElementData(source, "Owner") == getElementData(jogador, "ID") then
                triggerClientEvent(jogador, "H3>OpenDXFORAVEICULO", root, source, true)
            else
                triggerClientEvent(jogador, "H3>OpenDXFORAVEICULO", root, source, false)
            end
        end
    end
else
    if button == "left" and state == "down" then
        if getPedOccupiedVehicleSeat (jogador) == 0 then
        if getElementType(source) == "vehicle" then
            if getVehicleType(source) == "BMX" then return end
            if getElementData(source, "Owner") == getElementData(jogador, "ID") then
                triggerClientEvent(jogador, "H3>OpenDXDENTROVEICULO", root, source, true)
            else
                triggerClientEvent(jogador, "H3>OpenDXDENTROVEICULO", root, source, false)
            end
        end
        end
    end
end
end
end)
 
addEventHandler("onVehicleStartEnter", root, function(player)
    triggerClientEvent(player, "H3>CloseDXFORAVEICULO", root)
end)
 
addEventHandler("onVehicleEnter", root, function()
    if getVehicleType(source) == "BMX" then return end
        setVehicleEngineState(source, false)
end)
 
addEventHandler("onVehicleExit", root, function(player)
    triggerClientEvent(player, "H3>CloseDXDENTROVEICULO", root)
end)
 
addEvent("H3>StartVehicle", true)
addEventHandler("H3>StartVehicle", root, function(element)
    setVehicleEngineState(element, not getVehicleEngineState(element))
end)
 
addEvent("H3>CloseAndOpenVehicle", true)
addEventHandler("H3>CloseAndOpenVehicle", root, function(jogador, veiculo)
local x,y,z = getElementPosition(jogador)
    if getElementData(veiculo, "Owner") == getElementData(jogador, "ID") then
        if not isVehicleLocked(veiculo) then
            setVehicleLocked(veiculo, true)
            addNotification(jogador, "Veiculo trancado!", 'success' )
            triggerClientEvent(jogador, "playSound3D", root, "veh-lock.mp3", x, y, z)
            setPedAnimation(jogador, "SHOP", "ROB_Loop_Threat", true, false, false, false, 0, false)
            setTimer(function()
                setPedAnimation(jogador)
            end, 500, 1)
        else
            setVehicleLocked(veiculo, false)
            addNotification(jogador, "Veiculo destrancado!", 'error')
            setPedAnimation(jogador, "SHOP", "ROB_Loop_Threat", true, false, false, false, 0, false)
            triggerClientEvent(jogador, "playSound3D", root, "veh-lock.mp3", x, y, z)
            setTimer(function()
                setPedAnimation(jogador)
            end, 500, 1)
        end
    end
end)
 
function getPlayerFromAccountName(name)
    local acc = getAccount(name)
    if not acc or isGuestAccount(acc) then
        return false
    end
    return getAccountPlayer(acc)
end
 
function getVehicleFromPlate (plate)
    for _, v in ipairs(getElementsByType("vehicle")) do
    local placa = getVehiclePlateText(v)
        if placa == plate then
            return v
        end
    end
end


 
addEvent("H3>StartVehicle", false)
addEventHandler("H3>StartVehicle", root, function(element)
    if (getElementHealth (element) <= 351) then
        setVehicleEngineState(source, false)
        addNotification(source, "Seu veiculo quebrou, chame um mecanico", 'info')
    end
end)
 
addEvent("H3>StartVehicle", false)
addEventHandler("H3>StartVehicle", root, function(element)
    local gasolina = (tonumber (getElementData (element, 'fuel') ) or 0)
    if (gasolina <= 0) then
        addNotification(source, "Seu veiculo ficou sem gasolina", 'info')
        setVehicleEngineState(source, false)
    end
end)
 
function addNotification(playerSource, type, message)
    triggerClientEvent (playerSource, 'addBox', playerSource, type, message)
end
function setDadosVeh (carro, table)
   
    for _, upgrades in ipairs(table.Tunagem) do
        addVehicleUpgrade(carro, tonumber(upgrades))
    end
 
end

 

Link to comment
Guest
This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...