Jump to content

[AJUDA] Veiculo não ligar quando estiver quebrado


Recommended Posts

Eu estou com um SCRIPT de ligar/desligar carro e entre outras funções, o carro quebra e quando eu aperto a letra "M" ele liga normalmente, eu quero que quando o veiculo estiver quebrado não tenha como ligar o veiculo.

Aqui está o SCRIPT

CLIENT:

Spoiler

local types = {
    ["Automobile"] = true,
    ["Bike"] = true,
    ["Plane"] = true,
    ["Helicopter"] = true,
    ["Boat"] = true,
    ["Train"] = true,
    ["Monster Truck"] = true,
    ["Quad"] = true
}

 


local beltVehicles = {
    ["Automobile"] = true,
    ["Plane"] = true,
    ["Helicopter"] = true,
    ["Boat"] = true,
    ["Train"] = true,
    ["Monster Truck"] = true
}


function playSounds(sounds, bool)
    if not bool then bool = false end
    if sounds == "ov" then
        beltSound = playSound("files/".. sounds ..".mp3", bool)
    else
        playSound("files/".. sounds ..".mp3", bool)
    end
end

local beltVehicles = {
    ["Automobile"] = true,
    ["Plane"] = true,
    ["Helicopter"] = true,
    ["Boat"] = true,
    ["Train"] = true,
    ["Monster Truck"] = true
}

addEventHandler("onClientVehicleEnter", root, function(player)
    if player == localPlayer and beltVehicles[getVehicleType(getPedOccupiedVehicle(localPlayer))] then
        setElementData(localPlayer, "veh:ov", false)
    end
end)


addEventHandler("onClientVehicleExit", root, function(player)
    if player == localPlayer then
        if isElement(beltSound) then
        end
    end
end)


addEventHandler("onClientKey", root, function(key, pressed)
    if isChatBoxInputActive() or isConsoleActive() then return end
    if key == "h" and pressed and getPedOccupiedVehicle(localPlayer) and beltVehicles[getVehicleType(getPedOccupiedVehicle(localPlayer))] then
        if not getElementData(localPlayer, "veh:ov") then
            setElementData(localPlayer, "veh:ov", true)
            playSound("files/ovbe.mp3", false)
    --        outputChatBox("#1066E7[BVH - Veiculo]: #FFFFFFVocê colocou o cinto de segurança!", 255, 255, 255, true)
        else
            setElementData(localPlayer, "veh:ov", false)
            playSound("files/ovki.mp3", false)
        --    outputChatBox("#1066E7[BVH - Veiculo]: #FFFFFFVocê tirou o cinto de segurança!", 255, 255, 255, true)
        end
    end
end)


addEventHandler("onClientElementDestroy", getRootElement(), function ()
    if getElementType(source) == "vehicle" and types[getVehicleType(source)] and getVehicleType(source) ~= "Bike" then
        setElementData(localPlayer, "veh:ov", false)
    end
end)

addEventHandler("onClientPlayerVehicleEnter", localPlayer, function(vehicle, seat)
    if source == localPlayer then
        local engine = vehicle:getData("veh:motor")
        local vehicle = getPedOccupiedVehicle(localPlayer)
        
        if getVehicleType(getPedOccupiedVehicle(localPlayer)) == "BMX" then
            setVehicleEngineState(vehicle, true)
        else
            if not engine then
                setVehicleEngineState(vehicle, false)
            else
                setVehicleEngineState(vehicle, true)
            end
        end
    end
end)


addEventHandler("onClientPlayerVehicleEnter", localPlayer, function(vehicle, seat)
    if source == localPlayer then
        local engine = vehicle:getData("veh:motor")
        local vehicle = getPedOccupiedVehicle(localPlayer)
        
        if getVehicleType(getPedOccupiedVehicle(localPlayer)) == "BMX" then
            setVehicleEngineState(vehicle, true)
        else
            if not engine then
                setVehicleEngineState(vehicle, false)
            else
                setVehicleEngineState(vehicle, true)
            end
        end
        if vehicle then
    --    outputChatBox("#1066E7[BVH - Veiculo]: #FFFFFFPara ligar o veículo, pressione #1066E7J", 255, 255, 255, true)
    --    outputChatBox("#1066E7[BVH - Veiculo]: #FFFFFFColoque o cinto de segurança, pressione #1066E7X", 255, 255, 255, true)
        end
    end
end)

