Jump to content

Falha de motor.


Recommended Posts

Então, estou com um script para falha de motores, quanto mais o estado de vida do veículo para decaindo ou motor falhar com mais frequência, porém eu queria que quando esse nível de vida não ligasse mais. 
 

Lado do cliente

function vehiclefailures()
    failede = true
	local vehicle = getPedOccupiedVehicle(localPlayer)
	if ( vehicle and (getVehicleType(vehicle) == "Automobile")) then
		if getElementHealth(vehicle) < 550 then
		triggerServerEvent("Caroff", getRootElement(), vehicle)
		setTimer ( function()
		triggerServerEvent("Caron", getRootElement(), vehicle)
		end, 3000, 1 )
		end
	  end
    end

addEventHandler("onClientVehicleDamage", root, vehiclefailures)
addEventHandler("onClientVehicleEnter", root, vehiclefailures)

function enginefailures()
local vehicle = getPedOccupiedVehicle(localPlayer)
if ( vehicle and (getVehicleType(vehicle) == "Automobile")) then
if getElementHealth(vehicle) < 550 then
if not failede then return end
setTimer( function()
        if not failede then return end
        triggerServerEvent("failurex", getRootElement(), vehicle)
		triggerServerEvent("Caroff", getRootElement(), vehicle)
		local sound = playSound("failure.wav")
		setTimer ( function()
		triggerServerEvent("Caron", getRootElement(), vehicle)
		end, 3000, 1 )
		failede = false
		setTimer( function()
		failede = true
		end, 25000, 1 )
		end, 10, 1 )
end
end
end
addEventHandler ( "onClientPreRender", root, enginefailures )

function enginesoundf()
if not sounding then
sound=playSound("failure.wav")
setSoundVolume(sound, 0.5)
setTimer ( function()
sounding = true
end, 5000, 1 )
end
end
addEvent ( "failureclient", true )
addEventHandler ( "failureclient", getRootElement ( ), enginesoundf )


 

Lado do servidor

function turnEngineOff (vehicle)
        setVehicleEngineState ( vehicle, false )
    end
addEvent("Caroff", true)
addEventHandler("Caroff", getRootElement(), turnEngineOff)

function turnEngineOn (vehicle)
        setVehicleEngineState ( vehicle, true )
    end
addEvent("Caron", true)
addEventHandler("Caron", getRootElement(), turnEngineOn)

function carfailure (vehicle)
        if getElementHealth(vehicle) < 360 then return end 
        setElementHealth(vehicle, getElementHealth(vehicle) - 10 )
    end
addEvent("failurex", true)
addEventHandler("failurex", getRootElement(), carfailure)


 

 

Edited by Mec.Love
Link to comment

Fiz, verifique para mim Lord se está correto. 
Cliente-side
 

function vehiclefailures()
    failede = true
    local vehicle = getPedOccupiedVehicle(localPlayer)
    if (vehicle and (getVehicleType(vehicle) == "Automobile")) then
        if getElementHealth(vehicle) < 550 then
            triggerServerEvent("Caroff", getRootElement(), vehicle)
            setTimer(function()
                triggerServerEvent("Caron", getRootElement(), vehicle)
            end, 3000, 1)
        end
    end
end

addEventHandler("onClientVehicleDamage", root, vehiclefailures)
addEventHandler("onClientVehicleEnter", root, vehiclefailures)

function enginefailures()
    local vehicle = getPedOccupiedVehicle(localPlayer)
    if (vehicle and (getVehicleType(vehicle) == "Automobile")) then
        if getElementHealth(vehicle) < 550 then
            if not failede then return end
            setTimer(function()
                if not failede then return end
                triggerServerEvent("failurex", getRootElement(), vehicle)
                triggerServerEvent("Caroff", getRootElement(), vehicle)
                local sound = playSound("failure.wav")
                setTimer(function()
                    triggerServerEvent("Caron", getRootElement(), vehicle)
                end, 3000, 1)
                failede = false
                setTimer(function()
                    failede = true
                end, 25000, 1)
            end, 10, 1)
        end
    end
end
addEventHandler("onClientPreRender", root, enginefailures)

function enginesoundf()
    if not sounding then
        sound = playSound("failure.wav")
        setSoundVolume(sound, 0.5)
        setTimer(function()
            sounding = true
        end, 5000, 1)
    end
end
addEvent("failureclient", true)
addEventHandler("failureclient", getRootElement(), enginesoundf)

Server-side

function turnEngineOff(vehicle)
    setVehicleEngineState(vehicle, false)
end
addEvent("Caroff", true)
addEventHandler("Caroff", getRootElement(), turnEngineOff)

function turnEngineOn(vehicle)
    setVehicleEngineState(vehicle, true)
end
addEvent("Caron", true)
addEventHandler("Caron", getRootElement(), turnEngineOn)

function carfailure(vehicle)
    if getElementHealth(vehicle) < 360 then return end
    setElementHealth(vehicle, getElementHealth(vehicle) - 10)
end
addEvent("failurex", true)
addEventHandler("failurex", getRootElement(), carfailure)

 

Edited by Lord Henry
server-side convertido de HTML para Lua
Link to comment

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...