Jump to content

[HELP] destroyElement


squar

Recommended Posts

Post the code where the element get created. Else let me explain.

What I can see is you already got a table with the objects whatever..

Create a new table called objectOwner, and everytime you create a new object you use the code

  
objectOwner[theObject] = thePlayer 
  

Which means you are saying the object owner of the theObject, is a player data. The player which created theObject.

And then you check if the clicked element is owned by thePlayer with,

  
  
addEvent( 'onDestroyElement',true ) 
addEventHandler( 'onDestroyElement',root, 
    function( ) 
if source then 
    if objectOwner[source] == thePlayer then  
        destroyElement( source ) 
    end 
end 
) 
  
  

Should be working but not tested ;)

Link to comment
local objectsSpawned = {} 
  
function createTheObjects( thePlayer,objectID,objectPosX,objectPosY,objectPosZ, objectRotX, objectRotY, objectRotZ ) 
    obj = createObject( thePlayer,objectID,objectPosX,objectPosY,objectPosZ, objectRotX, objectRotY, objectRotZ ) 
    setElementDoubleSided (obj,true) 
    if (not objectsSpawned[client]) then 
        objectsSpawned[client] = {} 
    end 
    table.insert ( objectsSpawned [ client ], obj ) 
end 
addEvent("createObjects",true) 
addEventHandler("createObjects",root,createTheObjects) 

Link to comment

-- server side:

local objectsSpawned = { } 
  
function createWorldObject ( thePlayer, objectID, objectPosX, objectPosY, objectPosZ, objectRotX, objectRotY, objectRotZ ) 
    obj = createObject ( objectID, objectPosX, objectPosY, objectPosZ, objectRotX, objectRotY, objectRotZ ) 
    setElementDoubleSided ( obj, true ) 
    if ( not objectsSpawned [ client ] ) then 
        objectsSpawned [ client ] = { } 
    end 
    objectsSpawned [ client ] [ obj ] = true 
end 
addEvent ( "spawnConstruction", true ) 
addEventHandler ( "spawnConstruction", root, createWorldObject ) 
  
addEvent ( 'onDestroyElement', true ) 
addEventHandler ( 'onDestroyElement', root, 
    function ( obj ) 
        if ( objectsSpawned [ client ] ) then 
            if ( objectsSpawned [ client ] [ obj ] ) then 
                destroyElement ( obj ) 
                objectsSpawned [ client ] [ obj ] = nil 
            end 
        end 
    end 
) 

-- client side:

function clickObject ( button, state, absoluteX, absoluteY, worldX, worldY, worldZ, clickedElement ) 
    if ( clickedElement and isElement ( clickedElement ) and getElementType ( clickedElement ) == "object" ) then 
        guiSetVisible ( mainGUI, true ) 
        removeEventHandler ( "onClientClick", root, clickObject ) 
        triggerServerEvent ( 'onDestroyElement', localPlayer, clickedElement ) 
    end 
end 

Link to comment

Hey! It worked , thank you! I didnt mention that i have a remove all objects function too. It got bugged when you made that new setup, and I'm not sure how to fix it. I hoped you could give a little hint about how to do it. Again, thanks!

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