function keyHandler(button,state) --Função Ligar motor
    if not (not guiGetInputEnabled() and not isMTAWindowActive() and not isCursorShowing()) then return end
    if isPedInVehicle(localPlayer) and getPedOccupiedVehicleSeat(localPlayer) == 0 then
        if not types[getVehicleType(getPedOccupiedVehicle(localPlayer))] then return end
        
        local veh = getPedOccupiedVehicle(localPlayer)
        if button == "m" and state then
                if isPedInVehicle(localPlayer) and getPedOccupiedVehicleSeat(localPlayer) == 0 then
                    
                    local state = getVehicleEngineState ( veh )
                    if not state then
                        playSounds("lightswitch")
                        vehTimer = setTimer(kocsiindit,1000,1)
                        playSounds("starter")
                    else
                        kocsiindit()
                    end

                end
        end
    end    
end
addEventHandler("onClientKey",getRootElement(),keyHandler)

function kocsiindit()
    local veh = getPedOccupiedVehicle(localPlayer)
    local state = getVehicleEngineState ( veh )
        if not state then
            m = true
             
            if getElementHealth(veh) >= 1000 then --Verifica se o carro ta quebrado se sim
                m = true
            else
                m = false
           --     outputChatBox("#1066E7[BVH - Veiculo]: #FFFFFFParece que está com o motor fundido chame por um Mecânico /mecanicos!", 255, 255, 255, true)                
            end
            
            if getElementData(veh, "fuel") > 0 then --Verifica se o veiculo ta sem gasolina se sim
                m = true
        --        outputChatBox("#1066E7[BVH - Veiculo]: #FFFFFFVeiculo ligado!", 255, 255, 255, true)
            else
                m = false
          --      outputChatBox("#1066E7[BVH - Veiculo]: #FFFFFFO Veiculo está sem gasolina", 255, 255, 255, true)                
            end

            else
               m = false
        --       outputChatBox("#1066E7[BVH - Veiculo]: #FFFFFFVeiculo desligado!", 255, 255, 255, true)        
        end
        triggerServerEvent("vehicleStart",localPlayer,localPlayer,veh,m)
end

function processLockUnlock(vehicle)
local locked = isVehicleLocked(vehicle)
    if isPedInVehicle(localPlayer) then
    playSounds("lockin")
    else
    playSounds("lockout")
    end
    if locked then
    triggerServerEvent("vehicleLock", localPlayer,localPlayer, vehicle, false)
--    outputChatBox("#1066E7[BVH - Veiculo]: #FFFFFFVeiculo destrancado!", 255, 255, 255, true)
    else
    triggerServerEvent("vehicleLock", localPlayer,localPlayer, vehicle, true)
--    outputChatBox("#1066E7[BVH - Veiculo]: #FFFFFFVeiculo trancado!", 255, 255, 255, true)
    end
end

function light() --Função do farol
    if klikkTimer then return end
    if isTimer(klikkTimerRun) then return end
    klikkTimer = true
    klikkTimerRun = setTimer(function()
        klikkTimer = false
    end,1000,1)
    local vehicle = getPedOccupiedVehicle(localPlayer)
    if isPedInVehicle(localPlayer) and getVehicleController(vehicle) == localPlayer and getVehicleType(vehicle) ~= "BMX" then
        local vehicle = getPedOccupiedVehicle ( localPlayer )
        local vehLampaStat = tonumber(vehicle:getData("veh:light")) or 0
        if vehLampaStat == 0 then
            playSounds("lightswitch")
            triggerServerEvent("setVehLightState",vehicle,vehicle,2, localPlayer)
            vehicle:setData("veh:light",1)
            vehicle:setData("veh >> light",true)
        else
            triggerServerEvent("setVehLightState",vehicle,vehicle,1, localPlayer)
            vehicle:setData("veh:light",0)
            playSounds("lightswitch")
            vehicle:setData("veh >> light",false)
        end
    end
end
bindKey("k", "down", light)
local klikkTimer = false

function setVehicleLockState() --Função trancar o carro
    if klikkTimer then return end
    if isTimer(klikkTimerRun) then return end
    klikkTimer = true
    klikkTimerRun = setTimer(function()
        klikkTimer = false
    end,1000,1)
    local vehicle = getPedOccupiedVehicle ( localPlayer )
    if vehicle then
        processLockUnlock(vehicle)
    else
        local int2 = getElementInterior(localPlayer)
        local dim2 = getElementDimension(localPlayer)
        local mx,my,mz = getElementPosition(localPlayer)
            for k,v in ipairs(getElementsByType("vehicle")) do
                local x,y,z = getElementPosition(v)
                local int = getElementInterior(v)
                local dim = getElementDimension(v)
                local dist = getDistanceBetweenPoints3D(x,y,z,mx,my,mz)
                if dist <= 3 and int2 == int and dim2 == dim then
                    processLockUnlock(v)
                    return
                end
            end
    end
