Jump to content

[HELP] destroyElement


squar

Recommended Posts

Posted

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 ;)

Posted

Ok. ive been trying to get that working, but there's always a problem. I call the objects i make for obj, like obj = createObject etc.. Do any of you know the problem? I'd appreciate your help

Posted

bump

Anyone know how i can set the objects in a table which saves the object to the player only, or at least make it removeable by the placer only

Posted

Post the part where you create the object.

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted
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) 

Posted

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

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted

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!

Posted
for object, _ in pairs ( objectsSpawned [ client ] ) do 
    destroyElement ( object ) 
    objectsSpawned [ client ] [ object ] = nil 
end 

That should do it.

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

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