Bean666 Posted January 30, 2021 Posted January 30, 2021 (edited) 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 January 30, 2021 by Shaman123 Aftermath
Moderators IIYAMA Posted January 30, 2021 Moderators Posted January 30, 2021 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); ]] Do you want to improve your Lua programming skills and make less mistakes? Start with Lua Language Server! Useful functions 3x Spoiler checkPassiveTimer getScreenStartPositionFromBox getPedGender Tutorials 4x Spoiler Scaling DX Events Attach an addEventHandler on a group of elements Debugging
Bean666 Posted January 30, 2021 Author Posted January 30, 2021 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? 1 Aftermath
Moderators IIYAMA Posted January 30, 2021 Moderators Posted January 30, 2021 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`) Do you want to improve your Lua programming skills and make less mistakes? Start with Lua Language Server! Useful functions 3x Spoiler checkPassiveTimer getScreenStartPositionFromBox getPedGender Tutorials 4x Spoiler Scaling DX Events Attach an addEventHandler on a group of elements Debugging
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now