Jump to content

Button


fsdfdsf

Recommended Posts

Read about the functions and events TAPL just provided you thoroughly and you'll be able to figure something out. You can't live on examples all of your life, eh? ;)

Give it some time, test things out. Scripting and programming involves a whole lot of trial and error, see what you can come up with and we'll help you from there buddy :)

Just think of it logically, write it down if you think it helps.

Say you want to create a button:

1. First you'll need a way to check if the cursor is currently within the area. For this you can use Castillo's function isMouseInPosition (I renamed it to isCursorWithin).

2. Secondly, once you have a way to check if the cursor is within the button's area, you'll need to detect whenever the mouse is clicked. onClientClick should do the trick! Remember to read about the parameters it passes to your function.

3. Thirdly, use those together and use outputChatBox to see if it works. It should only output a message if you click within the button's area.

Editboxes are a bit tougher to make, so start with the button.

Edited by Guest
Link to comment

ty alot man, i hve this

local x, y = guiGetScreenSize() 
  
bindKey("F2", "down", 
    function() 
        start = getTickCount() 
        addEventHandler("onClientRender", getRootElement(), logo) 
end) 
  
  
function logo() 
    showCursor(true) 
    local showing = isCursorShowing () 
    if showing then -- if the cursor is showing 
    local screenx, screeny, worldx, worldy, worldz = getCursorPosition() 
    jaja = dxDrawRectangle ( x/3.8, y/3.8, x/2.02, y/2, tocolor ( 0, 0, 0, 150 ) ) 
    end 
    destroyElement(jaja) 
end 
addEventHandler ( "onClientClick", getRootElement(), logo ) 
  

give me an example from you,idk how to puzzle the codes

but example with castillo code not getCursorPosition

Link to comment

Example:

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 ) 
    if ( cx >= x and cx <= x + width ) and ( cy >= y and cy <= y + height ) then 
        return true 
    else 
        return false 
    end 
end 
  
addEventHandler("onClientRender", root, 
function() 
    local imgX, imgY, imgWidth, imgHeight = 50, 50, 200, 200 
    buttonHover = isMouseInPosition(imgX, imgY, imgWidth, imgHeight) 
    dxDrawImage(imgX, imgY, imgWidth, imgHeight, buttonHover and "myImage2.png" or "myImage.png", tocolor(255, 255, 255)) 
end) 
  
addEventHandler("onClientClick", root, 
function(button, state) 
    if button == "left" and state == "down" then 
        if buttonHover then 
            outputChatBox("Button clicked!") 
        end 
    end 
end) 

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