Selection Box

Hey all,
Can somebody help me with making something like this:

What I’m trying to make is the selection box you see in the movie by Blackops, I don’t need it to select or anything just the render from point to point, if you know what I mean, hope someone can help, Thanks

-Trivkz

Check if the mouse button is down, if it is and you aren’t already drawing a box, save the coords. Then continue to draw to the current cursor position until the mouse button is no longer down.

[lua]surface.DrawRect(Start.x, Start.y, End.x, End.y)[/lua]

etc.

Chould someone make me a example?

There’s other code in here you may want to take out, but here it is. Enjoy my terrible code.

[lua]
local debug = CreateClientConVar(“rts_debug”, “0”, true)
function GM:HUDPaint()
if input.IsMouseDown( MOUSE_RIGHT ) then
if !pressed2 then
pressed2 = true
local mousetrace = util.TraceLine( util.GetPlayerTrace( LocalPlayer(), gui.ScreenToVector( gui.MousePos() ) ) ).HitPos
local effectdata = EffectData()
effectdata:SetOrigin( mousetrace )
util.Effect( “select_ring”, effectdata )
RunConsoleCommand(“mouse2pressed”)
end
else
if pressed2 then
pressed2 = false
RunConsoleCommand(“mouse2released”)
end
end
if input.IsMouseDown( MOUSE_LEFT ) then
if hitstartx == 0 and hitstarty == 0 then
hitstartx, hitstarty = gui.MousePos()
hitendx, hitendy = gui.MousePos()

		if pressed1 == false then
			pressed1 = true
			RunConsoleCommand("mouse1pressed")
			SelectedObjects = {}
		end
	else
		if debug:GetBool() == true then
			local effectdata = EffectData()
			local mousetrace = util.TraceLine( util.GetPlayerTrace( LocalPlayer(), gui.ScreenToVector( gui.MousePos() ) ) ).HitPos
			effectdata:SetStart( mousetrace )
			effectdata:SetOrigin( mousetrace )
			effectdata:SetScale( 1 )
			util.Effect( "HelicopterMegaBomb", effectdata )
			
			surface.SetDrawColor( 255, 0, 0, 255 )
			surface.DrawLine( hitstartx, hitstarty, hitendx, hitendy )
			draw.SimpleTextOutlined(math.Round(math.Dist(hitstartx, hitstarty, hitendx, hitendy)), "ScoreboardText", hitendx, hitendy, Color(255,255,255,255), TEXT_ALIGN_RIGHT, TEXT_ALIGN_LEFT, 1, Color(0,0,0,255))
		end
		
		local boxstartx = 0
		local boxendx = 0
		local boxstarty = 0
		local boxendy = 0
		
		if hitstartx >= hitendx then
			boxstartx = hitstartx
			boxendx = hitendx
		else
			boxstartx = hitendx
			boxendx = hitstartx
		end
		
		if hitstarty >= hitendy then
			boxstarty = hitstarty
			boxendy = hitendy
		else
			boxstarty = hitendy
			boxendy = hitstarty
		end
		
		boxendx = boxstartx-boxendx
		boxendy = boxstarty-boxendy
		
		boxstartx = boxstartx - boxendx
		boxstarty = boxstarty - boxendy
		
		surface.SetDrawColor( 100, 235, 25, 255 )
		surface.DrawOutlinedRect( boxstartx, boxstarty, boxendx, boxendy )
		surface.SetDrawColor( 100, 235, 25, 50 )
		surface.DrawRect( boxstartx, boxstarty, boxendx, boxendy )
		
		hitendx, hitendy = gui.MousePos()
	end
else
	if pressed1 == true then
		pressed1 = false
		RunConsoleCommand("mouse1released")
		
		local starttrace = util.TraceLine( util.GetPlayerTrace( LocalPlayer(), gui.ScreenToVector( hitstartx, hitstarty ) ) ).HitPos
		starttrace.z = starttrace.z - 512
		local endtrace = util.TraceLine( util.GetPlayerTrace( LocalPlayer(), gui.ScreenToVector( hitendx, hitendy ) ) ).HitPos
		endtrace.z = endtrace.z + 512
		for k,v in pairs(ents.FindInBox( starttrace, endtrace )) do
			if v:IsNPC() or table.HasValue(SelectableUnits,v:GetClass()) then
				table.insert(SelectedObjects,v)
			end
		end
	end
	hitstartx = 0
	hitstarty = 0
	hitendx = 0
	hitendy = 0
end

end
[/lua]

Thank you. :smile: