Jump to content

Help! DxRectangle Urgent!


FlyingSpoon

Recommended Posts

Posted
----------------------- 
-- The Menu -- 
----------------------- 
function DxMenu() 
        font = dxCreateFont("Digital.ttf",30)  
        dxDrawRectangle(261, 125, 292, 287, tocolor(50, 160, 212, 144), false) 
        dxDrawRectangle(312, 196, 186, 43, tocolor(0, 0, 0, 255), false) 
        dxDrawRectangle(313, 197, 184, 41, tocolor(50, 160, 212, 255), false) 
        dxDrawLine(261, 170, 552, 170, tocolor(1, 1, 1, 219), 1, true) 
        dxDrawRectangle(312, 255, 186, 43, tocolor(0, 0, 0, 255), false) 
        dxDrawRectangle(313, 256, 184, 41, tocolor(50, 160, 212, 255), false) 
        dxDrawRectangle(312, 316, 186, 43, tocolor(0, 0, 0, 255), false) 
        dxDrawRectangle(313, 317, 184, 41, tocolor(50, 160, 212, 255), false) 
        closeBtn = dxDrawRectangle(481, 380, 70, 29, tocolor(0, 0, 0, 255), false) 
        dxDrawRectangle(482, 381, 68, 27, tocolor(50, 160, 212, 255), false) 
        dxDrawText("Game Settings", 359, 269, 431, 287, tocolor(255, 255, 255, 255), 1.00, "clear", "left", "top", false, false, true, false, false) 
        dxDrawText("Help Menu", 371, 210, 443, 228, tocolor(255, 255, 255, 255), 1.00, "clear", "left", "top", false, false, true, false, false) 
        dxDrawText("Coming Soon...", 359, 329, 431, 347, tocolor(255, 255, 255, 255), 1.00, "clear", "left", "top", false, false, true, false, false) 
        dxDrawText("Close", 498, 386, 534, 400, tocolor(255, 255, 255, 255), 1.00, "clear", "left", "top", false, false, true, false, false) 
        dxDrawText("Settings Menu", 335, 128, 434, 155, tocolor(0, 0, 0, 255), 1.00, font, "left", "top", false, false, true, false, false)      
end 
  
  
  
----------------------- 
  
----------------------- 
-- Menu Moved -- 
----------------------- 
function bindKeys() 
    bindKey("F1", "down", F1RPhelp) 
end 
addEventHandler("onClientResourceStart", getRootElement(), bindKeys) 
  
function resetState() 
    pressed = false 
end 
  
function F1RPhelp() 
outputChatBox("This menu has been moved to /settingsmenu!", 0, 179, 255) 
end 
---------------------- 
  
---------------------- 
-- Binded CMD -- 
---------------------- 
function cmdType() 
addEventHandler("onClientRender", getRootElement(), DxMenu) 
showCursor(true) 
end 
addCommandHandler("settingsmenu", cmdType) 
---------------------- 
  
----------------------- 
-- Clicks -- 
----------------------- 
function allClicks() 
if source == closeBtn then 
removeEventHandler("onClientRender", getRootElement(), DxMenu) 
  end 
end 
addEventHandler("onClientGUIClick", getRootElement(), allClicks) 
----------------------- 

I am trying to create a simple script, but when I press that DxRectangle the DxMenu doesn't close or dissapear :( !

Please help it's urgent please!

Posted

That's because DX drawing isn't interactive, you need to calculate the current cursor position with the dx rectangle position, and use the event onClientClick.

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted

Use this small function:

function isMouseInPosition ( x, y, width, height ) 
    if ( not isCursorShowing ( ) ) then 
        return false 
    end 
  
    local sx, sy = guiGetScreenSize ( ) -- Get the player screen resolution 
    local cx, cy = getCursorPosition ( ) -- Get the cursor position 
    local cx, cy = ( cx * sx ), ( cy * sy ) -- Convert relative positions to absolute 
    if ( cx >= x and cx <= x + width ) and ( cy >= y and cy <= y + height ) then 
        return true 
    else 
        return false 
    end 
end 

Then you can do this:

addEventHandler ( "onClientClick", root, 
    function ( ) 
        if isMouseInPosition ( 481, 380, 70, 29 ) then 
            outputChatBox ( "CLICKED!" ) 
        end 
    end 
) 

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted

Define a variable with the status of your interface.

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted

Define a global variable, then update the state inside the function "F1RPhelp".

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted (edited)
function bTest()   
tWindow = guiCreateWindow(233, 251, 297, 226, "", false) 
guiWindowSetSizable(tWindow, false)     
end 

