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

224 lines
6.2 KiB
Lua
Raw Normal View History

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:")
language.Add("WirePodTool_Advanced", "Bloated Controller?")
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
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"
TOOL.ClientConVar["Advanced"] = "0"
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
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()
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
if self:GetStage() == 1 then
if not trace.Entity.GetPassenger then return false end
self.PodCont:Setup(trace.Entity)
self:SetStage(0)
2007-03-19 19:43:40 +00:00
return true
end
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
-- local Advanced = self:GetClientNumber("Advanced") ~= 0
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
wire_pod:SetPos(trace.HitPos - trace.HitNormal * wire_pod:OBBMins().z)
local const = WireLib.Weld(wire_pod, trace.Entity, trace.PhysicsBone, true)
2007-03-19 19:43:40 +00:00
undo.Create("Wire Pod")
undo.AddEntity(wire_pod)
undo.AddEntity(const)
undo.SetPlayer(ply)
2007-03-19 19:43:40 +00:00
undo.Finish()
ply:AddCleanup("wire_pods", wire_pod)
2007-03-19 19:43:40 +00:00
return true
end
function TOOL:RightClick(trace)
2007-09-19 15:28:15 +00:00
if not (trace.Entity and trace.Entity:IsValid() and (trace.Entity:GetClass() == "gmod_wire_pod" or trace.Entity:GetClass() == "gmod_wire_pod_adv")) then
return false
end
if CLIENT then return true end
self.PodCont = trace.Entity
self:SetStage(1)
return true
2007-03-19 19:43:40 +00:00
end
function TOOL:Reload(trace)
self:SetStage(0)
2007-03-19 19:43:40 +00:00
end
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")
end
if not wire_pod:IsValid() then return false end
2007-03-19 19:43:40 +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()
-- 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
}
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
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
function TOOL:UpdateGhostWirePod(ent, player)
if not ent or not ent:IsValid() then return end
2007-03-19 19:43:40 +00:00
local tr = utilx.GetPlayerTrace(player, player:GetCursorAimVector())
local trace = util.TraceLine(tr)
2007-03-19 19:43:40 +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
ent:SetPos(trace.HitPos - trace.HitNormal * ent:OBBMins().z)
ent:SetAngles(Ang)
2007-03-19 19:43:40 +00:00
ent:SetNoDraw(false)
2007-03-19 19:43:40 +00:00
end
function TOOL:Think()
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
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 = {
}
})
panel:AddControl("CheckBox", {
Label = "#WirePodTool_Advanced",
Command = "wire_pod_Advanced"
})
panel:AddControl("TextBox", {
Label = "#WirePodTool_Keys",
Command = "wire_pod_Keys",
Disabled = "true" -- Does this work?
})
end