<commit_before>TOOL.Category		= "Wire - Beacon"
TOOL.Name			= "Waypoint"
TOOL.Command		= nil
TOOL.ConfigName		= ""
TOOL.Tab			= "Wire"

if ( CLIENT ) then
    language.Add( "Tool_wire_waypoint_name", "Waypoint Beacon Tool (Wire)" )
    language.Add( "Tool_wire_waypoint_desc", "Spawns a waypoint beacon for use with the wire system." )
    language.Add( "Tool_wire_waypoint_0", "Primary: Create/Update Waypoint Beacon    Secondary: Link to next waypoint" )
    language.Add( "Tool_wire_waypoint_1", "Primary: Select waypoint to go to after this one" )
    language.Add( "WireWaypointTool_range", "Range:" )
	language.Add( "WireWaypointTool_alink", "Auto-link previous" )
	language.Add( "sboxlimit_wire_waypoints", "You've hit waypoint beacons limit!" )
	language.Add( "undone_wirewaypoint", "Undone Wire Waypoint Beacon" )
end

if (SERVER) then
  CreateConVar('sbox_maxwire_waypoints',30)
end

TOOL.ClientConVar[ "range" ] = "150"
TOOL.ClientConVar[ "alink" ] = "0"

TOOL.Model = "models/props_lab/powerbox02d.mdl"

cleanup.Register( "wire_waypoints" )

function TOOL:LeftClick(trace)
	if (!trace.HitPos) then return false end
	if (trace.Entity:IsPlayer()) then return false end
	if ( CLIENT ) then return true end

	local ply = self:GetOwner()

	if (self:GetStage() == 1) then
	    self:SetStage(0)

	    if (trace.Entity:IsValid()) and (trace.Entity:GetClass() == "gmod_wire_waypoint") and (self.SrcWaypoint) and (self.SrcWaypoint:IsValid()) then
	        self.SrcWaypoint:SetNextWaypoint(trace.Entity)
	        self.SrcWaypoint = nil

	        return true
	    end

	    self.SrcWaypoint = nil

	    return
	end

	local range = self:GetClientNumber("range")

	if ( trace.Entity:IsValid() && trace.Entity:GetClass() == "gmod_wire_waypoint" && trace.Entity.pl == ply ) then
		trace.Entity:Setup(range)
		trace.Entity.range = range
		return true
	end

	if ( !self:GetSWEP():CheckLimit( "wire_waypoints" ) ) then return false end

	local Ang = trace.HitNormal:Angle()

	local wire_waypoint = MakeWireWaypoint( ply, trace.HitPos, Ang, self.Model, range )

	local min = wire_waypoint:OBBMins()
	wire_waypoint:SetPos( trace.HitPos - trace.HitNormal * (min.z) )

	// Auto-link (itsbth)
	if ( self.OldWaypoint && self.OldWaypoint:IsValid() and self:GetClientNumber("alink") == 1 ) then
		self.OldWaypoint:SetNextWaypoint(wire_waypoint)
	end

	self.OldWaypoint = wire_waypoint

	undo.Create("WireWaypoint")
		undo.AddEntity( wire_waypoint )
		undo.SetPlayer( ply )
	undo.Finish()

	ply:AddCleanup( "wire_waypoints", wire_waypoint )

	return true
end

function TOOL:RightClick(trace)
	if (self:GetStage() == 0) and (trace.Entity:IsValid()) and (trace.Entity:GetClass() == "gmod_wire_waypoint") then
	    self.SrcWaypoint = trace.Entity
		self:SetStage(1)

		return true
	end

	return self:LeftClick(trace)
end

if SERVER then

	function MakeWireWaypoint(pl, Pos, Ang, model, range )
		if (!pl:CheckLimit("wire_waypoints")) then return end

		local wire_waypoint = ents.Create("gmod_wire_waypoint")
		wire_waypoint:SetPos(Pos)
		wire_waypoint:SetAngles(Ang)
		wire_waypoint:SetModel( Model(model or "models/props_lab/powerbox02d.mdl") )
		wire_waypoint:Spawn()
		wire_waypoint:Activate()

		wire_waypoint:Setup(range)
		wire_waypoint:SetPlayer(pl)

		local ttable = {
			pl			= pl,
			range       = range,
			nocollide	= nocollide,
		}
		table.Merge( wire_waypoint:GetTable(), ttable )

		pl:AddCount( "wire_waypoints", wire_waypoint )

		return wire_waypoint
	end

	duplicator.RegisterEntityClass("gmod_wire_waypoint", MakeWireWaypoint, "Pos", "Ang", "Model", "range")

