CsaliHUN Posted August 8, 2017 Share Posted August 8, 2017 Hi everyone! Can someone help me that, if I click on specified object, then run a function named "startit1" Link to comment
NeXuS™ Posted August 8, 2017 Share Posted August 8, 2017 If you are on client-side, you can use onClientClick event which has an arg to describe the clicked element. If you are on server-side, you can use onElementClicked event. Link to comment
CsaliHUN Posted August 8, 2017 Author Share Posted August 8, 2017 (edited) function openthegui if getElementType ( targetElem ) == "object" and getElementModel ( targetElem ) == 2778 then if showing then removeEventHandler("onClientRender", getRootElement(), renderFunc) game:destroy() window:destroy() showCursor(false) showing = false else window = DXWindow(sx/2-(319+10)/2, sy/2-(421+30)/2,319+10, 421+30, "Dream Life - Arcade - 2048", tocolor(255, 136, 0, 150)) window:setMoveable(true) showCursor(true) game = Game(window.x + 5,window.y + 25, highscore) game:setParent(window) addEventHandler("onClientRender", getRootElement(), renderFunc) showing = true end addEventHandler ( "onClientClick", getRootElement(), openthegui ) Is this good? Sry for bad english Edited August 8, 2017 by CsaliHUN Link to comment
NeXuS™ Posted August 8, 2017 Share Posted August 8, 2017 You can use the getElementModel function to determine the element's object ID. Link to comment
CsaliHUN Posted August 8, 2017 Author Share Posted August 8, 2017 Currently I made this, but it doesn't works function openthegui if getElementType ( clickedElement ) == "object" and getElementModel ( clickedElement ) == 2778 then if showing then removeEventHandler("onClientRender", getRootElement(), renderFunc) game:destroy() window:destroy() showCursor(false) showing = false else window = DXWindow(sx/2-(319+10)/2, sy/2-(421+30)/2,319+10, 421+30, " ", tocolor(255, 136, 0, 150)) window:setMoveable(true) showCursor(true) game = Game(window.x + 5,window.y + 25, highscore) game:setParent(window) addEventHandler("onClientRender", getRootElement(), renderFunc) showing = true end addEventHandler ( "onClientClick", getRootElement(), openthegui ) Link to comment
NeXuS™ Posted August 8, 2017 Share Posted August 8, 2017 (edited) Because your function is not even functioning as a function. To create a function, you have to use parenthesis (), and then you have args in that function. Check the wiki page of the onClientClick event for further info about those args. Edited August 8, 2017 by NeXuS™ Link to comment
CsaliHUN Posted August 8, 2017 Author Share Posted August 8, 2017 Like this? function openthegui ( button, state, absoluteX, absoluteY, worldX, worldY, worldZ, clickedElement ) if getElementType ( clickedElement ) == "object" and getElementModel ( clickedElement ) == 2778 then if showing then removeEventHandler("onClientRender", getRootElement(), renderFunc) game:destroy() window:destroy() showCursor(false) showing = false else window = DXWindow(sx/2-(319+10)/2, sy/2-(421+30)/2,319+10, 421+30, " ", tocolor(255, 136, 0, 150)) window:setMoveable(true) showCursor(true) game = Game(window.x + 5,window.y + 25, highscore) game:setParent(window) addEventHandler("onClientRender", getRootElement(), renderFunc) showing = true end addEventHandler ( "onClientClick", getRootElement(), openthegui ) Link to comment
CsaliHUN Posted August 9, 2017 Author Share Posted August 9, 2017 okay, it didn't worked for me, so I started over Like this, but it only opens up when the cursor is on the object. function openthegui ( button, state, absoluteX, absoluteY, worldX, worldY, worldZ, clickedElement ) if (guiGetVisible(GUIEditor.window[1])) then -- if the window is visible closeWindow() --close else guiSetVisible(GUIEditor.window[1], true) --else show the window setElementData(localPlayer,"2048_active",true,true) showCursor(true) end end addEventHandler ( "onClientClick", getRootElement(), openthegui ) Link to comment
NeXuS™ Posted August 9, 2017 Share Posted August 9, 2017 What do you mean by "when the cursor is on the object."? Link to comment
CsaliHUN Posted August 9, 2017 Author Share Posted August 9, 2017 it only appears when i still holding the cursor on the object Link to comment
NeXuS™ Posted August 9, 2017 Share Posted August 9, 2017 function openthegui(button, state, absoluteX, absoluteY, worldX, worldY, worldZ, clickedElement) if state == "down" then if(guiGetVisible(GUIEditor.window[1])) then -- if the window is visible closeWindow() --close else guiSetVisible(GUIEditor.window[1], true) --else show the window setElementData(localPlayer,"2048_active",true,true) showCursor(true) end end end addEventHandler("onClientClick", getRootElement(), openthegui) Link to comment
_DrXenon Posted August 9, 2017 Share Posted August 9, 2017 8 hours ago, CsaliHUN said: it only appears when i still holding the cursor on the object Just to make it clear, it only appears while holding or pressing the mouse button because you did not set the state of the button 'up' or 'down'. This way the function will be triggered twice, when you press and when you release the button so it shows up when you press and fades away when hou release because the function was triggered again. < I gave you this advice just in case you did not understand what @NeXuS™ done, and so you dont miss that detail in the future. Link to comment
CsaliHUN Posted August 10, 2017 Author Share Posted August 10, 2017 (edited) thanks a lot! Now it works beautiful! Edited August 10, 2017 by CsaliHUN 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