2007-02-04 01:16:06 +00:00
|
|
|
|
2007-02-04 03:03:09 +00:00
|
|
|
TOOL.Category = "Wire - Display"
|
2007-02-04 01:16:06 +00:00
|
|
|
TOOL.Name = "Indicator"
|
|
|
|
TOOL.Command = nil
|
|
|
|
TOOL.ConfigName = ""
|
|
|
|
|
|
|
|
if ( CLIENT ) then
|
|
|
|
language.Add( "Tool_wire_indicator_name", "Indicator Tool (Wire)" )
|
|
|
|
language.Add( "Tool_wire_indicator_desc", "Spawns a indicator for use with the wire system." )
|
|
|
|
language.Add( "Tool_wire_indicator_0", "Primary: Create/Update Indicator" )
|
|
|
|
language.Add( "ToolWireIndicator_Model", "Model:" )
|
|
|
|
language.Add( "ToolWireIndicator_a_value", "A Value:" )
|
|
|
|
language.Add( "ToolWireIndicator_a_colour", "A Colour:" )
|
|
|
|
language.Add( "ToolWireIndicator_b_value", "B Value:" )
|
|
|
|
language.Add( "ToolWireIndicator_b_colour", "B Colour:" )
|
2007-02-06 06:01:08 +00:00
|
|
|
language.Add( "ToolWireIndicator_Material", "Material:" )
|
|
|
|
language.Add( "ToolWireIndicator_90", "Rotate segment 90:" )
|
2007-02-04 01:16:06 +00:00
|
|
|
language.Add( "sboxlimit_wire_indicators", "You've hit indicators limit!" )
|
|
|
|
language.Add( "undone_wireindicator", "Undone Wire Indicator" )
|
|
|
|
end
|
|
|
|
|
|
|
|
if (SERVER) then
|
|
|
|
CreateConVar('sbox_maxwire_indicators', 20)
|
2007-11-13 06:32:49 +00:00
|
|
|
ModelPlug_Register("indicator")
|
2007-02-04 01:16:06 +00:00
|
|
|
end
|
|
|
|
|
2007-11-13 06:32:49 +00:00
|
|
|
TOOL.ClientConVar[ "noclip" ] = "0"
|
2007-02-04 01:16:06 +00:00
|
|
|
TOOL.ClientConVar[ "model" ] = "models/jaanus/wiretool/wiretool_siren.mdl"
|
|
|
|
TOOL.ClientConVar[ "a" ] = "0"
|
|
|
|
TOOL.ClientConVar[ "ar" ] = "255"
|
|
|
|
TOOL.ClientConVar[ "ag" ] = "0"
|
|
|
|
TOOL.ClientConVar[ "ab" ] = "0"
|
|
|
|
TOOL.ClientConVar[ "aa" ] = "255"
|
|
|
|
TOOL.ClientConVar[ "b" ] = "1"
|
|
|
|
TOOL.ClientConVar[ "br" ] = "0"
|
|
|
|
TOOL.ClientConVar[ "bg" ] = "255"
|
|
|
|
TOOL.ClientConVar[ "bb" ] = "0"
|
|
|
|
TOOL.ClientConVar[ "ba" ] = "255"
|
2007-02-06 06:01:08 +00:00
|
|
|
TOOL.ClientConVar[ "rotate90" ] = "0"
|
|
|
|
TOOL.ClientConVar[ "material" ] = "models/debug/debugwhite"
|
2007-02-04 01:16:06 +00:00
|
|
|
|
|
|
|
cleanup.Register( "wire_indicators" )
|
|
|
|
|
|
|
|
function TOOL:LeftClick( trace )
|
|
|
|
|
2007-11-13 06:32:49 +00:00
|
|
|
if trace.Entity && trace.Entity:IsPlayer() then return false end
|
2007-02-04 01:16:06 +00:00
|
|
|
if ( SERVER && !util.IsValidPhysicsObject( trace.Entity, trace.PhysicsBone ) ) then return false end
|
|
|
|
if (CLIENT) then return true end
|
|
|
|
|
|
|
|
local ply = self:GetOwner()
|
|
|
|
|
2007-11-13 06:32:49 +00:00
|
|
|
local noclip = self:GetClientNumber( "noclip" ) == 1
|
2007-02-04 01:16:06 +00:00
|
|
|
local model = self:GetClientInfo( "model" )
|
|
|
|
local a = self:GetClientNumber("a")
|
|
|
|
local ar = math.min(self:GetClientNumber("ar"), 255)
|
|
|
|
local ag = math.min(self:GetClientNumber("ag"), 255)
|
|
|
|
local ab = math.min(self:GetClientNumber("ab"), 255)
|
|
|
|
local aa = math.min(self:GetClientNumber("aa"), 255)
|
|
|
|
local b = self:GetClientNumber("b")
|
|
|
|
local br = math.min(self:GetClientNumber("br"), 255)
|
|
|
|
local bg = math.min(self:GetClientNumber("bg"), 255)
|
|
|
|
local bb = math.min(self:GetClientNumber("bb"), 255)
|
|
|
|
local ba = math.min(self:GetClientNumber("ba"), 255)
|
2007-02-06 06:01:08 +00:00
|
|
|
local material = self:GetClientInfo( "material" )
|
|
|
|
|
2007-02-04 01:16:06 +00:00
|
|
|
if ( trace.Entity:IsValid() && trace.Entity:GetClass() == "gmod_wire_indicator" && trace.Entity.pl == ply ) then
|
2007-02-06 06:01:08 +00:00
|
|
|
|
2007-02-04 01:16:06 +00:00
|
|
|
trace.Entity:Setup(a, ar, ag, ab, aa, b, br, bg, bb, ba)
|
2007-02-06 06:01:08 +00:00
|
|
|
wire_indicator:SetMaterial( material )
|
|
|
|
|
2007-02-04 01:16:06 +00:00
|
|
|
trace.Entity.a = a
|
|
|
|
trace.Entity.ar = ar
|
|
|
|
trace.Entity.ag = ag
|
|
|
|
trace.Entity.ab = ab
|
|
|
|
trace.Entity.aa = aa
|
|
|
|
trace.Entity.b = b
|
|
|
|
trace.Entity.br = br
|
|
|
|
trace.Entity.bg = bg
|
|
|
|
trace.Entity.bb = bb
|
|
|
|
trace.Entity.ba = ba
|
2007-11-13 06:32:49 +00:00
|
|
|
|
2007-02-04 01:16:06 +00:00
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
|
|
|
if ( !self:GetSWEP():CheckLimit( "wire_indicators" ) ) then return false end
|
2007-11-13 06:32:49 +00:00
|
|
|
|
2007-02-04 01:16:06 +00:00
|
|
|
if (not util.IsValidModel(model)) then return false end
|
|
|
|
if (not util.IsValidProp(model)) then return false end // Allow ragdolls to be used?
|
2007-11-13 06:32:49 +00:00
|
|
|
|
2007-02-06 06:01:08 +00:00
|
|
|
local Ang = self:GetSelectedAngle(trace.HitNormal:Angle())
|
2007-02-04 01:16:06 +00:00
|
|
|
Ang.pitch = Ang.pitch + 90
|
2007-11-13 06:32:49 +00:00
|
|
|
|
|
|
|
local wire_indicator = MakeWireIndicator( ply, model, Ang, trace.HitPos, a, ar, ag, ab, aa, b, br, bg, bb, ba, material, noclip )
|
2007-02-04 01:16:06 +00:00
|
|
|
|
|
|
|
local min = wire_indicator:OBBMins()
|
2007-02-06 06:01:08 +00:00
|
|
|
wire_indicator:SetPos( trace.HitPos - trace.HitNormal * self:GetSelectedMin(min) )
|
2007-02-04 01:16:06 +00:00
|
|
|
|
2007-03-29 04:57:31 +00:00
|
|
|
local const = WireLib.Weld(wire_indicator, trace.Entity, trace.PhysicsBone, true)
|
2007-02-04 01:16:06 +00:00
|
|
|
|
|
|
|
undo.Create("WireIndicator")
|
|
|
|
undo.AddEntity( wire_indicator )
|
|
|
|
undo.AddEntity( const )
|
|
|
|
undo.SetPlayer( ply )
|
|
|
|
undo.Finish()
|
2007-11-13 06:32:49 +00:00
|
|
|
|
2007-02-04 01:16:06 +00:00
|
|
|
ply:AddCleanup( "wire_indicators", wire_indicator )
|
|
|
|
ply:AddCleanup( "wire_indicators", const )
|
|
|
|
|
|
|
|
return true
|
2007-11-13 06:32:49 +00:00
|
|
|
|
2007-02-04 01:16:06 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
if (SERVER) then
|
|
|
|
|
2007-02-06 06:01:08 +00:00
|
|
|
function MakeWireIndicator( pl, Model, Ang, Pos, a, ar, ag, ab, aa, b, br, bg, bb, ba, material, nocollide, Vel, aVel, frozen )
|
2007-02-04 01:16:06 +00:00
|
|
|
if ( !pl:CheckLimit( "wire_indicators" ) ) then return false end
|
2007-03-28 23:24:55 +00:00
|
|
|
|
2007-02-04 01:16:06 +00:00
|
|
|
local wire_indicator = ents.Create( "gmod_wire_indicator" )
|
|
|
|
if (!wire_indicator:IsValid()) then return false end
|
2007-02-06 06:01:08 +00:00
|
|
|
|
2007-02-04 01:16:06 +00:00
|
|
|
wire_indicator:SetModel( Model )
|
2007-02-06 06:01:08 +00:00
|
|
|
wire_indicator:SetMaterial( material )
|
2007-02-04 01:16:06 +00:00
|
|
|
wire_indicator:SetAngles( Ang )
|
|
|
|
wire_indicator:SetPos( Pos )
|
|
|
|
wire_indicator:Spawn()
|
2007-03-28 23:24:55 +00:00
|
|
|
|
2007-02-04 01:16:06 +00:00
|
|
|
wire_indicator:Setup(a, ar, ag, ab, aa, b, br, bg, bb, ba)
|
|
|
|
wire_indicator:SetPlayer(pl)
|
2007-03-28 23:24:55 +00:00
|
|
|
|
2007-11-13 06:32:49 +00:00
|
|
|
if ( nocollide == true ) then wire_pixel:SetCollisionGroup(COLLISION_GROUP_WORLD) end
|
2007-03-28 23:24:55 +00:00
|
|
|
|
2007-02-04 01:16:06 +00:00
|
|
|
local ttable = {
|
|
|
|
a = a,
|
|
|
|
ar = ar,
|
|
|
|
ag = ag,
|
|
|
|
ab = ab,
|
|
|
|
aa = aa,
|
|
|
|
b = b,
|
|
|
|
br = br,
|
|
|
|
bg = bg,
|
|
|
|
bb = bb,
|
|
|
|
ba = ba,
|
2007-02-06 06:01:08 +00:00
|
|
|
material = material,
|
2007-02-04 01:16:06 +00:00
|
|
|
pl = pl,
|
|
|
|
nocollide = nocollide
|
|
|
|
}
|
2007-03-28 23:24:55 +00:00
|
|
|
|
2007-02-04 01:16:06 +00:00
|
|
|
table.Merge(wire_indicator:GetTable(), ttable )
|
2007-03-28 23:24:55 +00:00
|
|
|
|
2007-02-04 01:16:06 +00:00
|
|
|
pl:AddCount( "wire_indicators", wire_indicator )
|
2007-03-28 23:24:55 +00:00
|
|
|
|
2007-02-04 01:16:06 +00:00
|
|
|
return wire_indicator
|
|
|
|
end
|
|
|
|
|
2007-02-06 06:01:08 +00:00
|
|
|
duplicator.RegisterEntityClass("gmod_wire_indicator", MakeWireIndicator, "Model", "Ang", "Pos", "a", "ar", "ag", "ab", "aa", "b", "br", "bg", "bb", "ba", "material", "nocollide", "Vel", "aVel", "frozen")
|
2007-02-04 01:16:06 +00:00
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
function TOOL:UpdateGhostWireIndicator( ent, player )
|
2007-11-13 06:32:49 +00:00
|
|
|
|
2007-02-04 01:16:06 +00:00
|
|
|
if ( !ent ) then return end
|
|
|
|
if ( !ent:IsValid() ) then return end
|
2007-11-13 06:32:49 +00:00
|
|
|
|
2007-02-04 01:16:06 +00:00
|
|
|
local tr = utilx.GetPlayerTrace( player, player:GetCursorAimVector() )
|
|
|
|
local trace = util.TraceLine( tr )
|
|
|
|
if (!trace.Hit) then return end
|
|
|
|
|
|
|
|
if (trace.Entity && trace.Entity:GetClass() == "gmod_wire_indicator" || trace.Entity:IsPlayer()) then
|
|
|
|
ent:SetNoDraw( true )
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2007-02-06 06:01:08 +00:00
|
|
|
local Ang = self:GetSelectedAngle(trace.HitNormal:Angle())
|
2007-02-04 01:16:06 +00:00
|
|
|
Ang.pitch = Ang.pitch + 90
|
|
|
|
|
|
|
|
local min = ent:OBBMins()
|
2007-02-06 06:01:08 +00:00
|
|
|
ent:SetPos( trace.HitPos - trace.HitNormal * self:GetSelectedMin(min) )
|
2007-02-04 01:16:06 +00:00
|
|
|
ent:SetAngles( Ang )
|
|
|
|
|
|
|
|
ent:SetNoDraw( false )
|
|
|
|
|
|
|
|
end
|
|
|
|
|
2007-02-06 06:01:08 +00:00
|
|
|
function TOOL:GetSelectedAngle( Ang )
|
|
|
|
local Model = self:GetClientInfo( "model" )
|
|
|
|
//these models get mounted differently
|
|
|
|
if (Model == "models/props_borealis/bluebarrel001.mdl" || Model == "models/props_junk/PopCan01a.mdl") then
|
|
|
|
return Ang + Angle(180, 0, 0)
|
|
|
|
elseif (Model == "models/props_trainstation/trainstation_clock001.mdl" || Model == "models/segment.mdl" || Model == "models/segment2.mdl") then
|
|
|
|
return Ang + Angle(-90, 0, (self:GetClientNumber("rotate90") * 90))
|
|
|
|
else
|
|
|
|
return Ang
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function TOOL:GetSelectedMin( min )
|
|
|
|
local Model = self:GetClientInfo( "model" )
|
|
|
|
//these models are different
|
|
|
|
if (Model == "models/props_trainstation/trainstation_clock001.mdl" || Model == "models/segment.mdl" || Model == "models/segment2.mdl") then
|
|
|
|
return min.x
|
|
|
|
else
|
|
|
|
return min.z
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2007-02-04 01:16:06 +00:00
|
|
|
function TOOL:Think()
|
|
|
|
if (!self.GhostEntity || !self.GhostEntity:IsValid() || self.GhostEntity:GetModel() != self:GetClientInfo( "model" )) then
|
2007-02-06 06:01:08 +00:00
|
|
|
self:MakeGhostEntity( self:GetClientInfo( "model" ), Vector(0,0,0), self:GetSelectedAngle(Angle(0,0,0)) )
|
2007-02-04 01:16:06 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
self:UpdateGhostWireIndicator( self.GhostEntity, self:GetOwner() )
|
|
|
|
end
|
|
|
|
|
|
|
|
function TOOL.BuildCPanel(panel)
|
|
|
|
panel:AddControl("Header", { Text = "#Tool_wire_indicator_name", Description = "#Tool_wire_indicator_desc" })
|
|
|
|
|
|
|
|
panel:AddControl("ComboBox", {
|
|
|
|
Label = "#Presets",
|
|
|
|
MenuButton = "1",
|
|
|
|
Folder = "wire_indicator",
|
|
|
|
|
|
|
|
Options = {
|
|
|
|
["#Default"] = {
|
|
|
|
wire_indicator_a = "0",
|
|
|
|
wire_indicator_ar = "255",
|
|
|
|
wire_indicator_ag = "0",
|
|
|
|
wire_indicator_ab = "0",
|
|
|
|
wire_indicator_aa = "255",
|
|
|
|
wire_indicator_b = "1",
|
|
|
|
wire_indicator_br = "0",
|
|
|
|
wire_indicator_bg = "255",
|
|
|
|
wire_indicator_bb = "0",
|
2007-02-06 06:01:08 +00:00
|
|
|
wire_indicator_ba = "255",
|
|
|
|
wire_indicator_model = "models/jaanus/wiretool/wiretool_siren.mdl",
|
|
|
|
wire_indicator_material = "models/debug/debugwhite",
|
|
|
|
wire_indicator_rotate90 = "0"
|
|
|
|
|
2007-02-04 01:16:06 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
CVars = {
|
|
|
|
[0] = "wire_indicator_a",
|
|
|
|
[1] = "wire_indicator_ar",
|
|
|
|
[2] = "wire_indicator_ag",
|
|
|
|
[3] = "wire_indicator_ab",
|
|
|
|
[4] = "wire_indicator_aa",
|
|
|
|
[5] = "wire_indicator_b",
|
|
|
|
[6] = "wire_indicator_br",
|
|
|
|
[7] = "wire_indicator_bg",
|
|
|
|
[8] = "wire_indicator_bb",
|
2007-02-06 06:01:08 +00:00
|
|
|
[9] = "wire_indicator_ba",
|
|
|
|
[10] = "wire_indicator_model",
|
|
|
|
[11] = "wire_indicator_material",
|
|
|
|
[12] = "wire_indicator_rotate90"
|
2007-02-04 01:16:06 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
panel:AddControl("Slider", {
|
|
|
|
Label = "#ToolWireIndicator_a_value",
|
|
|
|
Type = "Float",
|
|
|
|
Min = "-10",
|
|
|
|
Max = "10",
|
|
|
|
Command = "wire_indicator_a"
|
|
|
|
})
|
|
|
|
panel:AddControl("Color", {
|
|
|
|
Label = "#ToolWireIndicator_a_colour",
|
|
|
|
Red = "wire_indicator_ar",
|
|
|
|
Green = "wire_indicator_ag",
|
|
|
|
Blue = "wire_indicator_ab",
|
|
|
|
Alpha = "wire_indicator_aa",
|
|
|
|
ShowAlpha = "1",
|
|
|
|
ShowHSV = "1",
|
|
|
|
ShowRGB = "1",
|
|
|
|
Multiplier = "255"
|
|
|
|
})
|
|
|
|
|
|
|
|
panel:AddControl("Slider", {
|
|
|
|
Label = "#ToolWireIndicator_b_value",
|
|
|
|
Type = "Float",
|
|
|
|
Min = "-10",
|
|
|
|
Max = "10",
|
|
|
|
Command = "wire_indicator_b"
|
|
|
|
})
|
|
|
|
panel:AddControl("Color", {
|
|
|
|
Label = "#ToolWireIndicator_b_colour",
|
|
|
|
Red = "wire_indicator_br",
|
|
|
|
Green = "wire_indicator_bg",
|
|
|
|
Blue = "wire_indicator_bb",
|
|
|
|
Alpha = "wire_indicator_ba",
|
|
|
|
ShowAlpha = "1",
|
|
|
|
ShowHSV = "1",
|
|
|
|
ShowRGB = "1",
|
|
|
|
Multiplier = "255"
|
|
|
|
})
|
2007-02-06 06:01:08 +00:00
|
|
|
|
2007-11-13 06:32:49 +00:00
|
|
|
ModelPlug_AddToCPanel(panel, "indicator", "wire_indicator", "#ToolWireIndicator_Model", nil, "#ToolWireIndicator_Model")
|
2007-02-06 06:01:08 +00:00
|
|
|
|
|
|
|
panel:AddControl("ComboBox", {
|
|
|
|
Label = "#ToolWireIndicator_Material",
|
|
|
|
MenuButton = "0",
|
|
|
|
|
|
|
|
Options = {
|
|
|
|
["Matte"] = { wire_indicator_material = "models/debug/debugwhite" },
|
|
|
|
["Shiny"] = { wire_indicator_material = "models/shiny" },
|
|
|
|
["Metal"] = { wire_indicator_material = "models/props_c17/metalladder003" }
|
2007-02-04 01:16:06 +00:00
|
|
|
}
|
|
|
|
})
|
2007-02-06 06:01:08 +00:00
|
|
|
|
|
|
|
panel:AddControl("CheckBox", {
|
|
|
|
Label = "#ToolWireIndicator_90",
|
|
|
|
Command = "wire_indicator_rotate90"
|
|
|
|
})
|
2007-11-13 06:32:49 +00:00
|
|
|
|
|
|
|
panel:AddControl("CheckBox", {
|
|
|
|
Label = "#WireGatesTool_noclip",
|
|
|
|
Command = "wire_indicator_noclip"
|
|
|
|
})
|
|
|
|
|
2007-02-04 01:16:06 +00:00
|
|
|
end
|