Hero192 Posted July 28, 2015 Share Posted July 28, 2015 Hello guys, i want to let the rectangle and Text color be changed after you the Cursor(Mouse) hit it and when it leave the color back like the first time. NOTE: If this way works for both of them TEXT & Rectangle its okay please give me just one example and i'll understand dxDrawText("BUY",538.0,380.0,611.0,398.0,tocolor(255,255,255,255),1.0,"arial","left","top",false,false,true) dxDrawRectangle(661.0,296.0,19.0,16.0,tocolor(0,0,0,200),false) Link to comment
GTX Posted July 28, 2015 Share Posted July 28, 2015 function isMouseInPosition(a, b, c, d) if not isCursorShowing() then return end local x, y = getCursorPosition() x, y = x*sx, y*sy if x >= a and y >= b and x <= a+c and y <= b+d then return true end return false end if isMouseInPosition(661, 296, 19, 16) then -- Do your thing end Link to comment
Hero192 Posted July 28, 2015 Author Share Posted July 28, 2015 I tried that but it gives me an Error (IT was giving the error before i add anything on it) ERROR: attempt to perform arithmetic on global 'sx' (a nil value) function isMouseInPosition(a, b, c, d) if not isCursorShowing() then return end local x, y = getCursorPosition() x, y = x*sx, y*sy if x >= a and y >= b and x <= a+c and y <= b+d then return true end return false end if isMouseInPosition(661, 296, 19, 16) then tocolor(150, 0, 0, 200) else tocolor(0, 0, 0, 200) end Link to comment
Dealman Posted July 28, 2015 Share Posted July 28, 2015 It's this function isMouseInPosition but he renamed the variables and seem to have forgotten to add this like; local sx, sy = guiGetScreenSize() Link to comment
GTX Posted July 28, 2015 Share Posted July 28, 2015 Didn't know that function was on wiki, lol. I copied it from another topic, where I helped someone and yeah, I forgot to add that. Anyways; if isMouseInPosition(661, 296, 19, 16) then dxDrawRectangle(661.0,296.0,19.0,16.0,tocolor(150,0,0,200),false) else dxDrawRectangle(661.0,296.0,19.0,16.0,tocolor(0,0,0,200),false) 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 ) if ( cx >= x and cx <= x + width ) and ( cy >= y and cy <= y + height ) then return true else return false end end Link to comment
Hero192 Posted July 28, 2015 Author Share Posted July 28, 2015 Now,it sends this ERROR and resource failed ERROR:attempt to call global 'isMouseInPosition' (a nil value) EDIT: does this function have an Event Handler? Link to comment
GTX Posted July 28, 2015 Share Posted July 28, 2015 function renderUI() dxDrawText("BUY",538.0,380.0,611.0,398.0,tocolor(255,255,255,255),1.0,"arial","left","top",false,false,true) if isMouseInPosition(661, 296, 19, 16) then dxDrawRectangle(661.0,296.0,19.0,16.0,tocolor(150,0,0,200),false) else dxDrawRectangle(661.0,296.0,19.0,16.0,tocolor(0,0,0,200),false) end end addEventHandler("onClientResourceStart", resourceRoot, function() addEventHandler("onClientRender", root, renderUI) 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 ) if ( cx >= x and cx <= x + width ) and ( cy >= y and cy <= y + height ) then return true else return false end end Link to comment
Dealman Posted July 28, 2015 Share Posted July 28, 2015 You can also write it like this in case you don't want to have a lot of if statements inside your function; dxDrawRectangle(661, 296, 19, 16, (isMouseInPosition(661, 296, 19,16) and tocolor(150, 0, 0, 200) or tocolor(0, 0, 0, 200)), false) Link to comment
Hero192 Posted July 28, 2015 Author Share Posted July 28, 2015 Thanks for everything GTX !! You must be PART OF MTA team 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