wiremod-svn-archive/wire/lua/weapons/gmod_tool/stools/wire_waypoint.lua
2008-06-14 00:55:20 +00:00

174 lines
4.7 KiB
Lua

TOOL.Category = "Wire - Beacon"
TOOL.Name = "Waypoint"
TOOL.Command = nil
TOOL.ConfigName = ""
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, 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, range, Vel, aVel, frozen )
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("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", "range", "Vel", "aVel", "frozen")
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