// // // This is the default entity base. // You can add to this is completely replace it if you know what you're doing. // // ENT.Type = "anim" ENT.PrintName = "Self Regenerating Suit Charger" ENT.Author = "Henoik" ENT.Contact = "" ENT.Purpose = "" ENT.Instructions = "" if CLIENT then function ENT:Draw() self:DrawModel() end end if SERVER then /*--------------------------------------------------------- Initialize ---------------------------------------------------------*/ function ENT:Initialize() self:SetModel("models/props_combine/suit_charger001.mdl") self:PhysicsInit( SOLID_VPHYSICS ) self:SetMoveType( MOVETYPE_VPHYSICS ) self:SetSolid( SOLID_VPHYSICS ) self:DrawShadow( true ) self:SetUseType( CONTINUOUS_USE ) self:SetCollisionGroup( COLLISION_GROUP_WEAPON ) self:SetNetworkedString("Owner", "World") self.MaxCharge = 200 self.Charge = self.MaxCharge self.ChargeTime = CurTime() self.ChargeSound = CreateSound( self.Entity, "items/suitcharge1.wav" ) self.Done = true local phys = self:GetPhysicsObject() if (phys:IsValid()) then phys:Wake() end end /*--------------------------------------------------------- Think ---------------------------------------------------------*/ function ENT:Think() local targ = self.Charge / self.MaxCharge local perc = perc or targ perc = Lerp( 0.2, perc, targ ) self:SetCycle( 1 - perc ) if self.ChargeTime < CurTime() then self.Charge = math.Clamp( self.Charge + 0.07, 0, self.MaxCharge ) end if self.Charge == self.MaxCharge and !self.Done then self:ChargeCompleted() self.Done = true end if self.User then if self.Charge > 0 then if !self.User:KeyDown( IN_USE ) or ( self.User:Armor() >= 100 ) then self.ChargeSound:Stop() self:EmitSound( "items/suitchargeno1.wav" ) self.User = nil end end end self:NextThink( CurTime() + 0.01 ) return true end function ENT:dsnd( delay, snd ) timer.Simple( delay, function() if self:IsValid() then self:EmitSound( snd ) end end) end function ENT:ChargeCompleted() self:EmitSound( "HL1/fvox/bell.wav" ) self:dsnd( 1.4, "HL1/fvox/onehundred.wav" ) self:dsnd( 2.4, "HL1/fvox/percent.wav" ) self:dsnd( 3.4, "HL1/fvox/power_restored.wav" ) end function ENT:Use( ply ) ply.uCharge = ply.uCharge or CurTime() ply.uHeal = ply.uHeal or CurTime() if self.User then if self.User != ply then return end end if ply.uCharge < CurTime() then if self.Charge < 1 then self:EmitSound( "items/suitchargeno1.wav" ) ply.uCharge = CurTime() + 0.75 self.ChargeSound:Stop() return end if ply:Armor() < 100 then if !self.User then self:EmitSound("items/suitchargeok1.wav") self.ChargeSound:Play() end self.Done = false ply.uCharge = CurTime() + 0.03 self.ChargeTime = CurTime() + 10 self.Charge = math.Clamp(self.Charge - 0.4 , 0, self.MaxCharge) self.User = ply if ply.uHeal < CurTime() then ply:SetArmor( math.Clamp( ply:Armor() + 1, 0, 100 ) ) ply.uHeal = CurTime() + 0.15 end end end end end function ENT:SpawnFunction( ply, tr ) if ( !tr.Hit ) then return end local SpawnPos = tr.HitPos + tr.HitNormal * 100 local ent = ents.Create( ClassName ) ent:SetPos( SpawnPos ) ent:Spawn() ent:Activate() return ent end