Jump to content

[SOLVED] VehicleExplode and setElementData


#RooTs

Recommended Posts

And why did you post this code now?!

Did you try the code I sent to you?

added more function

function detachNeon ( theVehicle ) 
    local attachedElements = getAttachedElements ( theVehicle ) 
    for i,v in pairs ( attachedElements ) do 
        --detachElements ( v, theVehicle )    is this even needed? If yes then activate it 
        destroyElement ( v ) 
    end 
end 
addEvent( "detachNeon", true ) 
addEventHandler( "detachNeon", getRootElement(), detachNeon ) 

its function

local playerInVehicle = {} 
local vehicleGotPlayer = {} 
  
function detachNeon ( theVehicle ) 
    local attachedElements = getAttachedElements ( theVehicle ) 
    for i,v in pairs ( attachedElements ) do 
        --detachElements ( v, theVehicle )    is this even needed? If yes then activate it 
        destroyElement ( v ) 
    end 
end 
addEvent( "detachNeon", true ) 
addEventHandler( "detachNeon", getRootElement(), detachNeon ) 
  
addEventHandler ( "onVehicleEnter", root, function ( player, seat ) 
    if seat == 0 then 
        playerInVehicle[player] = source 
        vehicleGotPlayer[source] = player 
        addEventHandler ( "onPlayerQuit", player, removeNeonOnEvent ) 
        addEventHandler ( "onPlayerVehicleExit", player, removeNeonOnEvent ) 
        addEventHandler ( "onVehicleExplode", source, removeNeonOnEvent ) 
    end 
end ) 
  
function removeNeonOnEvent ( vehicle ) 
    local vehicle = vehicle or getElementType ( source ) == "vehicle" and source or playerInVehicle[source] 
    local player = getElementType ( source ) == "player" and source or vehicleGotPlayer[vehicle] 
    detachNeon ( vehicle ) 
    playerInVehicle[player] = nil 
    vehicleGotPlayer[vehicle] = nil 
    setElementData ( player, "neon", 0 ) 
    removeEventHandler ( "onPlayerQuit", player, removeNeonOnEvent ) 
    removeEventHandler ( "onPlayerVehicleExit", player, removeNeonOnEvent ) 
    removeEventHandler ( "onVehicleExplode", vehicle, removeNeonOnEvent ) 
end 

the problem still remains

Link to comment

Oh, didint see the video.

The easiest way is to save the neon in an array with vehicle as index and use it in detachNeon.

neonarray[vehicle] = { neon1, neon2 ... } 

And something I never tested:

You can use setElementParent.

Let the vehicle become the parent of the neonlights.

If the vehicle gets destroyed the neonlights will get destroyed too.

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