Jump to content

eventhandler


Recommended Posts

addEventHandler("onClientClick", root, function(key, state, cx, cy)
if isContactOpened == true then return end
        if key == "left" and state == "down" then
        if isCursorInBox(screenW * 0.4729, screenH * 0.3130, screenW * 0.0953, screenH * 0.0269) then
        isContactOpened = true
        addEventHandler("onClientRender",getRootElement(),contactBTN)
        else
        removeEventHandler("onClientRender",getRootElement(),contactBTN)
        isContactOpened = false
        end
    end
end)

mm.. How can i do this?

Link to comment
aBool = false

addEventHandler("onClientClick", root,
function(key, state, cx, cy)
      if aBool == false then
        if key == "left" and state == "down" then
        if isCursorInBox(screenW * 0.4729, screenH * 0.3130, screenW * 0.0953, screenH * 0.0269) then
		aBool = true
        addEventHandler("onClientRender",getRootElement(),contactBTN)
        else
        removeEventHandler("onClientRender",getRootElement(),contactBTN)
        aBool = false
        end
      end
	end
end)

 

Edited by #BrosS
Link to comment
local isContactOpened = false

addEventHandler("onClientClick", root, function(key, state, cx, cy)
	if key == "left" and state == "down" then	
		if isCursorInBox(screenW * 0.4729, screenH * 0.3130, screenW * 0.0953, screenH * 0.0269) then			
			if isContactOpened then
				removeEventHandler("onClientRender",getRootElement(),contactBTN)
				isContactOpened = false
			else
				addEventHandler("onClientRender",getRootElement(),contactBTN)
				isContactOpened = true
			end
		end
	end
end)

You're welcome.

Edited by Tails
  • Like 1
Link to comment
4 minutes ago, Tails said:

local isContactOpened = false

addEventHandler("onClientClick", root, function(key, state, cx, cy)
	if key == "left" and state == "down" then	
        if isCursorInBox(screenW * 0.4729, screenH * 0.3130, screenW * 0.0953, screenH * 0.0269) then			
			if isContactOpened then
          		removeEventHandler("onClientRender",getRootElement(),contactBTN)
				isContactOpened = false
			else
				addEventHandler("onClientRender",getRootElement(),contactBTN)
				isContactOpened = true
			end
		end
	end
end)

You're welcome.

just one thing is wrong :3

 

local isContactOpened = false

addEventHandler("onClientClick", root, function(key, state, cx, cy)
	if key == "left" and state == "down" then	
        if isCursorInBox(screenW * 0.4729, screenH * 0.3130, screenW * 0.0953, screenH * 0.0269) then			
			if isContactOpened then
				addEventHandler("onClientRender",getRootElement(),contactBTN)
				isContactOpened = true
            else
          		removeEventHandler("onClientRender",getRootElement(),contactBTN)
				isContactOpened = false

			end
		end
	end
end)

 

Link to comment

No, yours is just the opposite. You want a bool that says IsPanelVisible, if it is then remove the handler.

We know the panel is not visible at the start so we do

local isContactOpened = false

then onClick we check, is it opened? if it's not then we add the handler to show the panel and vice versa.

Nice try though ;-)

Link to comment
1 minute ago, Tails said:

No, yours is just the opposite. You want a bool that says IsPanelVisible, if it is then remove the handler.

We know the panel is not visible at the start so we do


local isContactOpened = false

then onClick we check, is it opened? if it's not then we add the handler to show the panel and vice versa.

Nice try though ;-)

ahm
noway m8 
he want to make the button pressed one time 
this is not a check for a gui open xD

Link to comment
5 minutes ago, 3laa33 said:

he want to make the button pressed one time 

 

4 hours ago, TheMOG said:

if i click again on the button, remove the event handler

@3laa33

I think he wants it toggled.

Your example will throw an error because it's trying to remove a handler that doesn't yet exist.

Edited by Tails
Link to comment
4 hours ago, TheMOG said:

if i click again on the button, remove the event handler

local isContactOpened = true

addEventHandler("onClientClick", root, function(key, state, cx, cy)
	if key == "left" and state == "down" then	
        if isCursorInBox(screenW * 0.4729, screenH * 0.3130, screenW * 0.0953, screenH * 0.0269) then			
			if isContactOpened == true then
				addEventHandler("onClientRender",getRootElement(),contactBTN)
				isContactOpened = false
			end
		end
	end
end)

well then it will be like this

Link to comment
1 minute ago, TheMOG said:

I want that, when player click on the button show the menu, if again click on the button hide the menu (remove the handler)

-_- then use this

 

isContactOpened = true

addEventHandler("onClientClick", root, function(key, state, cx, cy)
	if key == "left" and state == "down" then	
        if isCursorInBox(screenW * 0.4729, screenH * 0.3130, screenW * 0.0953, screenH * 0.0269) then			
			if isContactOpened == true then
				addEventHandler("onClientRender",getRootElement(),contactBTN)
				isContactOpened = false
            else
          		removeEventHandler("onClientRender",getRootElement(),contactBTN)
				isContactOpened = true

			end
		end
	end
end

 

Link to comment
3 minutes ago, 3laa33 said:

local isContactOpened = true

addEventHandler("onClientClick", root, function(key, state, cx, cy)
	if key == "left" and state == "down" then	
        if isCursorInBox(screenW * 0.4729, screenH * 0.3130, screenW * 0.0953, screenH * 0.0269) then			
			if isContactOpened == true then
				addEventHandler("onClientRender",getRootElement(),contactBTN)
				isContactOpened = false
			end
		end
	end
end)

well then it will be like this

 

All this does is adding multiple eventHandlers to contactBTN every time you left click.

  • Like 1
Link to comment

@3laa33 yeah but what happens when he needs to close it?

You didn't remove the event so it just keeps adding more.

What @Tails posted was the correct solution.

 

8 minutes ago, 3laa33 said:

-_- then use this

 


isContactOpened = true

addEventHandler("onClientClick", root, function(key, state, cx, cy)
	if key == "left" and state == "down" then	
        if isCursorInBox(screenW * 0.4729, screenH * 0.3130, screenW * 0.0953, screenH * 0.0269) then			
			if isContactOpened == true then
				addEventHandler("onClientRender",getRootElement(),contactBTN)
				isContactOpened = false
            else
          		removeEventHandler("onClientRender",getRootElement(),contactBTN)
				isContactOpened = true

			end
		end
	end
end

 

 

What this code does is

if isContactOpened then

add an event even tho the contact is open thus creating another contactBTN

no need to use == true unless checking for specific results if it has a var it will always return true.

you need to swap your add and remove handlers...

Link to comment
16 minutes ago, Mr.Loki said:

@3laa33 yeah but what happens when he needs to close it?

You didn't remove the event so it just keeps adding more.

What @Tails posted was the correct solution.

 

What this code does is

if isContactOpened then

add an event even tho the contact is open thus creating another contactBTN

no need to use == true unless checking for specific results if it has a var it will always return true.

you need to swap your add and remove handlers...

it won't addEvents if it's false so when you click then the event will be aded and isContactOpened = false
so when he click again it will be false so it will go to removeEvent

Edited by 3laa33
Link to comment

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.
×
×
  • Create New...