Jump to content

[HELP] removeEventHandler not working..


Raizel

Recommended Posts

hello, im trying to make the panel pop up by command. the open function works but the close function doesnt work.

loadstring(exports.dgs:dgsImportFunction())()

local IsOn = false
local sW, sH = dgsGetScreenSize()



function OpenClosePhone()
    if IsOn == false then
        addEventHandler("onClientRender", getRootElement(), phone1)
    elseif IsOn == true then
        removeEventHandler("onClientRender", getRootElement(), phone1)
    end
end
bindKey("n", "down", OpenClosePhone) 



function phone1()
    if IsOn == false then
        
        -- components 
        rrn = dgsCreateRoundRect(30,false, tocolor(0,0,0,255))
        phone = dgsCreateImage( sW * 0.7, sH * 0.5, sW * 0.20, sH * 0.50, rrn, false)

        app_texture1 = dxCreateTexture("ohnoe.jpg")
        app1 = dgsCreateRoundRect(30,false, tocolor(255,255,255,255))
        app = dgsCreateImage( sW * 0.750, sH * 0.650, sW * 0.10, sH * 0.15, app1, false)
        app_button = dgsCreateButton(  sW * 0.750, sH * 0.650, sW * 0.10, sH * 0.15, "", false, _, tocolor(0,0,0,0) )
        dgsRoundRectSetTexture(app1, app_texture1)
        dgsSetLayer (app_button,"top")
        dgsSetAlpha(app_button, 0)
        IsOn = true
        addEventHandler ( "onDgsMouseClickDown", app_button, app1Func )

        -- animations 


    end
end 

function app1Func ()
    outputChatBox("hey")
end

idk how to fix it, please help me:sad2:

Link to comment
17 hours ago, _SAXI_ said:

The creation components in DGS are not to be used by the "onClientRender" event. If you want to remove the components you must use the destroyElement function

how do i make it be able to open and close anytime i want to? because rn when i close it i cant open it again :sad5:

Link to comment
loadstring(exports.dgs:dgsImportFunction())()

local IsOn = false
local sW, sH = dgsGetScreenSize()

function doPhone()
   if(IsOn) then return end
   rrn = dgsCreateRoundRect(30,false, tocolor(0,0,0,255))
   phone = dgsCreateImage( sW * 0.7, sH * 0.5, sW * 0.20, sH * 0.50, rrn, false)
   app_texture1 = dxCreateTexture("ohnoe.jpg")
   app1 = dgsCreateRoundRect(30,false, tocolor(255,255,255,255))
   app = dgsCreateImage( sW * 0.750, sH * 0.650, sW * 0.10, sH * 0.15, app1, false)
   app_button = dgsCreateButton(  sW * 0.750, sH * 0.650, sW * 0.10, sH * 0.15, "", false, _, tocolor(0,0,0,0) )
   dgsRoundRectSetTexture(app1, app_texture1)
   dgsSetLayer (app_button,"top")
   dgsSetAlpha(app_button, 0)
   addEventHandler("onDgsMouseClickDown", app_button, app1Func)
   IsOn = true
   -- animations 
end

function removePhone()
   if(not IsOn) then return end
   removeEventHandler("onDgsMouseClickDown", app_button, app1Func)
   destroyElement(rrn)
   destroyElement(phone)
   destroyElement(app_texture1)
   destroyElement(app1)
   destroyElement(app)
   destroyElement(app_button)
   IsOn = false
end

function togglePhone()
   if(IsOn) then
      removePhone()
   else
      doPhone()
   end
end
bindKey("n", "down", togglePhone) 

function app1Func()
    outputChatBox("hey")
end

 

I didn't test it but can you try this

Edited by Burak5312
  • Thanks 1
Link to comment
57 minutes ago, Burak5312 said:
loadstring(exports.dgs:dgsImportFunction())()

local IsOn = false
local sW, sH = dgsGetScreenSize()

function doPhone()
   if(IsOn) then return end
   rrn = dgsCreateRoundRect(30,false, tocolor(0,0,0,255))
   phone = dgsCreateImage( sW * 0.7, sH * 0.5, sW * 0.20, sH * 0.50, rrn, false)
   app_texture1 = dxCreateTexture("ohnoe.jpg")
   app1 = dgsCreateRoundRect(30,false, tocolor(255,255,255,255))
   app = dgsCreateImage( sW * 0.750, sH * 0.650, sW * 0.10, sH * 0.15, app1, false)
   app_button = dgsCreateButton(  sW * 0.750, sH * 0.650, sW * 0.10, sH * 0.15, "", false, _, tocolor(0,0,0,0) )
   dgsRoundRectSetTexture(app1, app_texture1)
   dgsSetLayer (app_button,"top")
   dgsSetAlpha(app_button, 0)
   addEventHandler("onDgsMouseClickDown", app_button, app1Func)
   IsOn = true
   -- animations 
end

function removePhone()
   if(not IsOn) then return end
   removeEventHandler("onDgsMouseClickDown", app_button, app1Func)
   destroyElement(rrn)
   destroyElement(phone)
   destroyElement(app_texture1)
   destroyElement(app1)
   destroyElement(app)
   destroyElement(app_button)
   IsOn = false
end

function togglePhone()
   if(IsOn) then
      removePhone()
   else
      doPhone()
   end
end
bindKey("n", "down", togglePhone) 

function app1Func()
    outputChatBox("hey")
end

 

I didn't test it but can you try this

thank you, it works perfectly

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