Jump to content

Player exit vehicle


joriss11

Recommended Posts

Posted

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

Posted

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

Posted
4 hours ago, joriss11 said:

Tried your code @URBAN, however this doesn't work either. Using your code the script wont even load, which is a problem haha.

Which side did u try? I tried that it works well. put it on server side.

Posted

@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

Posted

@URBAN This worked, however this TP's the player outside of the vehicle, instead of letting him get out using the regular animation. Which is what I was trying to achieve. Is that possible to do so?

Posted (edited)

Thanks it worked now, the only issue I am having now, is that its only a one-use script. as It has to be restarted, once a car was destroyed. after that it wont work haha

 

Edit: nvm, works now. Thanks anyways

Edited by joriss11
  • Like 1

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