Sign in to follow this  
Protagonist95

Can't delete object from client side?

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)

 

Share this post


Link to post

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

 

Share this post


Link to post
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?
 

Share this post


Link to post

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.

Share this post


Link to post
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

Share this post


Link to post

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

 

Share this post


Link to post
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?

Share this post


Link to post

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.

Share this post


Link to post
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.

Share this post


Link to post

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

Share this post


Link to post
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

Share this post


Link to post

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
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.