Jump to content

Ayuda dxButton


iSmokee

Recommended Posts

Tengo este codigo que es un dxButton que lo dieron aqui en el forum lo que necesito es que me ayuden para que cuando pase el mouse por el boton me cree un objeto y si sale del boton que se borre si alguien sabe como podria hacer eso se lo agradeceria muchisimo.

  
local xxx, yyy, www, hhh = 0.037, 0.33, 0.220, 0.03 
  
function equipamiento() 
dxDrawRectangle(xxx*sW, yyy*sH, www*sW, hhh*sH, color3, false) 
dxDrawText ( 'Equipamientos', (60/mi_x)*user_x, (255/mi_y)*user_y, (0/mi_x)*user_x, (30/mi_y)*user_y, tocolor ( 255, 255, 255, 255 ), 1, "default-bold" ) 
 showCursor(true) 
    if isCursorShowing() then 
    sX, sY, _, _, _ = getCursorPosition() 
        if sX >= xxx and sX <= xxx+www and sY >= yyy and sY <= yyy+hhh then 
            color3 = tocolor(255, 255, 255, 150) 
        else 
            color3 = tocolor(0, 0, 0, 210)   
        end 
    end 
end 
  
addEventHandler("onClientClick", getRootElement(), 
function(button, state, px, py) 
    if (button == "left" and state == "down") then 
        if (px > xxx*sW and px < (xxx+www)*sW and py > yyy*sH and py < (yyy+hhh)*sH) then 
            if(isEventHandlerAdded("onClientRender", getRootElement(getThisResource()), equipamiento)) then 
  
            end 
        end 
    end 
end) 
  

Link to comment
  • Administrators

Crea un botón GUI en la misma posición que tu botón dx y usa

guiSetAlpha 

Tu otra alternativa, un poco más compleja es usar aritmética para calcular la posición de tu cursor en relación al tamaño total de tu botón dx.

Link to comment

Usando la idea de CIBER te dejo un ejemplo,

  
  
theSuperButton = guiCreateButton(bla bla bla bla) 
  
addEventHandler("onClientMouseEnter",theSuperButton,function() 
if (source == theSuperButton) then 
-- Aqui lo del objeto 
end 
end 
) 
  
addEventHandler("onClientMouseLeave",theSuperButton,function() 
if (source == theSuperButton) then 
-- Aqui se va e.e 
end 
end 
) 
  

Crea un GuiButton y usa

  
setGuiAlpha 
  

Haaaaaaaaa nooooooooooob, nah mentira xD

Edited by Guest
Link to comment

Si quieres algo realmente eficiente, crea las posiciones y dimensiones de tu objeto en una tabla, luego crea una usefull que te la reciba y y que cree el evento para ese botón. Así te ahorras estar haciendo un evento para cada botón y generalizas tu código, después hasta lo puedes re-utilizar sin necesidad de estar haciendo todo de nuevo.

Link to comment
  • Administrators
Si quieres algo realmente eficiente, crea las posiciones y dimensiones de tu objeto en una tabla, luego crea una usefull que te la reciba y y que cree el evento para ese botón. Así te ahorras estar haciendo un evento para cada botón y generalizas tu código, después hasta lo puedes re-utilizar sin necesidad de estar haciendo todo de nuevo.
Tu otra alternativa, un poco más compleja es usar aritmética para calcular la posición de tu cursor en relación al tamaño total de tu botón dx.

Creo que no entendiste lo que se te planteo mas arriba. El botón solo sería para poder usar el evento, ya que no existe uno para elementos dx.

Edit: Acabo de ver esta libreria https://forum.multitheftauto.com/viewtopic.php?f=108&t=83205 no se que tal funcionará y demás pero incluye lo que vos necesitas. Dale un intento y nos comentas.

Link to comment

Es lo mismo que esta haciendo con el Color del Rectagle... solo que ponle createObject y destroyElement.

PD: No es necesario que crees un boton normal y lo pongas encima del Dx.

  
if isCursorShowing() then 
    sX, sY, _, _, _ = getCursorPosition() 
        if sX >= xxx and sX <= xxx+www and sY >= yyy and sY <= yyy+hhh then 
            color3 = tocolor(255, 255, 255, 150) 
            --createObject 
        else 
            color3 = tocolor(0, 0, 0, 210)  
            --destroyElement 
        end 
end 

Link to comment
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...