end

function TOOL:UpdateGhostWireWaypoint( ent, player )

	if ( !ent || !ent:IsValid() ) then return end

	local tr 	= utilx.GetPlayerTrace( player, player:GetCursorAimVector() )
	local trace 	= util.TraceLine( tr )

	if (!trace.Hit || trace.Entity:IsPlayer() || trace.Entity:GetClass() == "gmod_wire_waypoint" ) then
		ent:SetNoDraw( true )
		return
	end

	local Ang = trace.HitNormal:Angle()

	local min = ent:OBBMins()
	ent:SetPos( trace.HitPos - trace.HitNormal * min.z )
	ent:SetAngles( Ang )

	ent:SetNoDraw( false )

end

function TOOL:Think()

	if (!self.GhostEntity || !self.GhostEntity:IsValid() || self.GhostEntity:GetModel() != self.Model ) then
		self:MakeGhostEntity( self.Model, Vector(0,0,0), Angle(0,0,0) )
	end

	self:UpdateGhostWireWaypoint( self.GhostEntity, self:GetOwner() )

end

function TOOL.BuildCPanel(panel)
	panel:AddControl("Header", { Text = "#Tool_wire_waypoint_name", Description = "#Tool_wire_waypoint_desc" })

	panel:AddControl("Slider", {
		Label = "#WireWaypointTool_range",
		Type = "Float",
		Min = "1",
		Max = "1000",
		Command = "wire_waypoint_range"
	})
		panel:AddControl("Checkbox", {
		Label = "#WireWaypointTool_alink",
		Command = "wire_waypoint_alink"
	})
end

<commit_msg>[Waypoint] STOOL: Pressing reload now removes the link to the next waypoint.<commit_after>TOOL.Category		= "Wire - Beacon"
TOOL.Name			= "Waypoint"
TOOL.Command		= nil
TOOL.ConfigName		= ""
TOOL.Tab			= "Wire"

if ( CLIENT ) then
    language.Add( "Tool_wire_waypoint_name", "Waypoint Beacon Tool (Wire)" )
    language.Add( "Tool_wire_waypoint_desc", "Spawns a waypoint beacon for use with the wire system." )
    language.Add( "Tool_wire_waypoint_0", "Primary: Create/Update Waypoint Beacon, Secondary: Link to next waypoint, Reload: Remove link to next waypoint" )
    language.Add( "Tool_wire_waypoint_1", "Primary: Select waypoint to go to after this one" )
    language.Add( "WireWaypointTool_range", "Range:" )
	language.Add( "WireWaypointTool_alink", "Auto-link previous" )
	language.Add( "sboxlimit_wire_waypoints", "You've hit waypoint beacons limit!" )
	language.Add( "undone_wirewaypoint", "Undone Wire Waypoint Beacon" )
end

if (SERVER) then
  CreateConVar('sbox_maxwire_waypoints',30)
end

TOOL.ClientConVar[ "range" ] = "150"
TOOL.ClientConVar[ "alink" ] = "0"

TOOL.Model = "models/props_lab/powerbox02d.mdl"

cleanup.Register( "wire_waypoints" )

function TOOL:LeftClick(trace)
	if (!trace.HitPos) then return false end
	if (trace.Entity:IsPlayer()) then return false end
	if ( CLIENT ) then return true end

	local ply = self:GetOwner()

	if (self:GetStage() == 1) then
	    self:SetStage(0)

	    if (trace.Entity:IsValid()) and (trace.Entity:GetClass() == "gmod_wire_waypoint") and (self.SrcWaypoint) and (self.SrcWaypoint:IsValid()) then
	        self.SrcWaypoint:SetNextWaypoint(trace.Entity)
	        self.SrcWaypoint = nil

	        return true
	    end

	    self.SrcWaypoint = nil

	    return
	end

	local range = self:GetClientNumber("range")

	if ( trace.Entity:IsValid() && trace.Entity:GetClass() == "gmod_wire_waypoint" && trace.Entity.pl == ply ) then
		trace.Entity:Setup(range)
		trace.Entity.range = range
		return true
	end

	if ( !self:GetSWEP():CheckLimit( "wire_waypoints" ) ) then return false end

	local Ang = trace.HitNormal:Angle()

	local wire_waypoint = MakeWireWaypoint( ply, trace.HitPos, Ang, self.Model, range )

	local min = wire_waypoint:OBBMins()
	wire_waypoint:SetPos( trace.HitPos - trace.HitNormal * (min.z) )

	// Auto-link (itsbth)
	if ( self.OldWaypoint && self.OldWaypoint:IsValid() and self:GetClientNumber("alink") == 1 ) then
		self.OldWaypoint:SetNextWaypoint(wire_waypoint)
	end

	self.OldWaypoint = wire_waypoint

	undo.Create("WireWaypoint")
		undo.AddEntity( wire_waypoint )
		undo.SetPlayer( ply )
	undo.Finish()

	ply:AddCleanup( "wire_waypoints", wire_waypoint )

	return true
