CsaliHUN

Click on Object NEED HELP

Recommended Posts

Hi everyone!
Can someone help me that, if I click on specified object, then run a function named "startit1"

Share this post


Link to post

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.

Share this post


Link to post

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 by CsaliHUN

Share this post


Link to post

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 )

 

Share this post


Link to post

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 by NeXuS™

Share this post


Link to post

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 )

 

Share this post


Link to post

Yeah.

Share this post


Link to post

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 )

 

Share this post


Link to post

What do you mean by "when the cursor is on the object."?

Share this post


Link to post
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)

 

Share this post


Link to post
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.

Share this post


Link to post

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 account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.