Jump to content

[SOLVED] onPickupHit doesn't get it's element


Recommended Posts

going back and forth, trying diffrent things I am clueless.

I have a pickup element, the pickup element does exist. I know that it's being stored in a table and I am obviously missing something, but I have no clue how to resolve this.

Ideas?

  
     
  
    local dbid, ent, ext= nil 
    intEnt, intExt = {}, {} 
    function loadHouses(interiorElement) 
            if not (interiorElement) then 
                    interiorElement = getElementsByType('house') 
            end 
            
            if(interiorElement) then 
                    for _, interior in ipairs(interiorElement)do 
                            loadOnePickup(interior) 
                    end 
            else 
                    outputDebugString('[ERROR] : interiorElement not found', 3) 
            end 
    end 
    setTimer(loadHouses, 500, 1) 
      
    function loadOnePickup(int) 
            if not(int) then 
                    outputDebugString('[ERROR] : element(int) not found', 3) 
            end 
            dbid = getElementData(int, 'home:id') 
            if (dbid) then 
                    ent = getElementData(int, 'home:entrance') 
                    ext = getElementData(int, 'home:exit') 
                    createHousePickup(int) 
            end 
    end 
    addEvent('createHousePickups', true) 
    addEventHandler('createHousePickups', getRootElement(), loadOnePickup) 
      
    function createHousePickup(interior) 
            intEnt[dbid] = createPickup(ent[INT_X], ent[INT_Y], ent[INT_Z], 3, 1273) 
            setElementParent(intEnt[dbid], interior) 
            setElementDimension(intEnt[dbid], ent[INT_DIM]) 
            setElementInterior(intEnt[dbid], ent[INT_INT]) 
            intExt[dbid] = createPickup(ext[INT_X], ext[INT_Y], ext[INT_Z], 3, 1318) 
            setElementParent(intExt[dbid], interior) 
            setElementDimension(intExt[dbid], ext[INT_DIM]) 
            setElementInterior(intExt[dbid], ext[INT_INT]) 
            entrance = intEnt[dbid] 
            outputChatBox(tostring(getElementType(entrance))) 
            exit = intExt[dbid] 
    end 
      
    function boop() 
            outputChatBox('DAMMIT MOON MOON') 
    end 
    addEventHandler('onPickupHit', entrance, boop) 
  
  
  

Edited by Guest
Link to comment

I'm not entirely sure if it would work, but you could try this:

  
    local dbid, ent, ext= nil 
    intEnt, intExt = {}, {} 
    function loadHouses(interiorElement) 
            if not (interiorElement) then 
                    interiorElement = getElementsByType('house') 
            end 
            
            if(interiorElement) then 
                    for _, interior in ipairs(interiorElement)do 
                            loadOnePickup(interior) 
                    end 
            else 
                    outputDebugString('[ERROR] : interiorElement not found', 3) 
            end 
    end 
    setTimer(loadHouses, 500, 1) 
      
    function loadOnePickup(int) 
            if not(int) then 
                    outputDebugString('[ERROR] : element(int) not found', 3) 
            end 
            dbid = getElementData(int, 'home:id') 
            if (dbid) then 
                    ent = getElementData(int, 'home:entrance') 
                    ext = getElementData(int, 'home:exit') 
                    createHousePickup(int) 
            end 
    end 
    addEvent('createHousePickups', true) 
    addEventHandler('createHousePickups', getRootElement(), loadOnePickup) 
      
    function createHousePickup(interior) 
            intEnt[dbid] = createPickup(ent[INT_X], ent[INT_Y], ent[INT_Z], 3, 1273) 
            setElementParent(intEnt[dbid], interior) 
            setElementDimension(intEnt[dbid], ent[INT_DIM]) 
            setElementInterior(intEnt[dbid], ent[INT_INT]) 
            intExt[dbid] = createPickup(ext[INT_X], ext[INT_Y], ext[INT_Z], 3, 1318) 
            setElementParent(intExt[dbid], interior) 
            setElementDimension(intExt[dbid], ext[INT_DIM]) 
            setElementInterior(intExt[dbid], ext[INT_INT]) 
            entrance = intEnt[dbid] 
            addEventHandler('onPickupHit', entrance, boop) 
            outputChatBox(tostring(getElementType(entrance))) 
            exit = intExt[dbid] 
    end 
      
    function boop() 
            outputChatBox('DAMMIT MOON MOON') 
    end 
  

Basicly I've moved the event handler so that it adds one for each pickup you create. Again, I'm not sure if it would work, but give it a try.

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