2007-09-16 00:05:31 +00:00
|
|
|
TOOL.Category = "Wire - I/O"
|
|
|
|
TOOL.Name = "Pod Controller"
|
|
|
|
TOOL.Command = nil -- What is this for?
|
|
|
|
TOOL.ConfigName = ""
|
|
|
|
|
|
|
|
if CLIENT then
|
|
|
|
language.Add("Tool_wire_pod_name", "Pod Controller Tool (Wire)")
|
|
|
|
language.Add("Tool_wire_pod_desc", "Spawn/link a Wire Pod controller.")
|
|
|
|
language.Add("Tool_wire_pod_0", "Primary: Create Pod controller. Secondary: Link controller.")
|
|
|
|
language.Add("Tool_wire_pod_1", "Now select the pod to link to.")
|
|
|
|
language.Add("WirePodTool_pod", "Pod:")
|
2007-09-22 18:03:33 +00:00
|
|
|
language.Add("WirePodTool_Advanced", "Advanced Controller?")
|
2007-09-16 00:05:31 +00:00
|
|
|
language.Add("WirePodTool_Keys", "Outputs:")
|
|
|
|
language.Add("sboxlimit_wire_pods", "You've hit your Pod Controller limit!")
|
|
|
|
language.Add("Undone_Wire Pod", "Undone Wire Pod Controller")
|
2007-03-19 19:43:40 +00:00
|
|
|
end
|
|
|
|
|
2007-09-16 00:05:31 +00:00
|
|
|
if SERVER then
|
2007-03-19 19:43:40 +00:00
|
|
|
CreateConVar('sbox_maxwire_pods', 20)
|
|
|
|
end
|
|
|
|
|
|
|
|
TOOL.Model = "models/jaanus/wiretool/wiretool_siren.mdl"
|
2007-05-15 19:35:58 +00:00
|
|
|
TOOL.ClientConVar["Advanced"] = "0"
|
2007-09-16 00:05:31 +00:00
|
|
|
TOOL.ClientConVar["Keys"] = "W=0,1;A=0,1;S=0,1;D=0,1;"
|
|
|
|
|
|
|
|
cleanup.Register("wire_pods")
|
|
|
|
|
|
|
|
local keytable = {}
|
|
|
|
keytable["attack"] = IN_ATTACK
|
|
|
|
keytable["attack1"] = IN_ATTACK
|
|
|
|
keytable["mouse"] = IN_ATTACK
|
|
|
|
keytable["mouse1"] = IN_ATTACK
|
|
|
|
keytable["attack2"] = IN_ATTACK2
|
|
|
|
keytable["mouse2"] = IN_ATTACK2
|
|
|
|
keytable["forward"] = IN_FORWARD
|
|
|
|
keytable["w"] = IN_FORWARD
|
|
|
|
keytable["left"] = IN_MOVELEFT
|
|
|
|
keytable["a"] = IN_MOVELEFT
|
|
|
|
keytable["back"] = IN_BACK
|
|
|
|
keytable["s"] = IN_BACK
|
|
|
|
keytable["right"] = IN_MOVERIGHT
|
|
|
|
keytable["d"] = IN_MOVERIGHT
|
|
|
|
keytable["reload"] = IN_RELOAD
|
|
|
|
keytable["r"] = IN_RELOAD
|
|
|
|
keytable["jump"] = IN_JUMP
|
|
|
|
keytable["space"] = IN_JUMP
|
|
|
|
keytable["duck"] = IN_DUCK
|
|
|
|
keytable["ctrl"] = IN_DUCK
|
|
|
|
keytable["sprint"] = IN_SPEED
|
|
|
|
keytable["shift"] = IN_SPEED
|
|
|
|
keytable["zoom"] = IN_ZOOM
|
|
|
|
|
|
|
|
local function ParseKeys(str)
|
|
|
|
local keys = {}
|
|
|
|
for key, off, on in string.gmatch(str, "(%a+)=(%d+),(%d+);") do
|
|
|
|
local l = key:lower()
|
|
|
|
if keytable[l] then
|
|
|
|
keys[key] = {keytable[l], tonumber(on), tonumber(off)}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
return keys
|
|
|
|
end
|
2007-03-19 19:43:40 +00:00
|
|
|
|
2007-09-16 00:05:31 +00:00
|
|
|
function TOOL:LeftClick(trace)
|
|
|
|
if not trace.HitPos then return false end
|
|
|
|
if trace.Entity:IsPlayer() then return false end
|
|
|
|
if CLIENT then return true end
|
2007-03-19 19:43:40 +00:00
|
|
|
|
|
|
|
local ply = self:GetOwner()
|
|
|
|
|
2007-09-16 00:05:31 +00:00
|
|
|
if trace.Entity:IsValid() and trace.Entity:GetClass() == "gmod_wire_pod" and trace.Entity:GetTable().pl == ply then
|
|
|
|
trace.Entity:SetKeys(ParseKeys(self:GetClientInfo("Keys")))
|
|
|
|
return true
|
|
|
|
end
|
2007-03-19 19:43:40 +00:00
|
|
|
|
2007-09-16 00:05:31 +00:00
|
|
|
if not self:GetSWEP():CheckLimit("wire_pods") then return false end
|
2007-03-19 19:43:40 +00:00
|
|
|
|
|
|
|
local Ang = trace.HitNormal:Angle()
|
|
|
|
Ang.pitch = Ang.pitch + 90
|
|
|
|
|
2007-09-16 00:05:31 +00:00
|
|
|
-- local Advanced = self:GetClientNumber("Advanced") ~= 0
|
2007-05-15 19:35:58 +00:00
|
|
|
|
2007-09-16 00:05:31 +00:00
|
|
|
local wire_pod = MakeWirePod(ply, trace.HitPos, self:GetClientNumber("Advanced") ~= 0, Ang, nil, ParseKeys(self:GetClientInfo("Keys")))
|
2007-03-19 19:43:40 +00:00
|
|
|
|
2007-09-16 00:05:31 +00:00
|
|
|
wire_pod:SetPos(trace.HitPos - trace.HitNormal * wire_pod:OBBMins().z)
|
2007-04-04 05:33:36 +00:00
|
|
|
|
2007-03-28 23:24:55 +00:00
|
|
|
local const = WireLib.Weld(wire_pod, trace.Entity, trace.PhysicsBone, true)
|
2007-03-19 19:43:40 +00:00
|
|
|
|
|
|
|
undo.Create("Wire Pod")
|
2007-09-16 00:05:31 +00:00
|
|
|
undo.AddEntity(wire_pod)
|
|
|
|
undo.AddEntity(const)
|
|
|
|
undo.SetPlayer(ply)
|
2007-03-19 19:43:40 +00:00
|
|
|
undo.Finish()
|
|
|
|
|
2007-09-16 00:05:31 +00:00
|
|
|
ply:AddCleanup("wire_pods", wire_pod)
|
2007-03-19 19:43:40 +00:00
|
|
|
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
2007-09-16 00:05:31 +00:00
|
|
|
function TOOL:RightClick(trace)
|
2007-09-22 18:03:33 +00:00
|
|
|
if (self:GetStage() == 0) and (trace.Entity:GetClass() == "gmod_wire_pod" or trace.Entity:GetClass() == "gmod_wire_adv_pod") then
|
|
|
|
self.PodCont = trace.Entity
|
|
|
|
self:SetStage(1)
|
|
|
|
return true
|
|
|
|
elseif self:GetStage() == 1 and trace.Entity.GetPassenger then
|
|
|
|
self.PodCont:Setup(trace.Entity)
|
|
|
|
self:SetStage(0)
|
|
|
|
self.PodCont = nil
|
|
|
|
return true
|
|
|
|
else
|
2007-09-19 15:28:15 +00:00
|
|
|
return false
|
|
|
|
end
|
2007-03-19 19:43:40 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function TOOL:Reload(trace)
|
2007-09-16 00:05:31 +00:00
|
|
|
self:SetStage(0)
|
2007-09-22 18:03:33 +00:00
|
|
|
self.PodCont = nil
|
2007-03-19 19:43:40 +00:00
|
|
|
end
|
|
|
|
|
2007-09-16 00:05:31 +00:00
|
|
|
if SERVER then
|
|
|
|
|
|
|
|
function MakeWirePod(pl, Pos, Advanced, Ang, pod, Keys)
|
|
|
|
if not pl:CheckLimit("wire_pods") then return false end
|
|
|
|
-- if Advanced and Keys then return false end
|
|
|
|
if Advanced and Keys then Keys = nil end
|
|
|
|
local wire_pod
|
|
|
|
if Advanced then
|
|
|
|
wire_pod = ents.Create("gmod_wire_adv_pod")
|
|
|
|
else
|
|
|
|
wire_pod = ents.Create("gmod_wire_pod")
|
2007-05-15 19:35:58 +00:00
|
|
|
end
|
|
|
|
|
2007-09-16 00:05:31 +00:00
|
|
|
if not wire_pod:IsValid() then return false end
|
2007-03-19 19:43:40 +00:00
|
|
|
|
2007-09-16 00:05:31 +00:00
|
|
|
wire_pod:SetAngles(Ang)
|
|
|
|
wire_pod:SetPos(Pos)
|
|
|
|
-- wire_pod:SetModel(Model("models/jaanus/wiretool/wiretool_siren.mdl"))
|
2007-03-19 19:43:40 +00:00
|
|
|
wire_pod:Spawn()
|
2007-09-16 00:05:31 +00:00
|
|
|
-- Setup on secondary
|
|
|
|
-- wire_pod:GetTable():Setup()
|
|
|
|
if pod then wire_pod:GetTable():Setup(pod) end
|
|
|
|
wire_pod:GetTable():SetPlayer(pl)
|
2007-03-19 19:43:40 +00:00
|
|
|
|
|
|
|
local ttable = {
|
|
|
|
pl = pl,
|
2007-06-18 01:37:27 +00:00
|
|
|
Advanced = Advanced,
|
2007-03-19 19:43:40 +00:00
|
|
|
}
|
|
|
|
|
2007-09-16 00:05:31 +00:00
|
|
|
table.Merge(wire_pod:GetTable(), ttable)
|
|
|
|
|
|
|
|
pl:AddCount("wire_pods", wire_pod)
|
|
|
|
|
|
|
|
if Keys then
|
|
|
|
wire_pod:SetKeys(Keys)
|
|
|
|
end
|
2007-03-19 19:43:40 +00:00
|
|
|
|
|
|
|
return wire_pod
|
|
|
|
end
|
|
|
|
|
2007-09-16 00:05:31 +00:00
|
|
|
duplicator.RegisterEntityClass("gmod_wire_pod", MakeWirePod, "Pos", "Advanced", "Ang", "Pod", "Keys","Vel", "aVel", "frozen")
|
|
|
|
local function MakeWireAdvPod(pl, Pos, Advanced, Ang, pod)
|
|
|
|
return MakeWirePod(pl, Pos, true, Ang, pod)
|
2007-06-18 01:37:27 +00:00
|
|
|
end
|
|
|
|
duplicator.RegisterEntityClass("gmod_wire_adv_pod", MakeWireAdvPod, "Pos", "Advanced", "Ang", "Pod", "Vel", "aVel", "frozen")
|
2007-03-19 19:43:40 +00:00
|
|
|
|
|
|
|
end
|
|
|
|
|
2007-09-16 00:05:31 +00:00
|
|
|
function TOOL:UpdateGhostWirePod(ent, player)
|
|
|
|
if not ent or not ent:IsValid() then return end
|
2007-03-19 19:43:40 +00:00
|
|
|
|
2007-09-16 00:05:31 +00:00
|
|
|
local tr = utilx.GetPlayerTrace(player, player:GetCursorAimVector())
|
|
|
|
local trace = util.TraceLine(tr)
|
2007-03-19 19:43:40 +00:00
|
|
|
|
2007-09-16 00:05:31 +00:00
|
|
|
if not trace.Hit or trace.Entity:IsPlayer() or trace.Entity:GetClass() == "gmod_wire_pod" then
|
|
|
|
ent:SetNoDraw(true)
|
2007-03-19 19:43:40 +00:00
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
local Ang = trace.HitNormal:Angle()
|
|
|
|
Ang.pitch = Ang.pitch + 90
|
|
|
|
|
2007-09-16 00:05:31 +00:00
|
|
|
ent:SetPos(trace.HitPos - trace.HitNormal * ent:OBBMins().z)
|
|
|
|
ent:SetAngles(Ang)
|
2007-03-19 19:43:40 +00:00
|
|
|
|
2007-09-16 00:05:31 +00:00
|
|
|
ent:SetNoDraw(false)
|
2007-03-19 19:43:40 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function TOOL:Think()
|
2007-09-16 00:05:31 +00:00
|
|
|
if not self.GhostEntity or not self.GhostEntity:IsValid() or self.GhostEntity:GetModel() ~= self.Model then
|
|
|
|
self:MakeGhostEntity(self.Model, Vector(0,0,0), Angle(0,0,0))
|
2007-03-19 19:43:40 +00:00
|
|
|
end
|
|
|
|
|
2007-09-16 00:05:31 +00:00
|
|
|
self:UpdateGhostWirePod(self.GhostEntity, self:GetOwner())
|
2007-03-19 19:43:40 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function TOOL.BuildCPanel(panel)
|
|
|
|
panel:AddControl("Header", { Text = "#Tool_wire_pod_name", Description = "#Tool_wire_pod_desc" })
|
|
|
|
|
|
|
|
panel:AddControl("ComboBox", {
|
|
|
|
Label = "#Presets",
|
|
|
|
MenuButton = "1",
|
|
|
|
Folder = "wire_pod",
|
|
|
|
|
|
|
|
Options = {
|
|
|
|
Default = {
|
|
|
|
wire_pod_pod = "0",
|
|
|
|
}
|
|
|
|
},
|
|
|
|
CVars = {
|
|
|
|
}
|
|
|
|
})
|
2007-05-15 19:35:58 +00:00
|
|
|
panel:AddControl("CheckBox", {
|
|
|
|
Label = "#WirePodTool_Advanced",
|
|
|
|
Command = "wire_pod_Advanced"
|
|
|
|
})
|
2007-09-16 00:05:31 +00:00
|
|
|
panel:AddControl("TextBox", {
|
|
|
|
Label = "#WirePodTool_Keys",
|
|
|
|
Command = "wire_pod_Keys",
|
|
|
|
Disabled = "true" -- Does this work?
|
|
|
|
})
|
2007-05-30 16:40:50 +00:00
|
|
|
end
|