end

function TOOL:RightClick(trace)
	if (self:GetStage() == 0) and (trace.Entity:IsValid()) and (trace.Entity:GetClass() == "gmod_wire_waypoint") then
	    self.SrcWaypoint = trace.Entity
		self:SetStage(1)

		return true
	end

	return self:LeftClick(trace)
end

function TOOL:Reload(trace)
	if self:GetStage() ~= 0 then return false end

	if (trace.Entity:IsValid()) and (trace.Entity:GetClass() == "gmod_wire_waypoint") then
		trace.Entity:SetNextWaypoint(NULL)

		return true
	end
end

if SERVER then

	function MakeWireWaypoint(pl, Pos, Ang, model, range )
		if (!pl:CheckLimit("wire_waypoints")) then return end

		local wire_waypoint = ents.Create("gmod_wire_waypoint")
		wire_waypoint:SetPos(Pos)
		wire_waypoint:SetAngles(Ang)
		wire_waypoint:SetModel( Model(model or "models/props_lab/powerbox02d.mdl") )
		wire_waypoint:Spawn()
		wire_waypoint:Activate()

		wire_waypoint:Setup(range)
		wire_waypoint:SetPlayer(pl)

		local ttable = {
			pl			= pl,
			range       = range,
			nocollide	= nocollide,
		}
		table.Merge( wire_waypoint:GetTable(), ttable )

		pl:AddCount( "wire_waypoints", wire_waypoint )

		return wire_waypoint
	end

	duplicator.RegisterEntityClass("gmod_wire_waypoint", MakeWireWaypoint, "Pos", "Ang", "Model", "range")

end

function TOOL:UpdateGhostWireWaypoint( ent, player )

	if ( !ent || !ent:IsValid() ) then return end

	local tr 	= utilx.GetPlayerTrace( player, player:GetCursorAimVector() )
	local trace 	= util.TraceLine( tr )

	if (!trace.Hit || trace.Entity:IsPlayer() || trace.Entity:GetClass() == "gmod_wire_waypoint" ) then
		ent:SetNoDraw( true )
		return
	end

	local Ang = trace.HitNormal:Angle()

	local min = ent:OBBMins()
	ent:SetPos( trace.HitPos - trace.HitNormal * min.z )
	ent:SetAngles( Ang )

	ent:SetNoDraw( false )

end

function TOOL:Think()

	if (!self.GhostEntity || !self.GhostEntity:IsValid() || self.GhostEntity:GetModel() != self.Model ) then
		self:MakeGhostEntity( self.Model, Vector(0,0,0), Angle(0,0,0) )
	end

	self:UpdateGhostWireWaypoint( self.GhostEntity, self:GetOwner() )

end

function TOOL.BuildCPanel(panel)
	panel:AddControl("Header", { Text = "#Tool_wire_waypoint_name", Description = "#Tool_wire_waypoint_desc" })

	panel:AddControl("Slider", {
		Label = "#WireWaypointTool_range",
		Type = "Float",
		Min = "1",
		Max = "1000",
		Command = "wire_waypoint_range"
	})
		panel:AddControl("Checkbox", {
		Label = "#WireWaypointTool_alink",
		Command = "wire_waypoint_alink"
	})
end


{'fraction_non_alphanumeric': 0.12452462213554363, 'fraction_numerical': 0.005558264261335934, 'mean_word_length': 3.961780358006773, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2132115', 'n_tokens_mistral': 4017, 'n_tokens_neox': 3525, 'n_words': 755}