Jump to content

Click a un createObject


aka Blue

Recommended Posts

Posted

Bueno, como dice el título, tengo una variable llamada mesa1 la cual, crea una mesa en x lugar. Lo que quiero hacer es que al darle click haga una función.

¿Cómo podría hacerlo?

He intentado poner if source == mesa1 then pero nada. ¿Alguna solución?

Gracias.

Posted

probar:

local mesa1 =  createObject(model,x,y,z) 
  
function clickMesa1(mouse,buttonState,element) 
if(element == mesa1)then 
outputChatBox("you clicked in mesa1",source) 
end 
end 
addEventHandler("onPlayerClick",root,clickMesa1) 

Posted

Funciona pero no sé cómo hacer el trigger :c

local mesa1 = createObject(201, -2107.7, -2283.6001, 30.7, 0, 0, 320) 
  
function clickMesa1(mouse, buttonState, element, playerSource) 
        if (element == mesa1) then 
            triggerClientEvent(playerSource, "abrirMesa", playerSource) 
        end 
end 
addEventHandler("onPlayerClick",root,clickMesa1) 
  
--Client-side 
addEvent("abrirMesa", true) 
addEventHandler("abrirMesa", getRootElement(), 
    function ( ) 
        exports.gui:show('mesa') 
    end 
) 
  

Posted

Por que no usas onClientClick?

local mesa1 = createObject(201, -2107.7, -2283.6001, 30.7, 0, 0, 320) 
  
function clickMesa1(mouse, buttonState, element) 
        if element and element == mesa1 then 
            triggerClientEvent(source, "abrirMesa", source) 
        end 
end 
addEventHandler("onPlayerClick",root,clickMesa1) 
  
--Client-side 
addEvent("abrirMesa", true) 
addEventHandler("abrirMesa", getRootElement(), 
    function ( ) 
        exports.gui:show('mesa') 
    end 
) 
  

Posted

Mmm sigue sin hacer nada

mesa1= createObject(201, -2107.7, -2283.6001, 30.7, 0, 0, 320) 
  
function asda ( button, state, clickedElement ) 
        if clickedElement == mesa1 then 
            exports.gui:show('mesa') 
            outputChatBox("TEST1") 
        end 
end 
addEventHandler ( "onClientClick", getRootElement(), asda ) 

Posted
mesa1= createObject(201, -2107.7, -2283.6001, 30.7, 0, 0, 320) 
  
function asda ( button, state, _, _, _, _, _, clickedElement ) 
        if clickedElement == mesa1 then 
            exports.gui:show('mesa') 
            outputChatBox("TEST1") 
        end 
end 
addEventHandler ( "onClientClick", getRootElement(), asda ) 

Igual, ahora que lo pienso, creo que no sirve con elementos creados pero no pierdes nada intentando.

Posted

Que pasaría si en vez de esto pones la segunda opcion?, por curiosidad nada mas, nunca probé ni fui bueno en cliente

addEventHandler ( "onClientClick", getRootElement(), asda ) 

addEventHandler ( "onClientClick", localPlayer, asda ) 

Posted
Creo que hace lo mismo. Los problemas que me ha causado a veces getRootElement es que mostraba el panel a todos y eso era malo, xD.

Eso solo pasa si lo colocas en un trigger de server side a client side en vez de usar 'source' o 'client'

Posted
Creo que hace lo mismo. Los problemas que me ha causado a veces getRootElement es que mostraba el panel a todos y eso era malo, xD.

Eso solo pasa si lo colocas en un trigger de server side a client side en vez de usar 'source' o 'client'

Mmmm.

Posted
Que pasaría si en vez de esto pones la segunda opcion?, por curiosidad nada mas, nunca probé ni fui bueno en cliente
addEventHandler ( "onClientClick", getRootElement(), asda ) 

addEventHandler ( "onClientClick", localPlayer, asda ) 

Estarías poniendo el evento solo para el jugador local, me parece que no funcionaría así. Sólo funcionaria si clickeas en "localPlayer".

Posted

Si el elemento es server side, por qué no usas https://wiki.multitheftauto.com/wiki/OnElementClicked ?

The source of this event is the element that got clicked by the player.

mouseButton: A string representing the mousebutton that was clicked. This might be left, middle or right.

buttonState: A string representing what state the button clicked is in. This might be up or down.

playerWhoClicked: The player that clicked on the element

clickPosX: The X position in the world the player clicked at

clickPosY: The Y position in the world the player clicked at

clickPosZ: The Z position in the world the player clicked at

  • Recently Browsing   0 members

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