----------------------- 
-- The Menu -- 
----------------------- 
function DxMenu() 
        font = dxCreateFont("Digital.ttf",30) 
        dxDrawRectangle(261, 125, 292, 287, tocolor(50, 160, 212, 144), false) 
        dxDrawRectangle(312, 196, 186, 43, tocolor(0, 0, 0, 255), false) 
        dxDrawRectangle(313, 197, 184, 41, tocolor(50, 160, 212, 255), false) 
        dxDrawLine(261, 170, 552, 170, tocolor(1, 1, 1, 219), 1, true) 
        dxDrawRectangle(312, 255, 186, 43, tocolor(0, 0, 0, 255), false) 
        dxDrawRectangle(313, 256, 184, 41, tocolor(50, 160, 212, 255), false) 
        dxDrawRectangle(312, 316, 186, 43, tocolor(0, 0, 0, 255), false) 
        dxDrawRectangle(313, 317, 184, 41, tocolor(50, 160, 212, 255), false) 
        closeBtn = dxDrawRectangle(481, 380, 70, 29, tocolor(0, 0, 0, 255), false) 
        dxDrawRectangle(482, 381, 68, 27, tocolor(50, 160, 212, 255), false) 
        gameSet = dxDrawText("Game Settings", 359, 269, 431, 287, tocolor(255, 255, 255, 255), 1.00, "clear", "left", "top", false, false, true, false, false) 
        dxDrawText("Help Menu", 371, 210, 443, 228, tocolor(255, 255, 255, 255), 1.00, "clear", "left", "top", false, false, true, false, false) 
        dxDrawText("Coming Soon...", 359, 329, 431, 347, tocolor(255, 255, 255, 255), 1.00, "clear", "left", "top", false, false, true, false, false) 
        dxDrawText("Close", 498, 386, 534, 400, tocolor(255, 255, 255, 255), 1.00, "clear", "left", "top", false, false, true, false, false) 
        dxDrawText("Settings Menu", 335, 128, 434, 155, tocolor(0, 0, 0, 255), 1.00, font, "left", "top", false, false, true, false, false)      
end 
  
  
  
----------------------- 
  
----------------------- 
-- Menu Moved -- 
----------------------- 
function bindKeys() 
    bindKey("F1", "down", F1RPhelp) 
end 
addEventHandler("onClientResourceStart", getRootElement(), bindKeys) 
  
function resetState() 
    pressed = false 
end 
  
function F1RPhelp() 
outputChatBox("This menu has been moved to /settingsmenu!", 0, 179, 255) 
end 
---------------------- 
  
---------------------- 
-- Binded CMD -- 
---------------------- 
function cmdType() 
addEventHandler("onClientRender", getRootElement(), DxMenu) 
showCursor(true) 
end 
addCommandHandler("settingsmenu", cmdType) 
---------------------- 
  
----------------------- 
-- Clicks -- 
----------------------- 
function allClicks() 
if source == closeBtn then 
removeEventHandler("onClientRender", getRootElement(), DxMenu) 
  end 
end 
addEventHandler("onClientGUIClick", getRootElement(), allClicks) 
----------------------- 

Here's an example, so what would I do next?

  
function clickIt() 
if source == gameSet then 
guiSetVisible(tWindow, true) 
  

Edited by Guest
Posted

Why are you creating a GUI window?

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted

dxDrawText only returns a boolean (true/false).

I told you to use onClientClick, use my example.

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted
Use this small function:
function isMouseInPosition ( x, y, width, height ) 
    if ( not isCursorShowing ( ) ) then 
        return false 
    end 
  
    local sx, sy = guiGetScreenSize ( ) -- Get the player screen resolution 
    local cx, cy = getCursorPosition ( ) -- Get the cursor position 
    local cx, cy = ( cx * sx ), ( cy * sy ) -- Convert relative positions to absolute 
    if ( cx >= x and cx <= x + width ) and ( cy >= y and cy <= y + height ) then 
        return true 
    else 
        return false 
    end 
end 

Then you can do this:

addEventHandler ( "onClientClick", root, 
    function ( ) 
        if isMouseInPosition ( 481, 380, 70, 29 ) then 
            outputChatBox ( "CLICKED!" ) 
        end 
    end 
) 

This example?

But when I click there for example a player click by accident, then the GUI will appear.

Posted

That's why you need to define a global variable specifying if the menu is open or not.

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted

Is it done like this?

addEventHandler ( "onClientClick", root, 
    function ( ) 
        if DxMenu then 
        if isMouseInPosition ( 481, 380, 70, 29 ) then 
        removeEventHandler("onClientRender", getRootElement(), DxMenu) 
        showCursor(false) 
        end 
    end 
end 
) 

Posted
local menuState = false -- Menu is hidden 

And then, inside your "F1RPhelp" function:

menuState = true -- Menu is visible 

Then you check if the menu is visible inside the onClientClick function:

