Jump to content

Need help with attached elementes


KITT1995

Recommended Posts

I made this script

funtion removeNeon () 
    local neon = getAttachedElements (theVehicle) 
    for index , attachedElement in ipairs ( neon ) do 
    if getElementModel ( attachedElement ) == 3907 or getElementModel ( attachedElement ) == 3917 then 
    destroyElement (attachedElement) 
    end 
    end 
end 
  

What I want is that when a car that have attached 3907 or 3917 element, when that car explode that element will be destroy too.

If it is possible i want to that element destroy when a car will be unload (i mean the destroy command in admin panel).

Link to comment
When you create the objects, use setElementParent ( object, vehicle ), this will make the vehicle the parent of the objects. destroyElement will also destroy all children of the element you're destroying.

It doesn't work with setElementParent. It only destroy the two elements of last vehicle that they were applied

Link to comment

this is the part of the script where I need help. I can't post the entire script cuz is too long

funtion removeNeon () 
    local neon = getAttachedElements (theVehicle) 
    for index , attachedElement in ipairs ( neon ) do 
    if getElementModel ( attachedElement ) == 3907 or getElementModel ( attachedElement ) == 3917 then 
    destroyElement (attachedElement) 
    end 
    end 
end 
addEventHandler ( "onVehicleExplode", getRootElement(), removeNeon ) 
  

Link to comment
funtion removeNeon () 
    local neon = getAttachedElements ( source ) 
    for index , attachedElement in ipairs ( neon ) do 
        if getElementModel ( attachedElement ) == 3907 or getElementModel ( attachedElement ) == 3917 then 
            destroyElement ( attachedElement ) 
        end 
    end 
end 
addEventHandler ( "onVehicleExplode", getRootElement(), removeNeon ) 
  

Remember, onVehicle* events' source are the vehicles that the event occurred on.

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