3d2d button not working

Hello!

I’m trying to make a 3d2d button inside a panel which is drawn on a prop (a model).
I’ve managed to draw the panel properly, but I’m struggling to make a functional button in the panel (simple, just press E pointing at the button and something happens).

I’ve took some code from the internet (CallMePyro - an user in Facepunch forums), but it won’t register the button properly.
What happens when I run the code below, is that when I point at the entity, sometimes really near the actual button, I get a message in the console.
However, when I look away, i’m still getting the message. If I go far enough, I stop getting the message, but then if I look anywhere near the prop, the message triggers again.

cl_init code:


 include("shared.lua")

function ENT:Initialize()
	ArmButton = Color(51, 172, 0,90)
	
end
function ENT:Draw()
	ply = LocalPlayer()
	self:DrawModel()
	dist = self:GetPos() - ply:GetPos()
        // -- ((((ANOTHER METHOD FOR THE BUTTON -- This doesn't even recognize me looking at the entity))))
	//if (dist < 750) then
		//if util.GetPlayerTrace(ply, ang).Entity and util.GetPlayerTrace(ply, ang).Entity == self then 
        	//print("Entity is explosive")
           // localTrace = self:WorldToLocal( util.GetPlayerTrace().HitPos )
           //	print (localtrace.x .. " " .. localtrace.y )
           // if localTrace.x > -1.595 and localTrace.x < -1.595 + 1.595 and localTrace.y > -30 and localTrace.y < 0 + h then
    		//	ArmButton = Color (81, 102, 0, 100)
    		//end
    	//end
    //end
    // -- ACTUAL CODE
    local Vector_M = FindMetaTable( "Vector")
    local Dot = Vector_M.Dot
    local scale = 0.11
	local pos = self:GetPos()
	local Ang = self:GetAngles()
	local b1tl = pos + Ang:Up() * 10 + Vector(-14.5, -20, 0) * scale
	local tr = Vector (14.5, -20, 0) * scale
	local bl = Vector (-14.5, 0, 0) * scale
	//-- CallMePyro's code
	local isec = util.IntersectRayWithPlane( ply:EyePos(), EyeAngles():Forward(), b1tl, Ang:Up() * 10) // he añadido * 10 al final

		local ap = pos - isec
		local ab = pos - tr
		local ad = pos - bl

		local ap_ab = Dot( ap, ab )
		local ab_ab = Dot( ab, ab )
		local ap_ad = Dot( ap, ad )
		local ad_ad = Dot( ad, ad )

		if 0 < ap_ab and ap_ab < ab_ab and 0 < ap_ad and ap_ad < ad_ad 
		and ply:IsLineOfSightClear(isec) then
			print("LOOKING AT BUTTON!!!!! :D")

		end
	end

	local text = "Timed Explosives"
	local text2 = "Not primed"
	local text3 = "Arm"
	local TextWidth = surface.GetTextSize(text)
	local TextWidth2 = surface.GetTextSize(text2)
	local TextWidth3 = surface.GetTextSize(text3)
	// COORDENADAS BOTON 29, 0

	Ang:RotateAroundAxis(Ang:Up(), 90)

	cam.Start3D2D(pos + Ang:Up() * 10, Ang, scale)
	    draw.RoundedBox( 2, -65, -65, 137, 130, Color(184, 166, 0,30) )
		draw.WordBox(2, -TextWidth*0.5, -60, text, "Trebuchet18", Color(184, 166, 0, 100), Color(255,255,255,255))
		draw.WordBox(2, -TextWidth2*0.5, -30, text2, "Trebuchet18", Color(200, 10, 0,90), Color(255,255,255,255))
		draw.WordBox(2, -TextWidth3*0.5, 0, text3, "Trebuchet18", ArmButton, Color(255,255,255,255))
	cam.End3D2D()
end

function ENT:Think()
	
end



I’m sorry for being so confusing, it’s actually hard to describe.
If somebody could shed some light on how to implement buttons in 3d2d, I’d thank you so much.
Again, I’ve tried like 3 different methods with no results. This is the only one that did even recognize something.

Greetings

For the record, do not // every line you don’t want to work. Block commenting works using --[[ comment here, can be multiple lines ]] and you don’t need // if you have –

Thanks for the tip!

EDIT:

Oh , and by the way, if someone wants to help , that’s okay, but I finally solved it using the 3d2d imgui library (which I think it’s simpler to use).
If someone’s got a way to make it work natively without dependencies, I’d appreciate.

Dunno how to exactly do it (as I’ve been months without coding due to moving) but get the position of the cursor relative to the screen and overwrite ENT:Use() to do what you want it to do. (might have to be shared)

Also, in the shared file, put in ENT:Initialize(), self:SetUseType(SIMPLE_USE) if you are gonna do the use method, that way it doesn’t spam it if someone uses it.