--prop AddCSLuaFile("cl_init.lua") AddCSLuaFile("shared.lua") include("shared.lua") if file.Exists("../lua/entities/base_wire_entity/init.lua") then include("entities/base_wire_entity/init.lua") -- WIREMOD IS MADE OF AIDS end local RECHARGE_RATE=1 -- Time in seconds to recharge local RECHARGE_NUM=1 -- Amount to recharge function ENT:KeyValue( key, value ) if ( key == "size" ) then self.Radius=tonumber(value) end end function ENT:Initialize() self.Entity:PhysicsInit(SOLID_VPHYSICS) self.Entity:SetMoveType(MOVETYPE_VPHYSICS) self.Entity:SetSolid(SOLID_VPHYSICS) if WireAddon then self.Inputs = Wire_CreateInputs(self.Entity, { "toggle" }) end if WireAddon then self.Outputs = Wire_CreateOutputs(self.Entity, { "Energy" }) end self.Entity:SetNetworkedBool("on",false) self.Entity:SetNetworkedInt("energy",100) self.Entity:SetNetworkedInt("size",self.Radius) self.sEnt=nil self.FrameDrain=true self.Entity:Recharge() end function ENT:Toggle(wirefail) if self.Entity:GetNetworkedBool("on") or wirefail and wirefail==0 then self.Entity:SetNetworkedBool("on",false) if self.sEnt and self.sEnt:IsValid() then self.sEnt:Remove() end elseif self.Entity:GetNetworkedBool("on")==false or wirefail and wirefail==1 then self.Entity:SetNetworkedBool("on",true) if self.sEnt and self.sEnt:IsValid() then self.sEnt:Remove() end self.sEnt=ents.Create( 'p_shield' ) if !self.sEnt:IsValid() then return end self.sEnt:SetPos(self.Entity:GetPos()) self.sEnt:SetParent(self.Entity) self.sEnt:SetKeyValue("size",self.Radius) self.sEnt:Spawn() self.Entity:SetNetworkedBool("dostart",true) timer.Simple(2,self.Entity.StopEffects,self.Entity) end end function ENT:StopEffects() if self and self.Entity and self.Entity:IsValid() then self.Entity:SetNetworkedBool("dostart",false) end end function ENT:TriggerInput(input,value) if input=="toggle" then self.Entity:Toggle(value) end end function ENT:AcceptInput(name,activator,caller) if name=="toggle" then self.Entity:Toggle() end end function ENT:Recharge() if not self or not self.Entity then return end if self.Entity:GetNetworkedInt("energy")<100 then self.Entity:SetNetworkedInt("energy",math.Clamp(self.Entity:GetNetworkedInt("energy")+RECHARGE_NUM,-10,100)) end timer.Simple(RECHARGE_RATE,self.Recharge,self) end function ENT:Think() if WireAddon then Wire_TriggerOutput(self.Entity, "Energy", energy) end self.FrameDrain=true end