Jump to content

onVehicleExit e onPlayerWasted para destruir veiculo


Recommended Posts

porque nenhum dos dois esta funcionando?

 

function destruirKombiMorte()
local driver = getVehicleOccupant(vehicle)
    if driver and isElement(driver) and getElementType(driver) == "player" and getPedOccupiedVehicleSeat(driver) == 0 then
        if getElementData(vehicle, "kombiEntregas") == true then
        destroyElement(vehicle)
        end
    end
end
addEventHandler("onPlayerWasted", getRootElement(), destruirKombiMorte)

function destruiKombiExit(player, seat)
    if seat == 0 then
    local vehicle = getPedOccupiedVehicle(player)
        if vehicle then
            if getElementData(vehicle, "kombiEntregas") == true then
            destroyElement(vehicle)
            end
        end
    end
end
addEventHandler("onVehicleExit", getRootElement(), destruiKombiExit)

 

Link to comment
4 hours ago, SciptNovato said:

porque nenhum dos dois esta funcionando?

 

function destruirKombiMorte()
local driver = getVehicleOccupant(vehicle)
    if driver and isElement(driver) and getElementType(driver) == "player" and getPedOccupiedVehicleSeat(driver) == 0 then
        if getElementData(vehicle, "kombiEntregas") == true then
        destroyElement(vehicle)
        end
    end
end
addEventHandler("onPlayerWasted", getRootElement(), destruirKombiMorte)

function destruiKombiExit(player, seat)
    if seat == 0 then
    local vehicle = getPedOccupiedVehicle(player)
        if vehicle then
            if getElementData(vehicle, "kombiEntregas") == true then
            destroyElement(vehicle)
            end
        end
    end
end
addEventHandler("onVehicleExit", getRootElement(), destruiKombiExit)

 

No onVehicleExit já vem o elemento do veiculo no evento, sempre será "source", então não é necessario o getPedOccupiedVehicle.
No onVehicleExit EU ACHO que não tem como fazer a verificação se ele esta dentro do carro, por ele ja esta morto, por isso eu setei o elemento numa tabela junto com o assento.
 

--[[

 █▀▀▀█ █▀▀▀ ▀▀█▀▀ █▀▀█ █▀▀█   █▀▀▀ █░░░ █▀▀▀ █▀▄▀█ █▀▀▀ █▄░▒█ ▀▀█▀▀ █▀▀▀█
 ▀▀▀▄▄ █▀▀▀ ░▒█░░ █▄▄█ █▄▄▀   █▀▀▀ █░░░ █▀▀▀ █▒█▒█ █▀▀▀ █▒█▒█ ░▒█░░ █░░▒█
 █▄▄▄█ █▄▄▄ ░▒█░░ █░▒█ █░▒█   █▄▄▄ █▄▄█ █▄▄▄ █░░▒█ █▄▄▄ █░░▀█ ░▒█░░ █▄▄▄█

]]--

local theVehicle = { Element = nil, Seat = 0 } -- Cria a tabela

addEventHandler("onVehicleEnter", root, function(theP)
    if source then -- Se tiver o veiculo, então: 
        theVehicle = { Element = source, Seat = getPedOccupiedVehicleSeat(theP) } -- Coloca o element do carro e o assento.
    end
end)

--[[

 █▀▀▄ █▀▀▀ █▀▀▀█ ▀▀█▀▀ █▀▀█ █░▒█ ▀█▀ █▀▀█   █░▄▀ █▀▀▀█ █▀▄▀█ █▀▀█ ▀█▀
 █░▒█ █▀▀▀ ▀▀▀▄▄ ░▒█░░ █▄▄▀ █░▒█ ░█░ █▄▄▀   █▀▄░ █░░▒█ █▒█▒█ █▀▀▄ ░█░
 █▄▄▀ █▄▄▄ █▄▄▄█ ░▒█░░ █░▒█ ▀▄▄▀ ▄█▄ █░▒█   █░▒█ █▄▄▄█ █░░▒█ █▄▄█ ▄█▄

]]--

local destruiKombiExit = function(thePlayer, seat)
    if seat == 0 and getElementData(source, "kombiEntregas") == true then -- Verificação desejada
        destroyElement(source) -- Destruir carro
    end
end
addEventHandler("onVehicleExit", getRootElement(), destruiKombiExit)

--[[

 █▀▀▄ █▀▀▀ █▀▀▀█ ▀▀█▀▀ █▀▀█ █░▒█ ▀█▀ █▀▀█   ░░   █▀▄▀█ █▀▀▀█ █▀▀█ █▀▀█ █▀▀▀ █▀▀█
 █░▒█ █▀▀▀ ▀▀▀▄▄ ░▒█░░ █▄▄▀ █░▒█ ░█░ █▄▄▀   ▀▀   █▒█▒█ █░░▒█ █▄▄▀ █▄▄▀ █▀▀▀ █▄▄▀
 █▄▄▀ █▄▄▄ █▄▄▄█ ░▒█░░ █░▒█ ▀▄▄▀ ▄█▄ █░▒█   ░░   █░░▒█ █▄▄▄█ █░▒█ █░▒█ █▄▄▄ █░▒█

]]--

local destruirKombiMorte = function ()
    if theVehicle.Seat == 0 then -- Se o assento for o p1, então:
        if getElementData(theVehicle.Element, "kombiEntregas") == true then
            destroyElement(theVehicle.Element) -- Destroi o elemento Carro.
        end
    end
end
addEventHandler("onPlayerWasted", root, destruirKombiMorte)

 

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

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