Jump to content

Setting an object in elementData


..:D&G:..

Recommended Posts

Hello guys, I'm trying to make a mechanic job where the car parts are picked up by the player. When the mechanic enters a marker, the part should attach to the player, and if he enters again and already has a car part attached to them, the object should get destroyed, but it doesn't really work... The object is attached to the player, but it doesn't get destroyed due to the elementData...

parts =  
    { 
        [1015] = { } 
    }  
  
function attachCarPart(hitElement, partID)  
    if (tonumber(getElementData(hitElement, "partInHand")) > 0) then 
        local IDpart = tonumber(getElementData(hitElement, "partInHand")) 
        destroyElement(parts[IDpart][hitElement]) 
        parts[IDpart][hitElement] = nil 
        setElementData(hitElement, "partInHand", 0) 
    else 
        parts[partID][hitElement] = part 
        part = createObject(partID, 0, 0, 0) 
        setElementData(hitElement, "partInHand", partID) 
    end 
end 

Link to comment
    parts = 
        { 
            [1015] = { } 
        } 
      
    function attachCarPart(hitElement, partID) 
        if (tonumber(getElementData(hitElement, "partInHand")) > 0) then 
            local IDpart = tonumber(getElementData(hitElement, "partInHand")) 
            destroyElement(parts[IDpart][hitElement]) 
            parts[IDpart][hitElement] = nil 
            setElementData(hitElement, "partInHand", 0) 
        else 
            part = createObject(partID, 0, 0, 0) 
            parts[partID][hitElement] = part 
            setElementData(hitElement, "partInHand", partID) 
        end 
    end 

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