Jump to content

vehicle damage


botshara

Recommended Posts

When I get out and enter in vehicle while he is damaged i can start engine, but before i damaged car and i had not get out of the car i could not start engine, why ?

addCommandHandler( "toggleengine", 
    function( player, commandName ) 
        if exports.players:isLoggedIn( player ) then 
            local vehicle = getPedOccupiedVehicle( player ) 
            if vehicle and getVehicleOccupant( vehicle ) == player and doesVehicleHaveEngine( vehicle ) then 
                local data = vehicles[ vehicle ] 
                if data then 
                    if data.vehicleID < 0 or exports.sql:query_free( "UPDATE vehicles SET engineState = 1 - engineState WHERE vehicleID = " .. data.vehicleID ) then 
                        if math.floor( getElementHealth( vehicle ) + 0.5 ) > 301 then 
                            setVehicleEngineState( vehicle, not data.engineState ) 
                            data.engineState = not data.engineState 
                        else 
                            outputChatBox( "(( Vehicle motor is broken ))", player, 255, 0, 0 ) 
                        end 
                    end 
                end 
            end 
        end 
    end 
) 
  
addEventHandler( "onVehicleDamage", root, 
    function( loss ) 
        if getElementHealth( source ) <= 301 then 
            setElementHealth( source, 300 ) 
            setVehicleDamageProof( source, true ) 
            setVehicleEngineState( source, false ) 
            if getVehicleOccupant( source ) then 
                outputChatBox( "(( You broken your vehicle motor. ))", getVehicleOccupant( source ), 255, 204, 0 ) 
            end 
        end 
    end 
) 
  
addEventHandler( "onVehicleEnter", root, 
    function( ) 
        if isVehicleDamageProof( source ) and math.floor( getElementHealth( source ) + 0.5 ) > 301 then 
            setVehicleDamageProof( source, false ) 
        end 
    end 
) 
  

Link to comment
addCommandHandler( "toggleengine", 
    function( player, commandName ) 
        if exports.players:isLoggedIn( player ) then 
            local vehicle = getPedOccupiedVehicle( player ) 
            if vehicle and getVehicleOccupant( vehicle ) == player and doesVehicleHaveEngine( vehicle ) then 
                local data = vehicles[ vehicle ] 
                if data then 
                    if data.vehicleID < 0 or exports.sql:query_free( "UPDATE vehicles SET engineState = 1 - engineState WHERE vehicleID = " .. data.vehicleID ) then 
                        if math.floor( getElementHealth( vehicle ) + 0.5 ) > 301 then 
                            setVehicleEngineState( vehicle, not data.engineState ) 
                            data.engineState = not data.engineState 
                        else 
                            outputChatBox( "(( Vehicle motor is broken ))", player, 255, 0, 0 ) 
                        end 
                    end 
                end 
            end 
        end 
    end 
) 
  
addEventHandler( "onVehicleDamage", root, 
    function( loss ) 
        if getElementHealth( source ) <= 301 then 
            setElementHealth( source, 300 ) 
            setVehicleDamageProof( source, true ) 
            setVehicleEngineState( source, false ) 
            if getVehicleOccupant( source ) then 
                outputChatBox( "(( You broken your vehicle motor. ))", getVehicleOccupant( source ), 255, 204, 0 ) 
            end 
        end 
    end 
) 
  
addEventHandler( "onVehicleEnter", root, 
    function( ) 
        if isVehicleDamageProof( source ) and math.floor( getElementHealth( source ) + 0.5 ) > 301 then 
            setVehicleDamageProof( source, false ) 
        else 
            setVehicleEngineState( source, false ) 
        end 
    end 
) 
  

Try it.

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