Chopper Posted October 28, 2013 Posted October 28, 2013 Hello. So, i have a login panel made with Static Images. I have an onClientGUIClick eventhandler, for the loginButton element. Clicking on the button, i created a function, it works. But if i click anywhere else on the panel that is a gui Image, it does this. The original panel: Anyone have any idea whats wrong with it? Im sure its not the coding, since its just the panel with an event pointing to another function.
Chopper Posted October 28, 2013 Author Posted October 28, 2013 Not really sure what you mean. I have the handler like this: addEventHandler("onClientGUIClick",loginButton2, tryLogin, false) and the loginButton2 is: loginButton2 = guiCreateStaticImage(553, 447, 178, 100, "loginBut.png", false)
glowdemon1 Posted October 28, 2013 Posted October 28, 2013 https://wiki.multitheftauto.com/wiki/GuiSetEnabled The problem is that when you click a GUI, it puts the GUI into the foreground. Therefore you use guiSetEnabled to freeze a GUI so you cannot put it in the foreground. https://wiki.multitheftauto.com/wiki/GuiMoveToBack Would move a GUI to the back incase its needed, but if you create the background before any other GUI, it will be auto-set to the back.
pa3ck Posted October 28, 2013 Posted October 28, 2013 addEventHandler("onClientGUIClick",loginButton2, function() if (source == loginButton2) then tryLogin() end, false) As far as I understood your actual problem, thats what you need.
TAPL Posted October 28, 2013 Posted October 28, 2013 Not really sure what you mean. I have the handler like this: addEventHandler("onClientGUIClick",loginButton2, tryLogin, false) and the loginButton2 is: loginButton2 = guiCreateStaticImage(553, 447, 178, 100, "loginBut.png", false) see? you don't use parent argument. https://wiki.multitheftauto.com/wiki/GuiCreateStaticImage parent: This is the parent that the image is attached to. If the relative argument is true, sizes and positioning will be made relative to this parent. If the relative argument is false, positioning will be the number of offset pixels from the parent's origin. If no parent is passed, the parent will become the screen - causing positioning and sizing according to screen positioning. loginButton2 = guiCreateStaticImage(553, 447, 178, 100, "loginBut.png", false, YourWindowVariableHere)
Chopper Posted October 28, 2013 Author Posted October 28, 2013 I dont have a GUI Window. Heres my script. function login(player) outputChatBox(source) lathatoE = guiGetVisible(test) if not lathatoE then showCursor(true) fadeCamera(source, true, 5) setCameraMatrix(2442.1264648438,-1649.2254638672,28.584239959717, 5000, -500,-500) test = guiCreateStaticImage(0, 300, 413, 150, "bg1.png", false) test2 = guiCreateStaticImage(399, 202, 485, 357, "bg2.png", false) test3 = guiCreateStaticImage(868, 300, 413, 150, "bg1.png", false) felhnevBox = guiCreateEdit(541, 302, 201, 27, "", false) pwBox = guiCreateEdit(541, 422, 201, 27, "", false) loginButton2 = guiCreateStaticImage(553, 447, 178, 100, "loginBut.png", false,test) addEventHandler("onClientGUIClick",loginButton2, tryLogin, false) GuiSetEnabled(test,false) GuiSetEnabled(test2,false) GuiSetEnabled(test3,false) dxDrawImage(405, 212, 462, 333, "bg1.png",0, 0, 0, tocolor(255, 255, 255, 255), true) end end addEventHandler("onPlayerJoin", getRootElement(), login)
TAPL Posted October 28, 2013 Posted October 28, 2013 What a mess. player? source? GuiSetEnabled? dxDrawImage? onClientRender? onPlayerJoin is server side.
Chopper Posted October 28, 2013 Author Posted October 28, 2013 They are there for testing purposes, i was trying to figure the problem out, thats why they are there.
Dealman Posted October 28, 2013 Posted October 28, 2013 You do realize that LUA is very case-sensitive right? GuiSetEnabled is not the same as guiSetEnabled. And as TAPL mentioned, you're not using parents. Thus when you click anywhere else, anything that is not a child of that parent - will be put behind the clicked GUI Element. Therefore, you will need an image to work as a window. And assign it as parent to everything else. test = guiCreateStaticImage(0, 300, 413, 150, "bg1.png", false, parentHere) You'll then have to isolate onClientGUIClick, so it doesn't run the function every time you click some element. An example would be; function exampleCode() if(source == exampleButton1) then -- Do your stuff here. end if(source == exampleButton2) then -- Do your other stuff here end end addEventHandler("onClientGUIClick", getRootElement(), exampleCode) You'll also need to use onClientRenderto draw DX Drawings. Be careful with this, since it runs the function it's assigned for with every frame. So if not careful, you could end up re-creating hundreds and even thousands of unwanted things, such as timers or whatever you use.
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