Jump to content

removeEventHandler?


Bean666

Recommended Posts

Hi, its me again lol i want to make a non-messy code, how do I make all DX disappear in just one line, like i dont have to put 2 removeEventHandlers or more just to remove each one of them on one click.  i only want 1 removeEventHandler for all of them to disappear instead of adding 1 by one, how to do that? the reason I didnt put the test text in the function drawpistol because they are different categories / tabs, thats why i put them on separate functions.

function welcome()
        dxDrawText("test", (930/1920)*sx, (424/1080)*sy, (1254/1920)*sx, (452/1080)*sy, tocolor(255, 255, 255, 255), 1.00, "default-bold", "left", "top", false, false, false, false, false)
    end

function drawpistol()
dxDrawImage((879/1920)*sx, (328/1080)*sy, (162/1920)*sx, (142/1080)*sy, ":guieditor/images/colt45icon.png", 0, 0, 0, tocolor(255, 255, 255, 255), false)
dxDrawImage((997/1920)*sx, (556/1080)*sy, (157/1920)*sx, (144/1080)*sy, ":guieditor/images/desert_eagleicon.png", 0, 0, 0, tocolor(255, 255, 255, 255), false)
dxDrawImage((1120/1920)*sx, (330/1080)*sy, (160/1920)*sx, (140/1080)*sy, ":guieditor/images/silencedicon.png", 0, 0, 0, tocolor(255, 255, 255, 255), false)
end

addEventHandler("onClientGUIClick", root,function()
 if ( source == close) then
           removeEventHandler("onClientPreRender", getRootElement(), drawmypistol);
           removeEventHandler("onClientPreRender", getRootElement(), welcome);
           removeEventHandler("onClientPreRender", getRootElement(), draw);
            guiSetVisible(close, false)
           showCursor(false)
       end
   end )  
Edited by Shaman123
Link to comment
  • Moderators
1 hour ago, Shaman123 said:

thats why i put them on separate functions.

You can manage it like this:

function startDrawing()
	welcome()
	drawpistol()
end

--[[
addEventHandler("onClientPreRender", getRootElement(), startDrawing);
--
removeEventHandler("onClientPreRender", getRootElement(), startDrawing);
]]

 

Link to comment
46 minutes ago, IIYAMA said:

You can manage it like this:


function startDrawing()
	welcome()
	drawpistol()
end

--[[
addEventHandler("onClientPreRender", getRootElement(), startDrawing);
--
removeEventHandler("onClientPreRender", getRootElement(), startDrawing);
]]

 

yeah this is cool

function closedx()
 removeEventHandler("onClientPreRender", getRootElement(), drawpistol);
 removeEventHandler("onClientPreRender", getRootElement(), drawsmg);
end

 addEventHandler("onClientGUIClick", root,function()
 if ( source == close) then
           closedx()
       end
   end )  

i took your advise, it worked perfectly but this code i tried above works too, dont mind it, but if i used that closedx(), its fine too right? will other players experience the closed function too or just him?

  • Like 1
Link to comment
  • Moderators
3 minutes ago, Shaman123 said:

i took your advise, it worked perfectly but this code i tried above works too, dont mind it, but if i used that closedx(), its fine too right?

It is fine.

That being said.

  • 2x eventHandler will use more CPU. That is not a problem at this stage, but when you add more scripts, it might become a problem later for players that are using toasters.

 

5 minutes ago, Shaman123 said:

will other players experience the closed function too or just him?

Just him, since the exact same copy of code is running on each player their pc.

  • There is only 1 server. = 1x serverside
  • There can be multiple clients/players. = for each player there is an unique clientside. (repeat: `which is running on their pc`)

 

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