Jump to content

give action to client buttons


MamadHastam

Recommended Posts

there is one thing i cant understand
how can i give actions to the buttons in client
for example when i write :

 

addEventHandler ("onClientClick", root, function(btn, state)
	if btn ~= "left" or state ~= "down" then return end
	
	if isMouseInPosition (xx*594, yy*396, xx*235, yy*300) then
		-- click 1-st button
	elseif isMouseInPosition (xx*840, yy*396, xx*235, yy*300) then
		-- click 2-nd button
	end
end)

function isMouseInPosition ( x, y, width, height )
	if ( not isCursorShowing( ) ) then
		return false
	end
	local sx, sy = guiGetScreenSize ( )
	local cx, cy = getCursorPosition ( )
	local cx, cy = ( cx * sx ), ( cy * sy )
	
	return ( ( cx >= x and cx <= x + width ) and ( cy >= y and cy <= y + height ) )
end

how give button 1 an action to do somthing
please explain it to me

Link to comment

To give the first button an action to do something, you can simply add the code that you want to execute when the button is clicked within the block of the first if statement

For example, if you want the first button to output a message to the chat when it is clicked, you can do something like this:

 

addEventHandler ("onClientClick", root, function(btn, state)
	if btn ~= "left" or state ~= "down" then return end
	
	if isMouseInPosition (xx*594, yy*396, xx*235, yy*300) then
		-- click 1-st button
		outputChatBox("Button 1 was clicked!")
	elseif isMouseInPosition (xx*840, yy*396, xx*235, yy*300) then
		-- click 2-nd button
	end
end)

You can also execute other functions or trigger other events when the button is clicked. Just replace the outputChatBox line with the code that you want to execute.

Link to comment

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