Jump to content

On GUI Click Problem


3B00DG4MER

Recommended Posts

Posted

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) 

Posted

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.

Posted
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 ?

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

Posted
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

Posted

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

Posted

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) 

Posted (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 by Guest
Posted
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

Posted

You can think about some math too :P

local gCursor_pX, gCursor_pY = getCursorPosition() 
local sWidth, sHeight = guiGetScreenSize() 
gCursor_pX, gCursor_pY = gCursor_pX*sWidth, gCursor_pY*sHeight 

Posted
You can think about some math too :P
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

Posted

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

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