2007-02-19 16:52:35 +00:00
|
|
|
|
|
|
|
AddCSLuaFile( "cl_init.lua" )
|
|
|
|
AddCSLuaFile( "shared.lua" )
|
|
|
|
|
|
|
|
include('shared.lua')
|
|
|
|
|
2007-02-20 03:05:36 +00:00
|
|
|
ENT.WireDebugName = "Forcer"
|
2007-04-04 06:58:37 +00:00
|
|
|
ENT.OverlayDelay = .05
|
2007-02-19 16:52:35 +00:00
|
|
|
|
|
|
|
|
|
|
|
function ENT:Initialize()
|
|
|
|
self.Entity:PhysicsInit( SOLID_VPHYSICS )
|
|
|
|
self.Entity:SetMoveType( MOVETYPE_VPHYSICS )
|
|
|
|
self.Entity:SetSolid( SOLID_VPHYSICS )
|
2007-02-20 03:05:36 +00:00
|
|
|
|
2007-03-25 20:55:36 +00:00
|
|
|
self.F = 0
|
|
|
|
self.FoO = 0
|
|
|
|
self.V = 0
|
|
|
|
|
2007-03-24 06:34:23 +00:00
|
|
|
self.Inputs = Wire_CreateInputs(self.Entity, { "Force", "OffsetForce", "Velocity" })
|
2007-11-29 16:38:39 +00:00
|
|
|
self:SetForceBeam(false)
|
2007-02-19 16:52:35 +00:00
|
|
|
end
|
|
|
|
|
2007-02-20 03:05:36 +00:00
|
|
|
function ENT:Setup(force, length, showbeam)
|
2007-03-24 06:34:23 +00:00
|
|
|
self.Force = math.max(force, 1)
|
|
|
|
self.Tlength = math.max(length, 1)
|
|
|
|
self.F = 0
|
|
|
|
self.FoO = 0
|
|
|
|
self.V = 0
|
2007-02-20 03:05:36 +00:00
|
|
|
if (showbeam) then
|
|
|
|
self:SetBeamLength(length)
|
|
|
|
else
|
|
|
|
self:SetBeamLength(0)
|
|
|
|
end
|
2007-03-26 01:01:03 +00:00
|
|
|
self:TriggerInput("Force", 0)
|
2007-02-19 16:52:35 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function ENT:TriggerInput(iname, value)
|
2007-03-24 06:34:23 +00:00
|
|
|
if (iname == "Force") then
|
|
|
|
self.F = value
|
2007-11-29 16:38:39 +00:00
|
|
|
self:SetForceBeam(self.F != 0)
|
2007-03-24 06:34:23 +00:00
|
|
|
self:ShowOutput()
|
|
|
|
elseif (iname == "OffsetForce") then
|
|
|
|
self.FoO = value
|
|
|
|
self:ShowOutput()
|
|
|
|
elseif (iname == "Velocity") then
|
|
|
|
self.V = value
|
2008-01-12 21:56:29 +00:00
|
|
|
self:SetForceBeam(self.V != 0)
|
2007-03-24 06:34:23 +00:00
|
|
|
self:ShowOutput()
|
2007-02-19 16:52:35 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2007-02-20 03:05:36 +00:00
|
|
|
function ENT:Think()
|
2007-03-24 06:34:23 +00:00
|
|
|
|
2007-04-04 06:58:37 +00:00
|
|
|
if (self.F > 0.1) or (self.FoO > 0.1) or (self.V > 0.1)
|
|
|
|
or (self.F < -0.1) or (self.FoO < -0.1) or (self.V < -0.1) then
|
2007-04-01 08:01:45 +00:00
|
|
|
|
|
|
|
local vForward = self.Entity:GetUp()
|
|
|
|
local vStart = self.Entity:GetPos() + vForward*self.Entity:OBBMaxs().z
|
|
|
|
|
|
|
|
local trace = {}
|
|
|
|
trace.start = vStart
|
|
|
|
trace.endpos = vStart + (vForward * self.Tlength)
|
|
|
|
trace.filter = { self.Entity }
|
|
|
|
|
|
|
|
local trace = util.TraceLine( trace )
|
2007-03-24 06:34:23 +00:00
|
|
|
|
2007-04-01 08:01:45 +00:00
|
|
|
if (trace.Entity) and (trace.Entity:IsValid()) then // and (!trace.Entity:IsPlayer()) then
|
|
|
|
|
|
|
|
if (trace.Entity:GetMoveType() == MOVETYPE_VPHYSICS) then
|
|
|
|
local phys = trace.Entity:GetPhysicsObject()
|
|
|
|
if (phys:IsValid()) then
|
2007-04-04 06:58:37 +00:00
|
|
|
if (self.F > 0.1) or (self.F < -0.1) then phys:ApplyForceCenter( vForward * self.Force * self.F ) end
|
|
|
|
if (self.FoO > 0.1) or (self.FoO < -0.1) then phys:ApplyForceOffset( vForward * self.FoO, trace.HitPos ) end
|
2007-04-26 05:35:36 +00:00
|
|
|
//if (self.V > 0.1) or (self.V < -0.1) then phys:SetVelocity( vForward * self.V ) end
|
|
|
|
if (self.V > 0.1) or (self.V < -0.1) then phys:SetVelocityInstantaneous( vForward * self.V ) end
|
2007-04-01 08:01:45 +00:00
|
|
|
end
|
|
|
|
else
|
2007-04-04 06:58:37 +00:00
|
|
|
if (self.V > 0.1) or (self.V < -0.1) then trace.Entity:SetVelocity( vForward * self.V ) end
|
2007-03-24 06:34:23 +00:00
|
|
|
end
|
2007-04-01 08:01:45 +00:00
|
|
|
|
2007-03-24 06:34:23 +00:00
|
|
|
end
|
|
|
|
|
2007-02-19 16:52:35 +00:00
|
|
|
end
|
2007-02-20 03:05:36 +00:00
|
|
|
|
2007-04-01 08:01:45 +00:00
|
|
|
self.Entity:NextThink(CurTime() + 0.1)
|
2007-03-24 06:34:23 +00:00
|
|
|
return true
|
2007-02-19 16:52:35 +00:00
|
|
|
end
|
|
|
|
|
2007-03-24 06:34:23 +00:00
|
|
|
function ENT:ShowOutput()
|
|
|
|
self:SetOverlayText(
|
|
|
|
"Forcer\nCenter Force= "..tostring(math.Round(self.F * self.Force))..
|
|
|
|
"\nOffset Force= "..tostring(math.Round(self.FoO))..
|
|
|
|
"\nVelocity= "..tostring(math.Round(self.V))
|
|
|
|
)
|
2007-02-19 16:52:35 +00:00
|
|
|
end
|
2007-03-26 01:01:03 +00:00
|
|
|
|
|
|
|
function ENT:ApplyDupeInfo(ply, ent, info, GetEntByID)
|
|
|
|
//Moves old "A" input to new "Force" input for older saves
|
|
|
|
if (info.Wires) and (info.Wires.A) then
|
|
|
|
info.Wires.Force = info.Wires.A
|
|
|
|
info.Wires.A = nil
|
|
|
|
end
|
|
|
|
|
|
|
|
self.BaseClass.ApplyDupeInfo(self, ply, ent, info, GetEntByID)
|
|
|
|
end
|