iSmokee Posted January 17, 2016 Share Posted January 17, 2016 (edited) Buenas tardes gente quisiera saber si me podrían ayudar a resumir este dxButton es que quiero hacer un shop de weapons y se haría muy largo todo.. menuRiflesX, menuRiflesY, menuRiflesW, menuRiflesH = 0.878, 0.774, 0.105, 0.037 function menuRifles() dxDrawRectangle(menuRiflesX*sW, menuRiflesY*sH, menuRiflesW*sW, menuRiflesH*sH, color7, false) dxDrawText ( 'Rifles', (1250/mi_x)*user_x, (601/mi_y)*user_y, (0/mi_x)*user_x, (30/mi_y)*user_y, setColor7, 1, "default-bold" ) if isCursorShowing() then sX, sY, _, _, _ = getCursorPosition() if sX >= menuRiflesX and sX <= menuRiflesX+menuRiflesW and sY >= menuRiflesY and sY <= menuRiflesY+menuRiflesH then color7 = tocolor(191, 191, 191, 254) setColor7 = tocolor( 7, 243, 179, 255 ) else color7 = tocolor(191, 191, 191, 200) setColor7 = tocolor( 0, 0, 0, 255 ) end end end addEventHandler("onClientClick", getRootElement(), function(button, state, px, py) if (button == "left" and state == "down") then if (px > menuRiflesX*sW and px < (menuRiflesX+menuRiflesW)*sW and py > menuRiflesY*sH and py < (menuRiflesY+menuRiflesH)*sH) then if(isEventHandlerAdded("onClientRender", getRootElement(getThisResource()), menuRifles)) then end end end end) podría ser con tablas? o no se alguna forma.. por que estas horas para copiar y pegar.. Edited January 18, 2016 by Guest Link to comment
starksZ Posted January 17, 2016 Share Posted January 17, 2016 No te recomiendo tablas usa isCursorOnElement que te ahorra varias lineas de esa aritmética. Link to comment
alex17 Posted January 18, 2016 Share Posted January 18, 2016 tal ves te sirva esta forma para que no estés haciendo botón por botón botones = { [1] = {posx = 0, posy = 0, width = 100, height = 100, r= 0, g = 0, b = 0, r2 = 100, g2 = 0, b2 = 0, title = "rifles", tr = 255, tg = 255, tb = 255, tr2 = 0, tg2 = 0, tb2 = 0}, [2] = {posx = 0, posy = 0, width = 100, height = 100, r= 0, g = 0, b = 0, r2 = 100, g2 = 0, b2 = 0, title = "click", tr = 255, tg = 255, tb = 255, tr2 = 0, tg2 = 0, tb2 = 0} } function menuRifles() for _, boton in ipairs(botones) do if isCursorOnElement(boton.posx, boton.posy, boton.width, boton.height) then dxDrawRectangle(boton.posx, boton.posy, boton.width, boton.height, tocolor(boton.r, boton.g, boton.b), false) dxDrawText (boton.tile, boton.posx, boton.posy, boton.posx + boton.width, boton.posy + boton.height, tocolor(boton.tr, boton.tg, boton.tb) , 1, "default-bold") else dxDrawRectangle(boton.posx, boton.posy, boton.width, boton.height, tocolor(boton.r2, boton.g2, boton.b2), false) dxDrawText (boton.tile, boton.posx, boton.posy, boton.posx + boton.width, boton.posy + boton.height, tocolor(boton.tr2, boton.tg2, boton.tb2) , 1, "default-bold") end end end function onBotonClick(button, state, px, py) if (button == "left" and state == "down") then for _, boton in ipairs(botones) do if isCursorOnElement(boton.posx, boton.posy, boton.width, boton.height) then ----- ----- ----- return end end end end function isCursorOnElement(x,y,w,h) local mx,my = getCursorPosition () local fullx,fully = guiGetScreenSize() cursorx,cursory = mx*fullx,my*fully if cursorx > x and cursorx < x + w and cursory > y and cursory < y + h then return true else return false end end Link to comment
iSmokee Posted January 18, 2016 Author Share Posted January 18, 2016 Gracias @alex17 :D Link to comment
alex17 Posted January 18, 2016 Share Posted January 18, 2016 Gracias @alex17 :D por nada Link to comment
Recommended Posts