2007-03-25 23:01:45 +00:00
|
|
|
|
2007-02-04 03:03:09 +00:00
|
|
|
TOOL.Category = "Wire - Control"
|
2007-02-04 01:16:06 +00:00
|
|
|
TOOL.Name = "Gate - Arithmetic"
|
|
|
|
TOOL.Command = nil
|
|
|
|
TOOL.ConfigName = ""
|
|
|
|
|
|
|
|
if ( CLIENT ) then
|
|
|
|
language.Add( "Tool_wire_gate_arithmetic_name", "Arithmetic Gate Tool (Wire)" )
|
|
|
|
language.Add( "Tool_wire_gate_arithmetic_desc", "Spawns an arithmetic gate for use with the wire system." )
|
|
|
|
language.Add( "Tool_wire_gate_arithmetic_0", "Primary: Create/Update Arithmetic Gate" )
|
|
|
|
language.Add( "WireGateArithmeticTool_action", "Action:" )
|
2007-02-04 07:18:10 +00:00
|
|
|
language.Add( "WireGateArithmeticTool_model", "Model:" )
|
2007-02-04 01:16:06 +00:00
|
|
|
language.Add( "sboxlimit_wire_gate_arithmetics", "You've hit arithmetic gates limit!" )
|
|
|
|
language.Add( "undone_wiregatearithmetic", "Undone Wire Arithmetic Gate" )
|
|
|
|
end
|
|
|
|
|
|
|
|
if (SERVER) then
|
|
|
|
CreateConVar('sbox_maxwire_gates', 30)
|
|
|
|
end
|
|
|
|
|
|
|
|
TOOL.ClientConVar[ "action" ] = "+"
|
2007-03-25 23:01:45 +00:00
|
|
|
TOOL.ClientConVar[ "noclip" ] = "0"
|
2007-02-05 10:52:02 +00:00
|
|
|
TOOL.ClientConVar[ "model" ] = "models/jaanus/wiretool/wiretool_gate.mdl"
|
2007-02-04 01:16:06 +00:00
|
|
|
|
2007-02-05 10:52:02 +00:00
|
|
|
if (SERVER) then
|
|
|
|
ModelPlug_Register("gate")
|
|
|
|
end
|
2007-02-04 01:16:06 +00:00
|
|
|
|
|
|
|
cleanup.Register( "wire_gate_arithmetics" )
|
|
|
|
|
|
|
|
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()
|
|
|
|
|
|
|
|
|
|
|
|
// Get client's CVars
|
|
|
|
local action = self:GetClientInfo( "action" )
|
2007-03-25 23:01:45 +00:00
|
|
|
local noclip = self:GetClientNumber( "noclip" ) == 1
|
2007-02-04 07:18:10 +00:00
|
|
|
local model = self:GetClientInfo( "model" )
|
2007-02-04 01:16:06 +00:00
|
|
|
|
|
|
|
if ( trace.Entity:IsValid() && trace.Entity:GetClass() == "gmod_wire_gate" && trace.Entity.pl == ply ) then
|
2007-03-25 23:01:45 +00:00
|
|
|
trace.Entity:Setup( GateActions[action], noclip )
|
2007-02-04 01:16:06 +00:00
|
|
|
trace.Entity:GetTable().action = action
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
|
|
|
if ( !self:GetSWEP():CheckLimit( "wire_gates" ) ) then return false end
|
|
|
|
|
2007-02-05 01:37:01 +00:00
|
|
|
if (not util.IsValidModel(model)) then return false end
|
|
|
|
if (not util.IsValidProp(model)) then return false end
|
|
|
|
|
2007-02-04 01:16:06 +00:00
|
|
|
local Ang = trace.HitNormal:Angle()
|
|
|
|
Ang.pitch = Ang.pitch + 90
|
|
|
|
|
2007-03-25 23:01:45 +00:00
|
|
|
local wire_gate_arithmetic = MakeWireGate( ply, trace.HitPos, Ang, model, action, noclip )
|
2007-02-04 01:16:06 +00:00
|
|
|
|
|
|
|
local min = wire_gate_arithmetic:OBBMins()
|
|
|
|
wire_gate_arithmetic:SetPos( trace.HitPos - trace.HitNormal * min.z )
|
|
|
|
|
2007-03-28 23:24:55 +00:00
|
|
|
/*local const, nocollide
|
2007-02-04 01:16:06 +00:00
|
|
|
|
|
|
|
// Don't weld to world
|
|
|
|
if ( trace.Entity:IsValid() ) then
|
2007-03-22 03:27:52 +00:00
|
|
|
const = constraint.Weld( wire_gate_arithmetic, trace.Entity, 0, trace.PhysicsBone, 0, true, true )
|
2007-02-04 01:16:06 +00:00
|
|
|
// Don't disable collision if it's not attached to anything
|
|
|
|
wire_gate_arithmetic:GetPhysicsObject():EnableCollisions( false )
|
|
|
|
wire_gate_arithmetic.nocollide = true
|
2007-03-28 23:24:55 +00:00
|
|
|
end*/
|
|
|
|
local const = WireLib.Weld(wire_gate_arithmetic, trace.Entity, trace.PhysicsBone, true)
|
2007-02-04 01:16:06 +00:00
|
|
|
|
|
|
|
undo.Create("WireGateArithmetic")
|
|
|
|
undo.AddEntity( wire_gate_arithmetic )
|
|
|
|
undo.AddEntity( const )
|
|
|
|
undo.SetPlayer( ply )
|
|
|
|
undo.Finish()
|
|
|
|
|
|
|
|
|
|
|
|
ply:AddCleanup( "wire_gate_arithmetics", wire_gate_arithmetic )
|
|
|
|
|
|
|
|
return true
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
function TOOL:RightClick( trace )
|
|
|
|
return self:LeftClick( trace )
|
|
|
|
end
|
|
|
|
|
|
|
|
function TOOL:UpdateGhostWireGateArithmetic( 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_gate" ) then
|
|
|
|
ent:SetNoDraw( true )
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
local Ang = trace.HitNormal:Angle()
|
|
|
|
Ang.pitch = Ang.pitch + 90
|
|
|
|
|
|
|
|
local min = ent:OBBMins()
|
|
|
|
ent:SetPos( trace.HitPos - trace.HitNormal * min.z )
|
|
|
|
ent:SetAngles( Ang )
|
|
|
|
|
|
|
|
ent:SetNoDraw( false )
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
function TOOL:Think()
|
2007-02-04 07:18:10 +00:00
|
|
|
if (!self.GhostEntity || !self.GhostEntity:IsValid() || self.GhostEntity:GetModel() != self:GetClientInfo( "model" )) then
|
|
|
|
self:MakeGhostEntity( self:GetClientInfo( "model" ), Vector(0,0,0), Angle(0,0,0) )
|
2007-02-04 01:16:06 +00:00
|
|
|
end
|
2007-02-04 07:18:10 +00:00
|
|
|
|
2007-02-04 01:16:06 +00:00
|
|
|
self:UpdateGhostWireGateArithmetic( self.GhostEntity, self:GetOwner() )
|
|
|
|
end
|
|
|
|
|
|
|
|
function TOOL.BuildCPanel(panel)
|
|
|
|
panel:AddControl("Header", { Text = "#Tool_wire_gate_arithmetic_name", Description = "#Tool_wire_gate_arithmetic_desc" })
|
|
|
|
|
2007-03-25 23:01:45 +00:00
|
|
|
panel:AddControl("CheckBox", {
|
|
|
|
Label = "#WireGatesTool_noclip",
|
|
|
|
Command = "wire_gate_arithmetic_noclip"
|
|
|
|
})
|
|
|
|
|
2007-02-04 01:16:06 +00:00
|
|
|
local Actions = {
|
|
|
|
Label = "#WireGateArithmeticTool_action",
|
|
|
|
MenuButton = "0",
|
2007-02-12 18:50:46 +00:00
|
|
|
Height = 180,
|
2007-02-04 01:16:06 +00:00
|
|
|
Options = {}
|
|
|
|
}
|
|
|
|
|
|
|
|
for k,v in pairs(GateActions) do
|
|
|
|
if(v.group == "Arithmetic") then
|
|
|
|
Actions.Options[v.name or "No Name"] = { wire_gate_arithmetic_action = k }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
panel:AddControl("ListBox", Actions)
|
2007-02-04 07:18:10 +00:00
|
|
|
|
|
|
|
ModelPlug_AddToCPanel(panel, "gate", "wire_gate_arithmetic", "#WireGateArithmeticTool_model", nil, "#WireGateArithmeticTool_model")
|
2007-02-04 01:16:06 +00:00
|
|
|
end
|
|
|
|
|