Snow-Man Posted January 26, 2014 Share Posted January 26, 2014 how can i make Dx Rectangle button i know functions but i need example Link to comment
Bonsai Posted January 26, 2014 Share Posted January 26, 2014 how can i make Dx Rectangle button i know functions but i need example Example would basically be the whole code. You need to get the cursor position and check if its on the button. Not that hard. If it's on the button u could change the alpha or something so players get a response. Link to comment
Dealman Posted January 26, 2014 Share Posted January 26, 2014 If you know the functions, then try to make it instead of expecting it to be served on silver platter. If you're having trouble, post the code you've got and we'll try to help from there. There are various ways to achieve this. Link to comment
Karuzo Posted January 26, 2014 Share Posted January 26, 2014 Just like bonsai said , you could make an button over you rectangel , set its alpha to 0 so you cant see it , and just handle it like a normal button. button = guiCreateButton(x,y,w,h, "button", false) guiSetAlpha(button, 0) dxDrawRectangle(x,y,w,h) function buttonclick() --your code end addEventHandler("onClientGUIClick", button , buttonclick) Link to comment
Gallardo9944 Posted January 26, 2014 Share Posted January 26, 2014 or check if cursor position is within some range and trigger some function you need. onClientClick would help with it. Link to comment
McDeKi Posted January 26, 2014 Share Posted January 26, 2014 function DrawRectangle() x, y = guiGetScreenSize() local check = isMouseWithinRangeOf(x*0,x*0.5,y*0,y*0.5) -- start x, width, start y, height if check then dxDrawRectangle(x*0,y*0,x*0.5,y*0.5,tocolor(0,0,0,180)) end end addEventHandler("onClientRender",resourceRoot,DrawRectangle) function isMouseWithinRangeOf(psx,pssx,psy,pssy) if not isCursorShowing() then return false end local cx,cy = getCursorPosition() cx,cy = cx*x,cy*y if cx >= psx and cx <= psx+pssx and cy >= psy and cy <= psy+pssy then return true,cx,cy else return false end end Gallardo gave me this code and it works perfect Link to comment
Gallardo9944 Posted January 26, 2014 Share Posted January 26, 2014 and you can add a click checker to the code above: function onClick() local check = isMouseWithinRangeOf(x*0,x*0.5,y*0,y*0.5) -- start x, width, start y, height if check then outputChatBox("you have pressed inside the rectangle") end end addEventHandler("onClientClick",getRootElement(),onClick) Link to comment
McDeKi Posted January 26, 2014 Share Posted January 26, 2014 (edited) you can also do this with onClientRender, if you want for example smooth move camera local x1 = 50 local y1 = 50 local z1 = 50 function onClick() local x,y = guiGetScreenSize() setCameraMatrix(x1,y1,z1,50,50,50) local check = isMouseWithinRangeOf(x*0,x*0.5,y*0,y*0.5) -- start x, width, start y, height if getKeyState("mouse1") == true then if check then x1 = x1 + 0.2 y1 = y1 - 0.02 end end addEventHandler("onClienRender",getRootElement(),onClick) Edit: Gallardo you are fast, I noticed that and changed it after 30 seconds. Edited January 26, 2014 by Guest Link to comment
Gallardo9944 Posted January 26, 2014 Share Posted January 26, 2014 @McDeKi, the code is going to bug as far as you set "x" to be "50" and you set "x" to be the screen width. Use different variable names for the positions. EDIT: yeah, i'm fast, more than 500 hoursepowers... Link to comment
xXMADEXx Posted January 26, 2014 Share Posted January 26, 2014 You can use examples from these resources that i've made that have DX buttons: http://www.mediafire.com/download/gbkal ... -login.zip https://community.multitheftauto.com/ind ... ls&id=7970 Here's a basic example: local rectangleData = { x = 0, y = 0, width = 100, height = 20 } addEventHandler ( "onClientRender", root, function ( ) dxDrawRectangle ( rectangleData.x, rectangleData.y, rectangleData.width, rectangleData.height, tocolor ( 0, 0, 0, 120 ) ) end ) addEventHandler ( "onClientClick", root, function ( _, _, x, y ) if ( x >= rectangleData.x and x <= rectangleData.x + rectangleData.width and y >= rectangleData.y and y <= rectangleData.y + rectangleData.height ) then outputChatBox ( "On rectangle click!" ) end end ) 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