Jump to content

if vehicle dead?


Reinhard

Recommended Posts

i tried to use onVehicleExplode to check if vehicle is dead.. but it still doesn't trigger the function fail, how ???
 

vehicle = createVehicle ( 429, 1, 2, 3, 0, 0, 0)

function fail (player) 
if player and getElementType ( player ) == 'player' then 
         setElementData(player, "mission", false)
         setTimer(setVehicleLocked, 350, 1, vehicle, false)
         outputChatBox("test")
addEventHandler ( "onVehicleExplode", vehicle, fail )
end
end

 

Link to comment
vehicle = createVehicle ( 429, 1, 2, 3, 0, 0, 0)

function fail (player) 
	if player and getElementType ( player ) == 'player' then 
         setElementData(player, "mission", false)
         setTimer(setVehicleLocked, 350, 1, vehicle, false)
         outputChatBox("test")
	end
end
addEventHandler ( "onVehicleExplode", root, fail )

addEventHandler sits after the whole function. And you need to replace 'vehicle' with 'root' in the addEventHandler line.

Edited by koragg
https://wiki.multitheftauto.com/wiki/AddEventHandler
Link to comment
13 minutes ago, koragg said:

vehicle = createVehicle ( 429, 1, 2, 3, 0, 0, 0)

function fail (player) 
	if player and getElementType ( player ) == 'player' then 
         setElementData(player, "mission", false)
         setTimer(setVehicleLocked, 350, 1, vehicle, false)
         outputChatBox("test")
	end
end
addEventHandler ( "onVehicleExplode", root, fail )

addEventHandler sits after the whole function. And you need to replace 'vehicle' with 'root' in the addEventHandler line.

doesn't work and anyway.. i want it to work at that "vehicle" not all the vehicles in san andreas.... anyways i saw this ex in wiki. not all addEventHandlers are roots...

function onThisResourceStart ()

	-- Create the vagos vehicle. A van.
	vagosVehicle = createVehicle ( 522, 0, 0, 5 )

	-- Add its explode handler. When this car explodes, onVagosVehicleExplode is called
	addEventHandler ( "onVehicleExplode", vagosVehicle, onVagosVehicleExplode )
end

 

my script works with...

onVehicleEnter and onVehicleExit but idk why it doesnt work with onVehicleExplode!

Edited by Reinhard
Link to comment
1 minute ago, Reinhard said:

doesn't work and anyway.. i want it to work at that "vehicle" not all the vehicles in san andreas.... anyways i saw this ex in wiki. not all addEventHandlers are roots...


function onThisResourceStart ()	-- Create the vagos vehicle. A van.	vagosVehicle = createVehicle ( 522, 0, 0, 5 )	-- Add its explode handler. When this car explodes, onVagosVehicleExplode is called	addEventHandler ( "onVehicleExplode", vagosVehicle, onVagosVehicleExplode )end

If you want it to work only that vehicle then yes, what you did is correct. But the 'addEventhandler' must be after the function in your case. In this^ example it is inside a function, but the addEventHandler is not bound to the same function it is inside of - it's for another function. 

Link to comment
Just now, koragg said:

If you want it to work only that vehicle then yes, what you did is correct. But the 'addEventhandler' must be after the function in your case. In this^ example it is inside a function, but the addEventHandler is not bound to the same function it is inside of - it's for another function. 

but my script works with onVehicleEnter and onVehicleExit, it just doesn't work with onVehicleExplode...

Link to comment

What @koragg said is correct, you needed only to replace root with vehicle

vehicle = createVehicle ( 429, 1, 2, 3, 0, 0, 0)

function fail (player) 
	if player and getElementType ( player ) == 'player' then 
         setElementData(player, "mission", false)
         setTimer(setVehicleLocked, 350, 1, vehicle, false)
         outputChatBox("test")
	end
end
addEventHandler ( "onVehicleExplode", vehicle, fail )

I can't see any problem with his script, did you try to edit it as he told you?

Have fun with scripting :)

Edited by LoPollo
Link to comment

here's the part of my code, for some reason, it says element at argument 2 got nil at the addEventHandler("onVehicleExplode", vehicle, fail)? why?

function createVehicles ( ) 
    loc = math.random ( #vehicles ) 
vehicle = createVehicle ( 429, vehicles[loc][1], vehicles[loc][2], vehicles[loc][3], 0, 0, 0)
    outputChatBox("test", root, 100, 0, 0, true)
blips[vehicles] = createBlipAttachedTo(vehicle, 41) 
setBlipVisibleDistance(blips[vehicles], 150)
addEventHandler ( "onVehicleEnter", vehicle, start ) 
addEventHandler ( "onVehicleExit", vehicle, removedata2 )
end 

function fail (player) 
	if player and getElementType ( player ) == 'player' then 
         setElementData(player, "mission", false)
         setTimer(setVehicleLocked, 350, 1, vehicle, false)
         outputChatBox("test")
	end
end
addEventHandler ( "onVehicleExplode", vehicle, fail )

 

Edited by Reinhard
Link to comment

no more debug errors but still doesn't work wtf? but the onVehicleExit and onVehicleEnter works....

function createVehicles ( ) 
loc = math.random ( #vehicles ) 
vehicle = createVehicle ( 429, vehicles[loc][1], vehicles[loc][2], vehicles[loc][3], 0, 0, 0)
outputChatBox("test", root, 100, 0, 0, true)
blips[vehicles] = createBlipAttachedTo(vehicle, 41) 
setBlipVisibleDistance(blips[vehicles], 150)
addEventHandler ( "onVehicleEnter", vehicle, start ) 
addEventHandler ( "onVehicleExit", vehicle, removedata2 )
addEventHandler ( "onVehicleExplode", vehicle, fail )
end 

function fail (player) 
if player and getElementType ( player ) == 'player' then 
setElementData(player, "mission", false)
setTimer(setVehicleLocked, 350, 1, vehicle, false)
outputChatBox("test")
end
end

 

Edited by Reinhard
Link to comment

function fail (player) -- Are you sure this actually returns the player? I don't see it on the wiki...
    if player and getElementType ( player ) == 'player' then 
         setElementData(player, "mission", false)
         setTimer(setVehicleLocked, 350, 1, vehicle, false)
         outputChatBox("test")
    end
end
addEventHandler ( "onVehicleExplode", vehicle, fail )

 

Try to get the "player" by using this:

local player = getPedOccupiedVehicle(source)

 

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