addEventHandler ( "onClientClick", root, 
    function ( ) 
        if ( menuState ) then -- if the menu is visible... 
            if isMouseInPosition ( 481, 380, 70, 29 ) then 
                outputChatBox ( "CLICKED!" ) 
            end 
        end 
    end 
) 

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted

Like this?

  
----------------------- 
-- The Menu -- 
----------------------- 
function DxMenu() 
        font = dxCreateFont("Digital.ttf",30)  
        dxDrawRectangle(261, 125, 292, 287, tocolor(50, 160, 212, 144), false) 
        dxDrawRectangle(312, 196, 186, 43, tocolor(0, 0, 0, 255), false) 
        dxDrawRectangle(313, 197, 184, 41, tocolor(50, 160, 212, 255), false) 
        dxDrawLine(261, 170, 552, 170, tocolor(1, 1, 1, 219), 1, true) 
        dxDrawRectangle(312, 255, 186, 43, tocolor(0, 0, 0, 255), false) 
        dxDrawRectangle(313, 256, 184, 41, tocolor(50, 160, 212, 255), false) 
        dxDrawRectangle(312, 316, 186, 43, tocolor(0, 0, 0, 255), false) 
        dxDrawRectangle(313, 317, 184, 41, tocolor(50, 160, 212, 255), false) 
        dxDrawRectangle(481, 380, 70, 29, tocolor(0, 0, 0, 255), false) 
        dxDrawRectangle(482, 381, 68, 27, tocolor(50, 160, 212, 255), false) 
        gameSet = dxDrawText("Game Settings", 359, 269, 431, 287, tocolor(255, 255, 255, 255), 1.00, "clear", "left", "top", false, false, true, false, false) 
        dxDrawText("Help Menu", 371, 210, 443, 228, tocolor(255, 255, 255, 255), 1.00, "clear", "left", "top", false, false, true, false, false) 
        dxDrawText("Coming Soon...", 359, 329, 431, 347, tocolor(255, 255, 255, 255), 1.00, "clear", "left", "top", false, false, true, false, false) 
        closeBtn = dxDrawText("Close", 498, 386, 534, 400, tocolor(255, 255, 255, 255), 1.00, "clear", "left", "top", false, false, true, false, false) 
        dxDrawText("Settings Menu", 335, 128, 434, 155, tocolor(0, 0, 0, 255), 1.00, font, "left", "top", false, false, true, false, false)   
     
     
end 
  
  
  
----------------------- 
  
----------------------- 
-- Menu Moved -- 
----------------------- 
function bindKeys() 
    bindKey("F1", "down", F1RPhelp) 
end 
addEventHandler("onClientResourceStart", getRootElement(), bindKeys) 
  
function resetState() 
    pressed = false 
end 
  
function F1RPhelp() 
outputChatBox("This menu has been moved to /settingsmenu!", 0, 179, 255) 
DxMenu = true 
end 
---------------------- 
  
---------------------- 
-- Binded CMD -- 
---------------------- 
function cmdType() 
addEventHandler("onClientRender", getRootElement(), DxMenu) 
showCursor(true) 
end 
addCommandHandler("settingsmenu", cmdType) 
---------------------- 
  
---------------------- 
-- Test -- 
---------------------- 
function bTest()   
tWindow = guiCreateWindow(233, 251, 297, 226, "", false) 
guiWindowSetSizable(tWindow, false)     
end 
  
  
local DxMenu = false 
----------------------- 
-- Clicks -- 
----------------------- 
function isMouseInPosition ( x, y, width, height ) 
    if ( not isCursorShowing ( ) ) then 
        return false 
    end 
  
    local sx, sy = guiGetScreenSize ( ) -- Get the player screen resolution 
    local cx, cy = getCursorPosition ( ) -- Get the cursor position 
    local cx, cy = ( cx * sx ), ( cy * sy ) -- Convert relative positions to absolute 
    if ( cx >= x and cx <= x + width ) and ( cy >= y and cy <= y + height ) then 
        return true 
    else 
        return false 
    end 
end 
  
addEventHandler ( "onClientClick", root, 
    function ( ) 
        if ( DxMenu ) then 
        if isMouseInPosition ( 481, 380, 70, 29 ) then 
        outputChatBox("Hi") 
        removeEventHandler("onClientRender", getRootElement(), DxMenu) 
        showCursor(false) 
        end 
    end 
end 
) 
------------------------- 
  

local DxMenu = false

DxMenu = true

Posted

put font line outside DxMenu function

it just hurts me knowing that font would be created over 50 times in a second...

edit: please give information what debugscript 3 says

If you find my post useful or if it helped you, please like my post :)
Ingame name: ZoeN

560x95_FFFFFF_FF9900_000000_000000.png

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