Doongogar Posted March 2, 2023 Share Posted March 2, 2023 (edited) quando eu do dv nos carros eles desaparecem da garagem, somente dando restart no mod que volta para garagem como faço para quando der dv em vez de destuir o veiculo triggar o evento de guarda o veiculo? function guardarveiculo (player) local id = getElementData(player, "ID") local accName = getAccountName(getPlayerAccount(player)) local carro = getPedOccupiedVehicle(player) local nomecarro = getElementData(carro, "Nome") local donocarro = getElementData(carro, "Owner") local saude = getElementHealth(carro) local gasolina = getElementData(carro, "MD:Gasolina") or 50 local multas = getElementData(carro, "Multas") or 0 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 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) destroyElement(carro) exports._infobox:addNotification(player, "Você guardou seu veiculo!", "success") end end end end addEvent("H3>GuardarVeiculo", true) addEventHandler("H3>GuardarVeiculo", root, guardarveiculo) addCommandHandler("dv", function(playerSource,commandName,id) if isObjectInACLGroup ( "user." ..getAccountName(getPlayerAccount(playerSource)), aclGetGroup ("Staff")) then if(id) then local playerID = tonumber(id) if(playerID) then local targetPlayer, targetPlayerName = getPlayerID(playerID) if targetPlayer then local veh = getPedOccupiedVehicle(targetPlayer) if veh then destroyElement(veh) end end end end end end ) ambos estão em pastas diferentes Edited March 2, 2023 by SciptNovato Link to comment
Other Languages Moderators Lord Henry Posted March 2, 2023 Other Languages Moderators Share Posted March 2, 2023 Código ilegível. Corrija a indentação. Link to comment
Doongogar Posted March 2, 2023 Author Share Posted March 2, 2023 function guardarveiculo (player) local id = getElementData(player, "ID") local accName = getAccountName(getPlayerAccount(player)) local carro = getPedOccupiedVehicle(player) local nomecarro = getElementData(carro, "Nome") local donocarro = getElementData(carro, "Owner") local saude = getElementHealth(carro) local gasolina = getElementData(carro, "MD:Gasolina") or 50 local multas = getElementData(carro, "Multas") or 0 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 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) destroyElement(carro) exports._infobox:addNotification(player, "Você guardou seu veiculo!", "success") end end end end addEvent("H3>GuardarVeiculo", true) addEventHandler("H3>GuardarVeiculo", root, guardarveiculo) addCommandHandler("dv", function(playerSource,commandName,id) if isObjectInACLGroup ( "user." ..getAccountName(getPlayerAccount(playerSource)), aclGetGroup ("Staff")) then if (id) then local playerID = tonumber(id) if(playerID) then local targetPlayer, targetPlayerName = getPlayerID(playerID) if targetPlayer then local veh = getPedOccupiedVehicle(targetPlayer) if veh then destroyElement(veh) end end end end end end ) assim ta certo?, não editei lá pq n to achando o botão de editar acho que some depois de um tempo né Link to comment
Other Languages Moderators Lord Henry Posted March 2, 2023 Other Languages Moderators Share Posted March 2, 2023 Sim, some depois de um tempo pra evitar que os usuários deletem códigos prontos. Só faltou dar mais espaço ali nos dbExec, no exports e nos destroyElement. Link to comment
Doongogar Posted March 3, 2023 Author Share Posted March 3, 2023 function guardarveiculo (player) local id = getElementData(player, "ID") local accName = getAccountName(getPlayerAccount(player)) local carro = getPedOccupiedVehicle(player) local nomecarro = getElementData(carro, "Nome") local donocarro = getElementData(carro, "Owner") local saude = getElementHealth(carro) local gasolina = getElementData(carro, "MD:Gasolina") or 50 local multas = getElementData(carro, "Multas") or 0 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 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) destroyElement(carro) exports._infobox:addNotification(player, "Você guardou seu veiculo!", "success") end end end end addEvent("H3>GuardarVeiculo", true) addEventHandler("H3>GuardarVeiculo", root, guardarveiculo) addCommandHandler("dv", function(playerSource,commandName,id) if isObjectInACLGroup ( "user." ..getAccountName(getPlayerAccount(playerSource)), aclGetGroup ("Staff")) then if (id) then local playerID = tonumber(id) if(playerID) then local targetPlayer, targetPlayerName = getPlayerID(playerID) if targetPlayer then local veh = getPedOccupiedVehicle(targetPlayer) if veh then destroyElement(veh) end end end end end end ) Link to comment
Other Languages Moderators Lord Henry Posted March 3, 2023 Other Languages Moderators Share Posted March 3, 2023 Já tentou usar onElementDestroy para guardar os veículos antes deles serem destruídos? Link to comment
Doongogar Posted March 3, 2023 Author Share Posted March 3, 2023 bem eu não estava ciente desse evento nem pensei nisso, como eu verifico se o elemento carro tem um "Owner"? Link to comment
Other Languages Moderators Lord Henry Posted March 6, 2023 Other Languages Moderators Share Posted March 6, 2023 Normalmente o pessoal associa o veículo a uma tabela. Ou colocam o "owner" como elementData no veículo. Link to comment
Recommended Posts