Jump to content

Player exit vehicle


joriss11

Recommended Posts

Hey,

i am having an issue regarding a certain script. I am trying to create a script, in which the player will automaticly exit the vehicle once it catches fire / has a certain amount of health left.

this is what I currently have :

[lua] 

setTimer(
function (player)
local yass = getPedOccupiedVehicle(player)
	for _, vehicle in ipairs ( getElementsByType ( "vehicle" ) ) do
	 if getElementHealth(vehicle) < 301 then
	 setVehicleDamageProof( vehicle, true)
	 setVehicleEngineState( vehicle, false)
          setTimer(removeThePed, 100, 1)
 else
     if getElementHealth(vehicle) > 302 then
	 setVehicleDamageProof( vehicle, false)
	 setVehicleEngineState( vehicle, true)
	
   end
  end
 end
end,
100, 0
)

function removeThePed ( )
removePedFromVehicle ( yass )                                 -- Removes the ped from any vehicle. 
end

[/lua]

From what I know I tried my best to get things working correctly. The damage proof and engine state works fine, but the player wont exit the vehicle.

if anyone could assist me, that would be great,

joriss11

Link to comment

This is better use this.

Quote

function checkDamage(loss)
    if getElementHealth(source) > 301 then
        setVehicleDamageProof(source,false)
        setVehicleEngineState(source,true)
    else
        setVehicleDamageProof(source,true)
        setVehicleEngineState(source,false)
    end
    for i,player in ipairs(getVehicleOccupants(source)) do
        removePedFromVehicle(player)
    end
end
addEventHandler("onVehicleDamage",getRootElement(),checkDamage)

Regards, URBAN

Link to comment

@joriss11 

function checkDamage(loss)
    if getElementHealth(source) > 301 then
        setVehicleDamageProof(source,false)
        setVehicleEngineState(source,true)
    else
        setVehicleDamageProof(source,true)
        setVehicleEngineState(source,false)
        for i,player in pairs(getVehicleOccupants(source)) do
            removePedFromVehicle(player)
        end
    end
end
addEventHandler("onVehicleDamage",getRootElement(),checkDamage)

Use this version i just changed position of loop

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