AddCSLuaFile('shared.lua')
AddCSLuaFile('cl_init.lua')
include("shared.lua")

function ENT:Think()
	if self.enable_ent and (!IsValid(self.ent) or self.ent:Health() <= 0) then
		self:Remove()
		return
	end

	if self:GetCycle() >= 1 then
		self:SetCycle(0)
	end

	local ent = self.ent
	if IsValid(ent) then
		local bone = self:LookupBone("root") or self:LookupBone("ValveBiped.Bip01_Pelvis")
		local att = self:GetBonePosition(bone)
		local tr = util.TraceLine({
			start = att,
			endpos = att - Vector(0,0,100),
			filter = ent,
		})
		ent:SetPos(tr.HitPos)
	end

	if self.push or IsValid(ent) then
		local bone = self:LookupBone("root") or self:LookupBone("ValveBiped.Bip01_Pelvis")
		local att = self:GetBonePosition(bone)
		for k, v in pairs(ents.FindInSphere(att, 100)) do
			if v:IsNPC() and v != ent then
				local pos1 = att
				local pos2 = v:GetPos()
				local dir = (pos1 - pos2):GetNormalized()
				v:SetVelocity(-dir * 100)
			end
		end
	end

	self:NextThink(CurTime())
	return true 
end