wiremod-svn-archive/wire/lua/weapons/gmod_tool/stools/wire_gate_logic.lua

138 lines
4.0 KiB
Lua
Raw Normal View History

2007-02-04 01:16:06 +00:00
TOOL.Category = "Wire - Control"
2007-02-04 01:16:06 +00:00
TOOL.Name = "Gate - Logic"
TOOL.Command = nil
TOOL.ConfigName = ""
if ( CLIENT ) then
language.Add( "Tool_wire_gate_logic_name", "Logic Gate Tool (Wire)" )
language.Add( "Tool_wire_gate_logic_desc", "Spawns a logic gate for use with the wire system." )
language.Add( "Tool_wire_gate_logic_0", "Primary: Create/Update Logic Gate" )
language.Add( "WireGateLogicTool_action", "Action:" )
2007-02-04 07:34:07 +00:00
language.Add( "WireGateLogicTool_model", "Model:" )
2007-02-04 01:16:06 +00:00
language.Add( "sboxlimit_wire_gate_logics", "You've hit logic gates limit!" )
language.Add( "undone_wiregatelogic", "Undone Wire Logic Gate" )
end
if (SERVER) then
CreateConVar('sbox_maxwire_gate_logics', 30)
end
TOOL.ClientConVar[ "action" ] = "and"
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_logics" )
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" )
local noclip = self:GetClientNumber( "noclip" ) == 1
2007-02-04 07:34:07 +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
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_gate_logics" ) ) then return false end
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
local wire_gate_logic = MakeWireGate( ply, trace.HitPos, Ang, model, action, noclip )
2007-02-04 01:16:06 +00:00
local min = wire_gate_logic:OBBMins()
wire_gate_logic:SetPos( trace.HitPos - trace.HitNormal * min.z )
local const = WireLib.Weld(wire_gate_logic, trace.Entity, trace.PhysicsBone, true)
2007-02-04 01:16:06 +00:00
undo.Create("WireGateLogic")
undo.AddEntity( wire_gate_logic )
undo.AddEntity( const )
undo.SetPlayer( ply )
undo.Finish()
ply:AddCleanup( "wire_gate_logics", wire_gate_logic )
return true
end
function TOOL:RightClick( trace )
return self:LeftClick( trace )
end
function TOOL:UpdateGhostWireGateLogic( 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:34:07 +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
self:UpdateGhostWireGateLogic( self.GhostEntity, self:GetOwner() )
end
function TOOL.BuildCPanel(panel)
panel:AddControl("Header", { Text = "#Tool_wire_gate_logic_name", Description = "#Tool_wire_gate_logic_desc" })
panel:AddControl("CheckBox", {
Label = "#WireGatesTool_noclip",
Command = "wire_gate_logic_noclip"
})
2007-02-04 01:16:06 +00:00
local Actions = {
Label = "#WireGateLogicTool_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 == "Logic") then
Actions.Options[v.name or "No Name"] = { wire_gate_logic_action = k }
end
end
panel:AddControl("ListBox", Actions)
2007-02-04 07:34:07 +00:00
ModelPlug_AddToCPanel(panel, "gate", "wire_gate_logic", "#WireGateLogicTool_model", nil, "#WireGateLogicTool_model")
2007-02-04 01:16:06 +00:00
end