Protagonist95 Posted December 13, 2016 Share Posted December 13, 2016 What may be the problem? function destroyObject( theElement, matchingDimension ) local object = getElementAttachedTo(source) -- object attached to colshape if (theElement == getLocalPlayer()) then -- if player hits colshape destroyElement(object) -- destroy object within colshape end end addEventHandler("onClientColShapeHit",getRootElement(),destroyObject) Link to comment
Simple0x47 Posted December 13, 2016 Share Posted December 13, 2016 Put destroyElement( source ) Link to comment
Protagonist95 Posted December 13, 2016 Author Share Posted December 13, 2016 48 minutes ago, Simple01 said: Put destroyElement( source ) didn't help Link to comment
tosfera Posted December 13, 2016 Share Posted December 13, 2016 First of all, you're not even checking if you got an object. Does your console say something about it? Second of all, always detach an object before trying to destroy it. It's not going to work without. function destroyObject ( theElement, matchingDimension ) if ( theElement == getLocalPlayer() ) then local tmpObject = getElementAttachedTo ( source ); if ( tmpObject ) then detachElements ( tmpObject, source ); destroyElement ( tmpObject ); end end end addEventHandler ( "onClientColShapeHit", getRootElement(), destroyObject ); Link to comment
Protagonist95 Posted December 13, 2016 Author Share Posted December 13, 2016 24 minutes ago, tosfera said: First of all, you're not even checking if you got an object. Does your console say something about it? Second of all, always detach an object before trying to destroy it. It's not going to work without. function destroyObject ( theElement, matchingDimension ) if ( theElement == getLocalPlayer() ) then local tmpObject = getElementAttachedTo ( source ); if ( tmpObject ) then detachElements ( tmpObject, source ); destroyElement ( tmpObject ); end end end addEventHandler ( "onClientColShapeHit", getRootElement(), destroyObject ); Why do you need to detach elements? Link to comment
tosfera Posted December 13, 2016 Share Posted December 13, 2016 You're unable to reposition an element when it's attached. If you're attaching an object to another element, or any element to another element. it becomes a child element from the attached to element. Which means; if the parent (the attached to element) gets removed, they get detatched. If you're trying to destroy the element you're attaching, you should first make it an element of it's own again. Else the parent will have trouble seeking it's child. The attachment functions in MTA have a higher priority than any destroy function on the attached element. Link to comment
Protagonist95 Posted December 13, 2016 Author Share Posted December 13, 2016 30 minutes ago, tosfera said: You're unable to reposition an element when it's attached. If you're attaching an object to another element, or any element to another element. it becomes a child element from the attached to element. Which means; if the parent (the attached to element) gets removed, they get detatched. If you're trying to destroy the element you're attaching, you should first make it an element of it's own again. Else the parent will have trouble seeking it's child. The attachment functions in MTA have a higher priority than any destroy function on the attached element. Okay,but in my situation i would like to remove both.Btw not working. Link to comment
tosfera Posted December 13, 2016 Share Posted December 13, 2016 You want to remove the attached element and the colshape? You could try something like this then: function destroyObject ( theElement, matchingDimension ) if ( theElement == getLocalPlayer() ) then local tmpObject = getElementAttachedTo ( source ); if ( tmpObject ) then -- detach everything from both elements detachElements ( tmpObject ); detachElements ( source ); -- destroy both elements destroyElement ( tmpObject ); destroyElement ( source ); end end end addEventHandler ( "onClientColShapeHit", getRootElement(), destroyObject ); Link to comment
Protagonist95 Posted December 13, 2016 Author Share Posted December 13, 2016 4 minutes ago, tosfera said: You want to remove the attached element and the colshape? You could try something like this then: function destroyObject ( theElement, matchingDimension ) if ( theElement == getLocalPlayer() ) then local tmpObject = getElementAttachedTo ( source ); if ( tmpObject ) then -- detach everything from both elements detachElements ( tmpObject ); detachElements ( source ); -- destroy both elements destroyElement ( tmpObject ); destroyElement ( source ); end end end addEventHandler ( "onClientColShapeHit", getRootElement(), destroyObject ); Okay,the detach part is successful,but the destroy isn't.Still dont know why... Any ideas? Link to comment
tosfera Posted December 13, 2016 Share Posted December 13, 2016 Are the objects created on the client's side or server sided? Maybe, just maybe, we're not allowed to delete server sided objects in our client. Link to comment
Protagonist95 Posted December 13, 2016 Author Share Posted December 13, 2016 6 minutes ago, tosfera said: Are the objects created on the client's side or server sided? Maybe, just maybe, we're not allowed to delete server sided objects in our client. I was just thinking about it,and yes.I spawn objects on server side and try to delete them on client side. Link to comment
tosfera Posted December 13, 2016 Share Posted December 13, 2016 That's not working, might want to attach an ID to the object/colshape and do the part where you delete everything on the server. This does mean that only 1 player can get the actual object from that colshape. If you want every client to be able to do so.. you should create the colshapes and objects on the client's side. Link to comment
Protagonist95 Posted December 13, 2016 Author Share Posted December 13, 2016 6 minutes ago, tosfera said: That's not working, might want to attach an ID to the object/colshape and do the part where you delete everything on the server. This does mean that only 1 player can get the actual object from that colshape. If you want every client to be able to do so.. you should create the colshapes and objects on the client's side. Ok il try 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