--shield local SHIELD_DRAIN=2 -- Amount to drain every "zap" AddCSLuaFile("cl_init.lua") AddCSLuaFile("shared.lua") include("shared.lua") function ENT:KeyValue( key, value ) if ( key == "size" ) then self.Radius=tonumber(value) end end function ENT:Initialize() self.Effect=0 self.Entity:SetMoveType( MOVETYPE_NONE ) self.Entity:SetSolid( SOLID_NONE ) self.Entity:DrawShadow( false ) self.Entity:PhysicsInitSphere(self.Radius) local phys = self.Entity:GetPhysicsObject() if (phys:IsValid()) then phys:EnableCollisions( false ) end self.Entity:SetTrigger( true ) self.Entity:SetNotSolid( true ) self.Entity:SetCollisionBounds( Vector( -self.Radius, -self.Radius, -self.Radius), Vector( self.Radius, self.Radius, self.Radius ) ) local found=ents.FindInSphere(self.Entity:GetPos(),self.Radius) self.NoCollide={} for _,ent in pairs(found) do self.NoCollide[ent]=true end end function ENT:StartTouch(entity) end function ENT:Think() local parent=self.Entity:GetParent() if parent:GetNetworkedInt("energy",1)>0 then self.Entity:SetTrigger(true) else self.Entity:SetTrigger(false) end self:NextThink(CurTime()) end function ENT:Touch( entity ) if entity==GetWorldEntity() then return end if entity:GetClass()=="prop_vehicle_jeep" then return end if(entity.Touch) then entity:Touch(self.Entity) end local pushed=0 local parent=self.Entity:GetParent() if parent:GetNetworkedInt("energy")>0 then if self.NoCollide[entity] then return end if entity:GetClass()=="rpg_missile" then entity:SetLocalVelocity((entity:GetPos()-self.Entity:GetPos()):Normalize()*1000) entity:SetHealth(0) local bullet = { Num = 1, Src = entity:GetPos(), Dir = Vector(0,0,0), Spread = Vector(0,0,0), Tracer = 0, Force = 1, Damage = 100 } self.Entity:FireBullets(bullet) pushed=1 end local physobj=entity:GetPhysicsObject() local normal = (entity:GetPos()-self.Entity:GetPos()):Normalize(); if physobj:IsValid() and entity:GetClass()~="player" and physobj:GetVelocity():Length()>3 then if entity:IsPlayerHolding() then entity:SetPos(self.Entity:GetPos()+(entity:GetPos()-self.Entity:GetPos()):Normalize()*self.Radius) return false end physobj:ApplyForceOffset(normal*physobj:GetMass()*physobj:GetVelocity():Length(),entity:GetPos()*normal); pushed=1 else if entity:GetCollisionGroup()==COLLISION_GROUP_PROJECTILE or entity:GetVelocity( )~=Vector(0,0,0) and entity:GetClass()~="rpg_missile" then entity:SetOwner(self.Entity) entity:SetLocalVelocity((entity:GetPos()-self.Entity:GetPos()):Normalize()*100) if entity:GetClass()=="crossbow_bolt" then entity:SetLocalVelocity((entity:GetPos()-self.Entity:GetPos()):Normalize()*1000) end pushed=1 end end if pushed==1 then if not entity.LastShieldZap then entity.LastShieldZap=CurTime() end if entity.LastShieldZapSHIELD_DRAIN then parent:SetNetworkedInt("energy",math.Clamp(parent:GetNetworkedInt("energy")-SHIELD_DRAIN,-10,100)) else parent:SetNetworkedInt("energy",math.Clamp(parent:GetNetworkedInt("energy")-10,-10,100)) end parent.FrameDrain=false end end end end