Jump to content

Problem with destroyElement


xXMADEXx

Recommended Posts

Hello everbody. So, i've got this problem. When I use isElement, it returns true but when I use destroyElement it does absolutly nothing.

local playerTag = { } 
addEventHandler ( "onPlayerMute", root, function ( ) 
    if ( isElement ( playerTag[source] ) ) then 
        destroyElement ( playerTag[source] ) 
    end 
     
    playerTag[source] = exports['NGJobs']:create3DText ( "[MUTED]", { 0, 0, 0 }, { 255, 0, 0 }, source, { 5 } ) 
end )  
  
addEventHandler ( 'onPlayerUnmute', root, function ( ) 
    if ( isElement ( playerTag[source] ) ) then 
        destroyElement ( playerTag[source] ) 
    end 
end ) 
  
addEventHandler ( "onPlayerQuit", root, function ( ) if ( isElement ( playerTag[source] ) ) then destroyElement ( playerTag[source] ) end end ) 
addEventHandler ( "onResourceStop", resourceRoot, function ( ) for i, v in pairs ( playerTag ) do  if ( isElement ( v ) ) then destroyElement ( v ) end end end ) 
addEventHandler ( "onResourceStart", resourceRoot, function ( ) for i, v in ipairs ( getElementsByType ( 'player' ) ) do  if ( isPlayerMuted ( v ) ) then playerTag[v] = exports['NGJobs']:create3DText ( "[MUTED]", { 0, 0, 0 }, { 255, 0, 0 }, source, { 5 } ) end end end ) 

It is only doing it for the "onPlayerUnmuted" event, the rest work fine, this has be absolutely confused...

(Note: "exports['NGJobs']:create3DText " returns an element)

Link to comment
Make sure you define the table element as nil after the actual element is deleted, then you'll avoid getting in situations like these.

K, i changed it to this, but it still does the same thing:

addEventHandler ( 'onPlayerUnmute', root, function ( ) 
    if ( isElement ( playerTag[source] ) ) then 
        destroyElement ( playerTag[source] ) 
        playerTag[source] = nil 
    end 
end ) 

Link to comment
create3DText returns which is not element.

It is returning an element..

function create3DText ( str, pos, color, parent, settings )  
    if str and pos and color then 
        local text = createElement ( '3DText' ) 
        local settings = settings or  { } 
        setElementData ( text, "text", str ) 
        setElementData ( text, "position", pos ) 
        setElementData ( text, "color", color ) 
         
        if ( not parent ) then 
            parent = nil 
        else 
            if ( isElement ( parent ) ) then 
                parent = parent 
            else 
                parent = nil 
            end 
        end 
         
        setElementData ( text, "Settings", settings ) 
        setElementData ( text, "parentElement", parent ) 
         
        return text 
    end 
    return false 
end 

For some reason, it's only not deleting in the onPlayerUnmute event, but the rest work fine..

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