136 lines
3.0 KiB
Lua
136 lines
3.0 KiB
Lua
|
|
---------------------
|
|
-- Your Name is Benny
|
|
---------------------
|
|
|
|
AddCSLuaFile()
|
|
|
|
ENT.Type = "anim"
|
|
ENT.Base = "base_anim"
|
|
ENT.BennyItem = true
|
|
ENT.AutomaticFrameAdvance = true
|
|
|
|
function ENT:Initialize()
|
|
self:SetModel( self.Class.Model or "models/weapons/w_357.mdl" )
|
|
if SERVER then
|
|
self:PhysicsInit( SOLID_VPHYSICS )
|
|
self:SetCollisionGroup( COLLISION_GROUP_WEAPON )
|
|
self:GetPhysicsObject():Wake()
|
|
end
|
|
|
|
self.Class:Initialize( self )
|
|
end
|
|
|
|
if SERVER then
|
|
util.AddNetworkString("Benny_ItemSlept")
|
|
else
|
|
net.Receive("Benny_ItemSlept", function()
|
|
local ent = net.ReadEntity()
|
|
|
|
if ent:IsValid() then
|
|
ent:SetPredictable( false )
|
|
print("CL Stopping prediction on", ent)
|
|
end
|
|
end)
|
|
end
|
|
|
|
function ENT:PlayAnimation( seqid, speed )
|
|
self:ResetSequence( seqid )
|
|
-- Interpolation
|
|
if CLIENT and IsFirstTimePredicted() then
|
|
self.CLCycle = 0
|
|
self.StartTime = UnPredictedCurTime()
|
|
end
|
|
end
|
|
|
|
function ENT:Think()
|
|
self:NextThink( CurTime() )
|
|
if CLIENT then
|
|
self:SetNextClientThink( CurTime()-5 )
|
|
|
|
-- Interpolation
|
|
if self:GetOwner() == LocalPlayer() then
|
|
local diff = (UnPredictedCurTime()) - (self.LastThink or UnPredictedCurTime())
|
|
|
|
if diff then
|
|
self.CLCycle = math.Approach( self.CLCycle or 0, 1, ( 1/self:SequenceDuration() ) * diff )
|
|
self:SetCycle( self.CLCycle )
|
|
self.LastThink = UnPredictedCurTime()
|
|
end
|
|
end
|
|
end
|
|
|
|
if CLIENT then return true end
|
|
self.BAsleep = self.BAsleep or false
|
|
|
|
local ph = self:GetPhysicsObject()
|
|
if ph:IsValid() and !self:GetOwner():IsValid() then
|
|
|
|
if ph:IsAsleep() then
|
|
if !self.BAsleep then
|
|
net.Start("Benny_ItemSlept")
|
|
net.WriteEntity(self)
|
|
net.Broadcast()
|
|
print("SV Stopping prediction on", self)
|
|
self:SetCollisionGroup( COLLISION_GROUP_WEAPON )
|
|
self.BAsleep = true
|
|
end
|
|
elseif self.BAsleep then
|
|
-- print(self, "Woke up")
|
|
self.BAsleep = false
|
|
end
|
|
|
|
end
|
|
|
|
return true
|
|
end
|
|
|
|
local function recurse( modify, includer )
|
|
local basevars = ITEMS[includer].BaseClass
|
|
if ITEMS[includer].BaseClass then
|
|
recurse( modify, ITEMS[includer].Base )
|
|
end
|
|
|
|
local localvars = ITEMS[includer]:GetRaw("Vars")
|
|
if localvars then
|
|
for i, v in pairs( localvars ) do
|
|
if !modify[i] then modify[i] = {} end
|
|
table.Add( modify[i], v )
|
|
end
|
|
end
|
|
end
|
|
|
|
function ENT:SetupDataTables()
|
|
local NWVars = { ["Float"] = { "AnimStartTime", "AnimEndTime" } }
|
|
recurse( NWVars, self.ID )
|
|
for varname, varlist in pairs(NWVars) do
|
|
--local numba = 0
|
|
for keyind, keyname in ipairs(varlist) do
|
|
self:NetworkVar( varname, keyname )
|
|
--numba = numba + 1
|
|
end
|
|
end
|
|
end
|
|
|
|
if SERVER then
|
|
function ENT:PhysicsCollide( data, collider )
|
|
if ( data.DeltaTime > 0.1 ) then
|
|
--self:EmitSound( str, 70, 100, 1, CHAN_STATIC )
|
|
end
|
|
return
|
|
end
|
|
else
|
|
hook.Add("NotifyShouldTransmit", "AE_NotifyShouldTransmit", function( ent, shouldtransmit )
|
|
if ent.BennyItem then
|
|
if shouldtransmit then
|
|
if ent:GetOwner() == LocalPlayer() then
|
|
ent:SetPredictable( true )
|
|
end
|
|
else
|
|
ent:SetPredictable( false )
|
|
end
|
|
end
|
|
end)
|
|
end
|
|
|