3B00DG4MER Posted August 6, 2014 Share Posted August 6, 2014 Hi Guys i've make 2 buttons as Dx Rectangle but if i add event "onClientGUIClick" but it not working i tried to add outputchatbox on event but same anyone help here is Client: dxDrawText("Username", 478, 441, 597, 493, tocolor(255, 255, 255, 255), 1.00, bigfont, "center", "center", false, false, true, false, false) dxDrawText("Password", 480, 507, 597, 552, tocolor(255, 255, 255, 255), 1.00, bigfont, "center", "center", false, false, true, false, false) addEventHandler ( "onClientGUIClick", root, function() if source == login or source == register then outputChatBox("Test !!") end end) Link to comment
Et-win Posted August 6, 2014 Share Posted August 6, 2014 Where are 'login' and 'register' defined? Ow and btw, you know you are adding the 'addEventHandler's now by every frame? That's really bad. Link to comment
3B00DG4MER Posted August 6, 2014 Author Share Posted August 6, 2014 Where are 'login' and 'register' defined?Ow and btw, you know you are adding the 'addEventHandler's now by every frame? That's really bad. So i have to add the Event on onClientRender with Dx ? Link to comment
Et-win Posted August 6, 2014 Share Posted August 6, 2014 No... Is this actually the real code? Because that addEventHandler has not to be on the function which is on onClientRender. Link to comment
3B00DG4MER Posted August 6, 2014 Author Share Posted August 6, 2014 (edited) You want see the real ? here is Client: Sorry Guys but i have to delete it it was a complete scrip Edited August 6, 2014 by Guest Link to comment
Et-win Posted August 6, 2014 Share Posted August 6, 2014 dxDrawText This code returns a boolean only. (true or false) This means you cannot use it as element to check or it was pressed. You have to do this with positions or GUI. Link to comment
3B00DG4MER Posted August 6, 2014 Author Share Posted August 6, 2014 dxDrawText This code returns a boolean only. (true or false) This means you cannot use it as element to check or it was pressed. You have to do this with positions or GUI. i tried rectangle Link to comment
Et-win Posted August 6, 2014 Share Posted August 6, 2014 Also 'dxDrawRectangle' returns a boolean only. Almost all DX codes do that. addEventHandler ( "onClientGUIClick", root, function() local gCursor_pX, gCursor_pY = getCursorPosition() 480, 590, 122, 52 if (gCursor_pX > 480) and (gCursor_pY > 590) and (gCursor_pX < 480+122) and (gCursor_pY < 590+52) then outputChatBox("Test !!") end end) This would work in your case. (If I didn't do anything wrong) Atleast you can understand what I'm trying to do out of this. I'm checking or the cursor is between the 'dxDrawRectangle' (Login Button) code as soon as you clicked. If you are going to do it on this way, I prefer a variable for the positions, because if you ever want to change the positions, you don't have to change all positions in the script, only the variable you would have to change by then. Link to comment
Et-win Posted August 6, 2014 Share Posted August 6, 2014 If you type /debugscript 3 you get any errors. Then you would know I forgot to remove "480, 590, 122, 52" out of my code, lol. addEventHandler ( "onClientGUIClick", root, function() local gCursor_pX, gCursor_pY = getCursorPosition() if (gCursor_pX > 480) and (gCursor_pY > 590) and (gCursor_pX < 480+122) and (gCursor_pY < 590+52) then outputChatBox("Test !!") end end) Link to comment
3B00DG4MER Posted August 6, 2014 Author Share Posted August 6, 2014 (edited) If you type /debugscript 3 you get any errors. Then you would know I forgot to remove "480, 590, 122, 52" out of my code, lol. addEventHandler ( "onClientGUIClick", root, function() local gCursor_pX, gCursor_pY = getCursorPosition() if (gCursor_pX > 480) and (gCursor_pY > 590) and (gCursor_pX < 480+122) and (gCursor_pY < 590+52) then outputChatBox("Test !!") end end) i removed them if i tried: addEventHandler ( "onClientGUIClick", root, function() local gCursor_pX, gCursor_pY = getCursorPosition() outputChatBox(gCursor_pX.." "..gCursor_pY) end end) it output only on GUI elements only !! Edited August 6, 2014 by Guest Link to comment
Et-win Posted August 6, 2014 Share Posted August 6, 2014 Anything on /debugscript 3? Did you look? Try this: outputChatBox(tostring(gCursor_pX).." "..tostring(gCursor_pY)) Link to comment
3B00DG4MER Posted August 6, 2014 Author Share Posted August 6, 2014 Anything on /debugscript 3? Did you look?Try this: outputChatBox(tostring(gCursor_pX).." "..tostring(gCursor_pY)) it output only on GUI elements only !! Link to comment
Et-win Posted August 6, 2014 Share Posted August 6, 2014 Change 'onClientGUIClick' to 'onClientClick'. Forgot that it indeed only clicks on GUI. Link to comment
3B00DG4MER Posted August 6, 2014 Author Share Posted August 6, 2014 Change 'onClientGUIClick' to 'onClientClick'. Forgot that it indeed only clicks on GUI. now it's output but it's output only between 0 and 1 mean if center x= 0.5 and y 0.5 remember that my screen size is: 1280 X 1024 Link to comment
Et-win Posted August 6, 2014 Share Posted August 6, 2014 You can think about some math too local gCursor_pX, gCursor_pY = getCursorPosition() local sWidth, sHeight = guiGetScreenSize() gCursor_pX, gCursor_pY = gCursor_pX*sWidth, gCursor_pY*sHeight Link to comment
3B00DG4MER Posted August 6, 2014 Author Share Posted August 6, 2014 You can think about some math too local gCursor_pX, gCursor_pY = getCursorPosition() local sWidth, sHeight = guiGetScreenSize() gCursor_pX, gCursor_pY = gCursor_pX*sWidth, gCursor_pY*sHeight works !!!!!!! ty hint:math is useful everywhere Link to comment
Et-win Posted August 6, 2014 Share Posted August 6, 2014 By the way, you can also create a GUI button on the same spot as the 'dxDrawRectangle'. Just make it invisible. Also always check with 'isElement' or the button has been created, if not, create it. Then you can just use 'onClientGUIClick'. As soon as you remove the 'dxDrawRectangle' code (When you remove the login screen) then destroy the GUI button with 'destroyElement'. 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