Jump to content

Ayuda dxButton


iSmokee

Recommended Posts

Posted

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) 
  

  • MTA Team
Posted

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.

Posted (edited)

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
Posted

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.

Posted
Usando la idea de Alexs

Es una pésima idea, nunca he recomendado ni recomendaría utilizar algo así.

Era la idea de Ciber, señor que no se equivoca

Posted

no quiero crear un boton -.- el boton ya esta creado lo que quiero que cuando el mouse pase x ese boton se cree un elemento como por ejemplo una m4

  • MTA Team
Posted
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.

Posted

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 

Posted

Si hablas con xiti y le pides derechos para usar su libreria dx, te enseño a usarla, es mucho mas optimo usar algo ya existente, a crearlo.

  • Recently Browsing   0 members

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