end
bindKey("l", "down", setVehicleLockState)

SERVER:

Spoiler

--[[

---ACESSE: https://vikingsmodsmta.blogspot.com/

--]]

addEvent("vehicleStart",true)
addEventHandler("vehicleStart",getRootElement(),function(player,veh,value)
    if not isElement(veh) and not value and not isPedInVehicle(player) then return end
    if getElementHealth(veh) > 300 then
        setVehicleEngineState(veh,value)
        veh:setData("veh:motor",value)
    end
end)

addEvent("vehicleLock",true)
addEventHandler("vehicleLock",getRootElement(),function(player,veh,value)
    setVehicleLocked(veh, value)
    veh:setData("veh:status", value)
end)

function vehicleStartExit(thePlayer, seat, jacked)
    if isVehicleLocked(getPlayerOccupiedVehicle(thePlayer)) then
        outputChatBox("* #ff6666AVISO - O veículo está fechado!", thePlayer, 255, 255, 255, true)
        cancelEvent()
    end

    if getElementData(thePlayer, "isFuelling") then 
        cancelEvent()
    end
end
addEventHandler("onVehicleStartExit",getRootElement(),vehicleStartExit)

addEvent("setVehLightState",true)
addEventHandler("setVehLightState",root,function(veh,stat, playerSource)
    setVehicleOverrideLights(veh, stat)
    if playerSource then
        if (stat == 2) then
    --        outputChatBox("#1066E7[BVH - Veiculo]: #FFFFFF Farol ligado!", thePlayer, 255, 255, 255, true)
        else
    --        outputChatBox("#1066E7[BVH - Veiculo]: #FFFFFF Farol desligado!", thePlayer, 255, 255, 255, true)
            --outputChatBox("#1066E7[HiqueC - Veiculo]: #FFFFFF desligou a luz do veículo.", thePlayer, 255, 255, 255, true)
        end
    end
end)

-- Se o carro estiver quebrado o motor e desligado
function onVehicleDamage(damage)
    if getElementHealth(source) - damage <= 319 then
        setElementHealth(source, 320)
        resetVehicleExplosionTime(source) 
        setElementData(source, "veh:motor", false)
        setVehicleEngineState(source, false)
    end
end
addEventHandler("onVehicleDamage", root, onVehicleDamage)

addEventHandler("onVehicleStartEnter", root, function(player, _, _)
    if source:getData("veh:status") and getVehicleType(source) == "BMX" then
        cancelEvent()
    end    
    if isVehicleLocked(source) then
        outputChatBox("* #ff6666AVISO - O veículo está trancado!", player, 255, 255, 255, true)
        cancelEvent()
    end
end)

function vehicleDamage ( loss ) 
    local vehHealth = getElementHealth ( source ) 
    if ( vehHealth < 300 ) then 
        setElementHealth ( source, 300 ) 
        setVehicleDamageProof ( source, true ) 
    end 
end 
addEventHandler ( "onVehicleDamage", root, vehicleDamage ) 

 

Link to post

oi, acredito que assim já resolva !!

 

----------- COMO ESTÁ -----------

function kocsiindit()
    local veh = getPedOccupiedVehicle(localPlayer)
    local state = getVehicleEngineState ( veh )
        if not state then
            m = true
             
            if getElementHealth(veh) >= 1000 then --Verifica se o carro ta quebrado se sim
                m = true
            else
                m = false
           --     outputChatBox("#1066E7[BVH - Veiculo]: #FFFFFFParece que está com o motor fundido chame por um Mecânico /mecanicos!", 255, 255, 255, true)                
            end


--------------- COMO É --------------------


function kocsiindit()
    local veh = getPedOccupiedVehicle(localPlayer)
    local state = getVehicleEngineState ( veh )
        if not state then
            m = true
             
            if getElementHealth(veh) >= 0 then --Verifica se o carro ta quebrado se sim
                m = true
            else
                m = false
           --     outputChatBox("#1066E7[BVH - Veiculo]: #FFFFFFParece que está com o motor fundido chame por um Mecânico /mecanicos!", 255, 255, 255, true)                
            end

 

Link to post

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...