Jump to content

Can't delete object from client side?


Protagonist95

Recommended Posts

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

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

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

Link to comment

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

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

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