Detecting a certain space on-screen

So basically I’m trying to get when the player clicks on a part of the screen when gui.EnableScreenClicker is true.
I have these images that popup on screen and when the player clicks on them
I want things to happen, in my case send a net message to the server to perform a function.

For multiple instances of drawn boxes like the screenshot below:

Would I used the gui.MousePos()? If so how would I detect multiple boxes that were draw?
I apologize for my awful explanation, I’m not sure how else to describe this.

Just use GUI panels?

I have a lot of code I’d have to change, if I don’t absolutely have to I’d like to avoid it. Plus I wanted this to be like a quick popup menu that players could access while still moving around. With dframes it seems to stay open and not toggle correctly.

[editline]17th November 2016[/editline]

Would something like this work?



       --align being a table with 4 keys in it

hook.Add("GUIMousePressed", "detectMouse", function(mc)
	for i = 1, #align do
		if gui.MousePos().x > ScrW()/2-110+(i*40)
			--
		end
	end
end

You really should be using the VGUI panels for something like this, especially since you have a large amount of elements you need clickable. You can easily allow players to still move around by just disabling keyboard input on the panel.
[lua]
DFrame:MakePopup()
DFrame:SetKeyboardInputEnabled(false)
[/lua]
With toggling, how are you opening the panel? Chat command, key, button?

I decided I’d switch to a vgui panel, I haven’t been able to get a panel to pop up temporarily like when the player holds down a key, then when the player lets the key go the panel disappears.
I’ve been trying to recreate the spell system from Eternal Darkness: https://youtu.be/4rszOYiPllM?t=21 I have no clue though how to do a few different things.
I also really suck at any kinda gui things.

Ah, alright. Hopefully this is a help to you then. To make a frame toggle, you need to check if a key is down and the frame isn’t active. After that’s passed, create the frame. To make the frame close when the key is released, simply close the frame if the frame is active, but the key isn’t down.

Here’s an example for ya:
[lua]
local DermaFrame – localize the frame

local function openDFrame()
– creating the frame
DermaFrame = vgui.Create(“DFrame”)
DermaFrame:SetSize(400, 400)
DermaFrame:Center()
DermaFrame:MakePopup()
DermaFrame:SetKeyboardInputEnabled(false) – allows players to move around
end

local toggle_key = KEY_J – the toggle key (uses key enums)

hook.Add(“Think”, “checkForKeyDown”, function()
– checks if the key is down, but the frame isn’t active (prevents multiple frames opening)
if (input.IsKeyDown(toggle_key) and not IsValid(DermaFrame)) then
openDFrame() – call our function to create the frame
– checks if the key is NOT down, but only continues if the frame is active
elseif (not input.IsKeyDown(toggle_key) and IsValid(DermaFrame)) then
DermaFrame:Remove() – removes the frame
end
end)
[/lua]

Just wondering on this example here, would it be better to
use the SetVisible() function on the frame after creating it instead of just removing it? Or does it matter
whether you set it visible or remove it? I had a function within the hook PlayerButtonDown/Up to set a panel
to toggle IsVisible()