2007-03-19 19:43:40 +00:00
|
|
|
AddCSLuaFile( "cl_init.lua" )
|
|
|
|
AddCSLuaFile( "shared.lua" )
|
|
|
|
|
|
|
|
include('shared.lua')
|
|
|
|
|
|
|
|
ENT.WireDebugName = "Pod Controller"
|
|
|
|
|
|
|
|
local MODEL = Model("models/jaanus/wiretool/wiretool_siren.mdl")
|
|
|
|
|
|
|
|
function ENT:Initialize()
|
|
|
|
self.Entity:SetModel( MODEL )
|
|
|
|
self.Entity:PhysicsInit( SOLID_VPHYSICS )
|
|
|
|
self.Entity:SetMoveType( MOVETYPE_VPHYSICS )
|
|
|
|
self.Entity:SetSolid( SOLID_VPHYSICS )
|
|
|
|
|
2007-06-26 00:34:02 +00:00
|
|
|
-- Output self.Keys. Format: self.Keys["name"] = IN_*
|
|
|
|
self.Keys = { }
|
|
|
|
self.Keys["W"] = IN_FORWARD
|
|
|
|
self.Keys["A"] = IN_MOVELEFT
|
|
|
|
self.Keys["S"] = IN_BACK
|
|
|
|
self.Keys["D"] = IN_MOVERIGHT
|
|
|
|
self.Keys["Mouse1"] = IN_ATTACK
|
|
|
|
self.Keys["R"] = IN_RELOAD
|
2007-03-19 19:43:40 +00:00
|
|
|
|
|
|
|
-- Invert the table to use it with Wire_CreateOutputs
|
|
|
|
local outputs = { }
|
|
|
|
local n = 1
|
|
|
|
|
2007-06-26 00:34:02 +00:00
|
|
|
for k, v in pairs( self.Keys ) do
|
2007-03-19 19:43:40 +00:00
|
|
|
outputs[n] = k
|
|
|
|
n = n + 1
|
|
|
|
end
|
2007-07-23 02:24:48 +00:00
|
|
|
|
2007-04-28 19:46:24 +00:00
|
|
|
outputs[n] = "Active"
|
|
|
|
|
2007-05-05 01:54:41 +00:00
|
|
|
self.VPos = Vector(0, 0, 0)
|
|
|
|
|
2007-03-19 19:43:40 +00:00
|
|
|
-- Create outputs
|
|
|
|
self.Outputs = Wire_CreateOutputs( self.Entity, outputs )
|
2007-05-23 17:49:04 +00:00
|
|
|
self.Inputs = Wire_CreateInputs( self.Entity, { "Lock" } )
|
2007-04-22 09:08:30 +00:00
|
|
|
self:SetOverlayText( "Pod Controller" )
|
2007-08-24 00:24:58 +00:00
|
|
|
self.TTLFP = CurTime()
|
2007-03-19 19:43:40 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
-- Link to pod
|
|
|
|
function ENT:Setup( pod )
|
|
|
|
self.Pod = pod
|
|
|
|
end
|
|
|
|
|
|
|
|
-- No inputs
|
|
|
|
function ENT:TriggerInput(iname, value)
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
function ENT:ShowOutput(value)
|
|
|
|
if (value ~= self.PrevOutput) then
|
2007-04-22 09:08:30 +00:00
|
|
|
self:SetOverlayText( "Pod Controller" )
|
2007-03-19 19:43:40 +00:00
|
|
|
self.PrevOutput = value
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function ENT:OnRestore()
|
2007-06-26 00:34:02 +00:00
|
|
|
self.Keys = { }
|
|
|
|
self.Keys["W"] = IN_FORWARD
|
|
|
|
self.Keys["A"] = IN_MOVELEFT
|
|
|
|
self.Keys["S"] = IN_BACK
|
|
|
|
self.Keys["D"] = IN_MOVERIGHT
|
|
|
|
self.Keys["Mouse1"] = IN_ATTACK
|
|
|
|
self.Keys["R"] = IN_RELOAD
|
2007-03-23 06:51:08 +00:00
|
|
|
|
2007-04-22 09:08:30 +00:00
|
|
|
self.BaseClass.OnRestore(self)
|
2007-03-19 19:43:40 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
-- Called every 0.01 seconds, check for key down
|
|
|
|
function ENT:Think()
|
|
|
|
-- Check that we have a pod
|
|
|
|
if self.Pod then
|
|
|
|
-- Check if we should look for player entering/exiting the vehicle TTLFP = TimeToLookForPod
|
|
|
|
if self.TTLFP < CurTime() then
|
2007-05-05 01:54:41 +00:00
|
|
|
-- Check if the old player still is in our vehicle
|
2007-03-19 19:43:40 +00:00
|
|
|
if !(self.Ply and self.Ply:GetVehicle() == self.Pod) then
|
|
|
|
-- Get all players
|
|
|
|
local plys = player.GetAll()
|
|
|
|
self.Ply = nil
|
|
|
|
-- Loop through all players and check if their vehicle is our vehicle
|
|
|
|
for k,v in pairs(plys) do
|
2007-06-11 15:08:11 +00:00
|
|
|
if v:GetVehicle() == self.Pod then self.Ply = v; break end
|
2007-03-19 19:43:40 +00:00
|
|
|
end
|
2007-04-28 19:46:24 +00:00
|
|
|
|
|
|
|
if self.Ply then Wire_TriggerOutput( self.Entity, "Active", 1)
|
|
|
|
else Wire_TriggerOutput( self.Entity, "Active", 0) end
|
2007-03-19 19:43:40 +00:00
|
|
|
end
|
|
|
|
-- Look for players again in 1/10 second
|
|
|
|
self.TTLFP = CurTime() + 0.1
|
|
|
|
end
|
|
|
|
|
|
|
|
if self.Ply then
|
2007-06-26 00:34:02 +00:00
|
|
|
-- Loop through all the self.Keys, and check if they was pressed last frame
|
|
|
|
for k, v in pairs( self.Keys ) do
|
2007-03-19 19:43:40 +00:00
|
|
|
if self.Ply:KeyDownLast( v ) then Wire_TriggerOutput( self.Entity, k, 1 )
|
|
|
|
else Wire_TriggerOutput( self.Entity, k, 0 ) end
|
|
|
|
end
|
2007-06-11 20:04:22 +00:00
|
|
|
local trace = util.GetPlayerTrace(self.Ply)
|
|
|
|
trace.filter = self.Pod
|
|
|
|
self.VPos = util.TraceLine(trace).HitPos
|
2007-03-19 19:43:40 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
self.Entity:NextThink(CurTime() + 0.01)
|
|
|
|
return true
|
|
|
|
end
|
2007-04-04 05:33:36 +00:00
|
|
|
|
2007-05-23 17:46:21 +00:00
|
|
|
function ENT:TriggerInput(iname, value)
|
|
|
|
if !(self.Pod && self.Pod:IsValid()) then return end
|
|
|
|
if value > 0 then
|
|
|
|
self.Pod:Fire("Lock", "1", 0)
|
|
|
|
else
|
|
|
|
self.Pod:Fire("Unlock", "1", 0)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2007-05-05 01:54:41 +00:00
|
|
|
function ENT:GetBeaconPos(sensor)
|
|
|
|
return self.VPos
|
|
|
|
end
|
2007-04-04 05:33:36 +00:00
|
|
|
|
|
|
|
//Duplicator support to save pod link (TAD2020)
|
|
|
|
function ENT:BuildDupeInfo()
|
|
|
|
local info = self.BaseClass.BuildDupeInfo(self) or {}
|
|
|
|
|
2007-08-24 00:24:58 +00:00
|
|
|
if (self.Pod and self.Pod:IsValid()) then
|
2007-04-04 05:33:36 +00:00
|
|
|
info.pod = self.Pod:EntIndex()
|
|
|
|
end
|
|
|
|
|
|
|
|
return info
|
|
|
|
end
|
|
|
|
|
|
|
|
function ENT:ApplyDupeInfo(ply, ent, info, GetEntByID)
|
|
|
|
self.BaseClass.ApplyDupeInfo(self, ply, ent, info, GetEntByID)
|
|
|
|
|
|
|
|
if (info.pod) then
|
|
|
|
self.Pod = GetEntByID(info.pod)
|
2007-08-24 00:24:58 +00:00
|
|
|
if !(self.Pod and self.Pod:IsValid()) then
|
2007-04-04 05:33:36 +00:00
|
|
|
self.Pod = ents.GetByIndex(info.pod)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|