squar Posted March 4, 2013 Share Posted March 4, 2013 (edited) delete Edited March 7, 2013 by Guest Link to comment
albers14 Posted March 4, 2013 Share Posted March 4, 2013 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
squar Posted March 4, 2013 Author Share Posted March 4, 2013 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 Link to comment
squar Posted March 5, 2013 Author Share Posted March 5, 2013 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 Link to comment
Castillo Posted March 5, 2013 Share Posted March 5, 2013 Post the part where you create the object. Link to comment
squar Posted March 5, 2013 Author Share Posted March 5, 2013 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
Castillo Posted March 5, 2013 Share Posted March 5, 2013 -- 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
squar Posted March 5, 2013 Author Share Posted March 5, 2013 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
Castillo Posted March 5, 2013 Share Posted March 5, 2013 for object, _ in pairs ( objectsSpawned [ client ] ) do destroyElement ( object ) objectsSpawned [ client ] [ object ] = nil end That should do it. Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now