RandomRambo Posted August 14, 2022 Share Posted August 14, 2022 (edited) Hello guys. I need to create a button in front of my created image and on button K (for example) I need to hide the image and the button (and also cursor,but i did it). So,I can hide cursor and an image but I can't hide the button idk why. Code: local x,y = guiGetScreenSize() local elementd = true local screenW,screenH = guiGetScreenSize() local resW,resH = 1280,720 local sW,sH = (screenW/resW), (screenH/resH) function elementshowd () if elementd == false then elementd = true showCursor(false) guiSetVisible(event, false) else elementd = false end end bindKey( "K", "down", elementshowd) function eventshows () if elementd == false then showCursor ( true ) event = guiCreateButton(16, 20, 250, 40, "Take", false) addEventHandler ( "onClientGUIClick", event, Tokens ) --------- dxDrawImage(500*sW, 120*sH, 370*sW, 470*sH, "img/event.png", 0, 0, 0, tocolor(255, 255, 255, 255), true) end end addEventHandler ( "onClientRender", getRootElement(), eventshows ) Help me please to hide the button Edited August 14, 2022 by RandomRambo Link to comment
Addlibs Posted August 14, 2022 Share Posted August 14, 2022 guiCreateButton is a persistent button - it creates a button element, not renders a button for a frame -- you should never call it in onClientRender except in if-statements which you know will only execute once when necessary (i.e. not every frame, and only if the previously created button was destroyed). Setting elementd to false in your code merely stops creating new buttons -- it does not delete the previously created buttons (yes, buttons, plural. You're creating hundreds of buttons every couple seconds depending on the FPS of the client). This code event = guiCreateButton(16, 20, 250, 40, "Take", false) addEventHandler ( "onClientGUIClick", event, Tokens ) and this code function eventshows () if elementd == false then dxDrawImage(500*sW, 120*sH, 370*sW, 470*sH, "img/event.png", 0, 0, 0, tocolor(255, 255, 255, 255), true) end end addEventHandler ( "onClientRender", getRootElement(), eventshows ) should generally never exist in the same function Link to comment
RandomRambo Posted August 14, 2022 Author Share Posted August 14, 2022 6 hours ago, Addlibs said: guiCreateButton is a persistent button - it creates a button element, not renders a button for a frame -- you should never call it in onClientRender except in if-statements which you know will only execute once when necessary (i.e. not every frame, and only if the previously created button was destroyed). Setting elementd to false in your code merely stops creating new buttons -- it does not delete the previously created buttons (yes, buttons, plural. You're creating hundreds of buttons every couple seconds depending on the FPS of the client). This code event = guiCreateButton(16, 20, 250, 40, "Take", false) addEventHandler ( "onClientGUIClick", event, Tokens ) and this code function eventshows () if elementd == false then dxDrawImage(500*sW, 120*sH, 370*sW, 470*sH, "img/event.png", 0, 0, 0, tocolor(255, 255, 255, 255), true) end end addEventHandler ( "onClientRender", getRootElement(), eventshows ) should generally never exist in the same function So can you show me an example how I can create a button in front of this image and then hide it with it. Link to comment
RandomRambo Posted August 15, 2022 Author Share Posted August 15, 2022 Anyone please? Link to comment
#\_oskar_/# Posted August 15, 2022 Share Posted August 15, 2022 What do you want to do Link to comment
RandomRambo Posted August 15, 2022 Author Share Posted August 15, 2022 1 hour ago, #\_oskar_/# said: What do you want to do Create an image and then create a button in front of image and on for example "K" hide it or show it Link to comment
#\_oskar_/# Posted August 15, 2022 Share Posted August 15, 2022 4 hours ago, RandomRambo said: Create an image and then create a button in front of image and on for example "K" hide it or show it You mean like that? function AttachDxToGuiElement( GUIElement , img ) if ( guiGetVisible ( GUIElement ) ) then local x, y = guiGetPosition ( GUIElement , false ) local width , Height = guiGetSize ( GUIElement , false ) dxDrawImage(x, y, width , Height ,img, 0, 0, 0,SetImagecolor or tocolor(255, 0, 0, 255), true) dxDrawText(guiGetText ( GUIElement ) or tostring '',x, y, width + x , Height + y,SetTextcolor or tocolor(55,55,55,255),1,"default-bold","center","center",false,false,true) guiBringToFront ( GUIElement ) guiSetAlpha ( GUIElement , 0) end end ------------------ event = guiCreateButton(16, 20, 250, 40, "Take", false) addEventHandler ("onClientRender", root, function () AttachDxToGuiElement( event ,'img/event.png' ) end) bindKey( "k", "down",function( ) guiSetVisible( event , not guiGetVisible( event )) showCursor( guiGetVisible( event )) end ) 1 Link to comment
RandomRambo Posted August 18, 2022 Author Share Posted August 18, 2022 (edited) On 16/08/2022 at 00:48, #\_oskar_/# said: You mean like that? function AttachDxToGuiElement( GUIElement , img ) if ( guiGetVisible ( GUIElement ) ) then local x, y = guiGetPosition ( GUIElement , false ) local width , Height = guiGetSize ( GUIElement , false ) dxDrawImage(x, y, width , Height ,img, 0, 0, 0,SetImagecolor or tocolor(255, 0, 0, 255), true) dxDrawText(guiGetText ( GUIElement ) or tostring '',x, y, width + x , Height + y,SetTextcolor or tocolor(55,55,55,255),1,"default-bold","center","center",false,false,true) guiBringToFront ( GUIElement ) guiSetAlpha ( GUIElement , 0) end end ------------------ event = guiCreateButton(16, 20, 250, 40, "Take", false) addEventHandler ("onClientRender", root, function () AttachDxToGuiElement( event ,'img/event.png' ) end) bindKey( "k", "down",function( ) guiSetVisible( event , not guiGetVisible( event )) showCursor( guiGetVisible( event )) end ) Ye,but it shows when I start resource,but It should show if someone jujst press 'K' (not when resource started). And the button doesn't work,it is just as not a button it is just like a text Upd.Button works,but can I just make a button with my image? for example this (and text from button will be on it.Is it possible? Edited August 18, 2022 by RandomRambo Link to comment
RandomRambo Posted August 18, 2022 Author Share Posted August 18, 2022 When I try to add one more button it shows only 1 button anyway.What am I doing wrong?:\ function AttachDxToGuiElement( GUIElement , img ) if ( guiGetVisible ( GUIElement ) ) then showCursor ( true ) local x, y = guiGetPosition ( GUIElement , false ) local width , Height = guiGetSize ( GUIElement , false ) dxDrawImage(500*sW, 120*sH, 370*sW, 470*sH, "img/event.png", 0, 0, 0, tocolor(255, 255, 255, 255), true) dxDrawText(guiGetText ( GUIElement ) or tostring '',x, y, width + x , Height + y,SetTextcolor or tocolor(223,247,0,255),1,"default-bold","center","center",false,false,true) guiBringToFront ( GUIElement ) guiSetAlpha ( GUIElement , 0) end end ------------------ event = guiCreateButton(740, 800, 250, 40, "Take", false) event1 = guiCreateButton(890, 700, 250, 40, "Take", false) addEventHandler ("onClientRender", root, function () AttachDxToGuiElement( event ,'img/event.png' ) AttachDxToGuiElement( event1 ,'img/event.png' ) end) bindKey( "K", "down",function( ) guiSetVisible( event , not guiGetVisible( event )) guiSetVisible( event1 , not guiGetVisible( event1 )) showCursor( guiGetVisible( event )) showCursor ( false ) end ) Link to comment
RandomRambo Posted August 24, 2022 Author Share Posted August 24, 2022 @#\_oskar_/# I did everything I need but how to do that this image with button won't show when it started.I need that it can be show only when someone press 'K',not when resourse is started Link to comment
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