local N=game.Debris local k=game.ReplicatedStorage:WaitForChild("\065\067\083\095\069\110\103\105\110\101")local z=k:WaitForChild("\069\118\101\110\116\115")local L=require(k.GameRules:WaitForChild("\067\111\110\102\105\103"))local l=script.Parent.ACS_Modulo:WaitForChild("\067\111\110\102\105\103")local K=script.Parent:FindFirstChildOfClass("\084\111\111\108")local w=require(K:WaitForChild("\065\067\083\095\083\101\116\116\105\110\103\115"))local s=workspace:WaitForChild("\065\067\083\095\087\111\114\107\083\112\097\099\101")local M=k:WaitForChild("\077\111\100\117\108\101\115")local O=require(M:WaitForChild("\072\105\116\109\097\114\107\101\114"))local j=require(M:WaitForChild("\082\097\103\100\111\108\108"))local X=s:FindFirstChild("\083\101\114\118\101\114")local b=s:FindFirstChild("\067\108\105\101\110\116")local Z={X,b;s}local I=false task.wait(3)script.Parent.ForceField:Destroy()script.Parent.Humanoid.Died:connect(function()j(script.Parent)if script.Parent:FindFirstChild("\071\117\110")~=nil then script.Parent.Gun.CanCollide=true end I=true N:AddItem(script.Parent,game.Players.RespawnTime)end)local i=false local H=nil function onTouched(N)if N.Parent==nil then return end local k=N.Parent:findFirstChild("\072\117\109\097\110\111\105\100")if k==nil then H=N end end function waitForChild(N,k)local z=N:findFirstChild(k)if z then return z end while true do z=N.ChildAdded:wait()if z.Name==k then return z end end end local V=script.Parent local q=waitForChild(V,"\072\117\109\097\110\111\105\100")local c=waitForChild(V,"\084\111\114\115\111")local x=waitForChild(V,"\076\101\102\116 \076\101\103")local f=waitForChild(V,"\082\105\103\104\116 \076\101\103")x.Touched:connect(onTouched)f.Touched:connect(onTouched)function getHumanoid(N)for N,k in pairs(N:GetChildren())do if k:IsA("\072\117\109\097\110\111\105\100")then return k end end end local g=script.Parent local p=getHumanoid(g)local U=g.Torso local B=g:FindFirstChild("\072\101\097\100")local m=game:GetService("\080\097\116\104\102\105\110\100\105\110\103\083\101\114\118\105\099\101")local T=game:GetService("\080\108\097\121\101\114\115")local G=Spread/100 local A=0 local D=0 task.wait(.1)local d=l.Ammo.Value local u=.14 local t=1/(w.ShootRate/60)local S=false local J=script.Parent local P=J:WaitForChild("\071\114\105\112")function Hitmaker(N,k,L,l)z.HitEffect:FireAllClients(nil,k,N,L,l,w)end function CheckForHumanoid(N)local k=false local z=nil if N then if N.Parent:FindFirstChild("\072\117\109\097\110\111\105\100")or N.Parent.Parent:FindFirstChild("\072\117\109\097\110\111\105\100")then k=true if N.Parent:FindFirstChild("\072\117\109\097\110\111\105\100")then z=N.Parent.Humanoid elseif N.Parent.Parent:FindFirstChild("\072\117\109\097\110\111\105\100")then z=N.Parent.Parent.Humanoid end else k=false end end return k,z end function CalcularDano(N,k,z,L)local l=0 local K=0 local s=0 local M=N-(math.ceil(k)/40)*w.DamageFallOf if z.Parent:FindFirstChild("\083\097\117\100\101")~=nil then local N=z.Parent.Saude.Protecao.VestVida local k=z.Parent.Saude.Protecao.VestProtect local O=z.Parent.Saude.Protecao.HelmetVida local j=z.Parent.Saude.Protecao.HelmetProtect if L=="\072\101\097\100"then if O.Value>0 and w.BulletPenetration<j.Value then l=M*(w.BulletPenetration/j.Value)s=M*((100-w.BulletPenetration)/j.Value)if s<=0 then s=.5 end elseif O.Value>0 and w.BulletPenetration>=j.Value then l=M s=M*((100-w.BulletPenetration)/j.Value)if s<=0 then s=1 end elseif O.Value<=0 then l=M end else if N.Value>0 and w.BulletPenetration<k.Value then l=M*(w.BulletPenetration/k.Value)K=M*((100-w.BulletPenetration)/k.Value)if K<=0 then K=.5 end elseif N.Value>0 and w.BulletPenetration>=k.Value then l=M K=M*((100-w.BulletPenetration)/k.Value)if K<=0 then K=1 end elseif N.Value<=0 then l=M end end else l=M end if l<=0 then l=1 end return l,K,s end function Damage(N,k,z,L)if N.Parent:FindFirstChild("\083\097\117\100\101")~=nil then local k=N.Parent.Saude.Protecao.VestVida local l=N.Parent.Saude.Protecao.HelmetVida k.Value=k.Value-z l.Value=l.Value-L end N:TakeDamage(k)end local function r(N)if N and d~=l.Ammo.Value or d==0 then S=true if u then u=.03 end P.Reload:Play()task.wait(3)d=l.Ammo.Value if u then u=.14 end S=false elseif N then task.wait(.1)end end local function o()if not I then local N,k=l.ShotDistance.Value,nil for z,L in ipairs(game.Players:GetPlayers())do if L.Character and(L.Character:FindFirstChild("\072\117\109\097\110\111\105\100")and L:DistanceFromCharacter(P.Position)<N)then N,k=L:DistanceFromCharacter(P.Position),L end end if k then return k.Character:GetModelCFrame(),N,(CFrame.new(k.Character.Humanoid.WalkToPoint)).lookVector else return nil end end end

local Debris = game.Debris

local Engine = game.ReplicatedStorage:WaitForChild("ACS_Engine")
local Evt = Engine:WaitForChild("Events")
local ServerConfig = require(Engine.GameRules:WaitForChild("Config"))

local Settings = script.Parent.ACS_Modulo:WaitForChild("Config")
local Weapon = script.Parent:FindFirstChildOfClass("Tool")
local WeaponData = require(Weapon:WaitForChild("ACS_Settings"))

local ACS_Storage = workspace:WaitForChild("ACS_WorkSpace")

local Modules = Engine:WaitForChild("Modules")

local Hitmarker = require(Modules:WaitForChild("Hitmarker"))
local Ragdoll = require(Modules:WaitForChild("Ragdoll"))

local Ignore_Model = ACS_Storage:FindFirstChild("Server")

local BulletModel = ACS_Storage:FindFirstChild("Client")

local Ray_Ignore = {Ignore_Model, BulletModel, ACS_Storage}

local Dead = false
task.wait(3)
script.Parent.ForceField:Destroy()

script.Parent.Humanoid.Died:connect(function()
	Ragdoll(script.Parent)
	if script.Parent:FindFirstChild("Gun") ~= nil then
		script.Parent.Gun.CanCollide = true
	end
	Dead = true
	Debris:AddItem(script.Parent,game.Players.RespawnTime)
end)

local CanSee = false
local CurrentPart = nil

function onTouched(hit)
	if hit.Parent == nil then
		return
	end

	local humanoid = hit.Parent:findFirstChild("Humanoid")

	if humanoid == nil then
		CurrentPart = hit
	end
end

function waitForChild(parent, childName)
	local child = parent:findFirstChild(childName)

	if child then
		return child
	end

	while true do
		--print(childName)
		child = parent.ChildAdded:wait()

		if child.Name==childName then
			return child
		end
	end
end

local Figure = script.Parent
local Humanoid = waitForChild(Figure, "Humanoid")
local Torso = waitForChild(Figure, "Torso")
local Left = waitForChild(Figure, "Left Leg")
local Right = waitForChild(Figure, "Right Leg")

Left.Touched:connect(onTouched)
Right.Touched:connect(onTouched)

function getHumanoid(model)
	for _, v in pairs(model:GetChildren())do
		if v:IsA'Humanoid' then
			return v
		end
	end
end


local zombie = script.Parent
local human = getHumanoid(zombie)
local hroot = zombie.Torso
local head = zombie:FindFirstChild'Head'

local pfs = game:GetService("PathfindingService")
local players = game:GetService('Players')

local RecoilSpread = Spread/100
local perception = 0
local Memory = 0


task.wait(.1)

local ammo=Settings.Ammo.Value -- How much ammo the Enemy has
local w=.14
local RPM = 1/(WeaponData.ShootRate/60)
local r=false
local t=script.Parent


local h=t:WaitForChild'Grip'

function Hitmaker(HitPart, Position, Normal, Material)

	Evt.HitEffect:FireAllClients(nil, Position, HitPart, Normal, Material, WeaponData)

end


function CheckForHumanoid(L_225_arg1)
	local L_226_ = false
	local L_227_ = nil
	if L_225_arg1 then
		if (L_225_arg1.Parent:FindFirstChild("Humanoid") or L_225_arg1.Parent.Parent:FindFirstChild("Humanoid")) then
			L_226_ = true
			if L_225_arg1.Parent:FindFirstChild('Humanoid') then
				L_227_ = L_225_arg1.Parent.Humanoid
			elseif L_225_arg1.Parent.Parent:FindFirstChild('Humanoid') then
				L_227_ = L_225_arg1.Parent.Parent.Humanoid
			end
		else
			L_226_ = false
		end	
	end
	return L_226_, L_227_
end

function CalcularDano(DanoBase,Dist,Vitima,Type)

	local damage = 0
	local VestDamage = 0
	local HelmetDamage = 0
	local Traveleddamage = DanoBase-(math.ceil(Dist)/40)*WeaponData.DamageFallOf
	if Vitima.Parent:FindFirstChild("Saude") ~= nil then

		local Vest =  Vitima.Parent.Saude.Protecao.VestVida
		local Vestfactor = Vitima.Parent.Saude.Protecao.VestProtect
		local Helmet = Vitima.Parent.Saude.Protecao.HelmetVida
		local Helmetfactor = Vitima.Parent.Saude.Protecao.HelmetProtect

		if Type == "Head" then
			if Helmet.Value > 0 and (WeaponData.BulletPenetration) < Helmetfactor.Value  then
				damage = Traveleddamage * ((WeaponData.BulletPenetration)/Helmetfactor.Value)
				HelmetDamage = (Traveleddamage * ((100 - WeaponData.BulletPenetration)/Helmetfactor.Value))

				if HelmetDamage <= 0 then
					HelmetDamage = 0.5
				end

			elseif Helmet.Value > 0 and (WeaponData.BulletPenetration) >= Helmetfactor.Value then
				damage = Traveleddamage
				HelmetDamage = (Traveleddamage * ((100 - WeaponData.BulletPenetration)/Helmetfactor.Value))

				if HelmetDamage <= 0 then
					HelmetDamage = 1
				end				

			elseif Helmet.Value <= 0 then
				damage = Traveleddamage

			end
		else
			if Vest.Value > 0 and (WeaponData.BulletPenetration) < Vestfactor.Value  then
				damage = Traveleddamage * ((WeaponData.BulletPenetration)/Vestfactor.Value)
				VestDamage = (Traveleddamage * ((100 - WeaponData.BulletPenetration)/Vestfactor.Value))

				if VestDamage <= 0 then
					VestDamage = 0.5
				end

			elseif Vest.Value > 0 and (WeaponData.BulletPenetration) >= Vestfactor.Value then
				damage = Traveleddamage
				VestDamage = (Traveleddamage * ((100 - WeaponData.BulletPenetration)/Vestfactor.Value))

				if VestDamage <= 0 then
					VestDamage =  1
				end				

			elseif Vest.Value <= 0 then
				damage = Traveleddamage

			end
		end
	else
		damage = Traveleddamage
	end			
	if damage <= 0 then
		damage = 1
	end

	return damage,VestDamage,HelmetDamage
end

function Damage(VitimaHuman,Dano,DanoColete,DanoCapacete)
	if VitimaHuman.Parent:FindFirstChild("Saude") ~= nil then
		local Colete = VitimaHuman.Parent.Saude.Protecao.VestVida
		local Capacete = VitimaHuman.Parent.Saude.Protecao.HelmetVida
		Colete.Value = Colete.Value - DanoColete
		Capacete.Value = Capacete.Value - DanoCapacete
	end
	VitimaHuman:TakeDamage(Dano)
end

local function reload(boo)
	if(boo and ammo ~= Settings.Ammo.Value)or ammo==0 then
		r=true
		if w then
			w=.03
		end
		h.Reload:Play()
		task.wait(3) -- How long the Enemy reloads
		ammo= Settings.Ammo.Value
		if w then
			w=.14
		end
		r=false
	elseif boo then
		task.wait(.1)
	end
end
local function near()
	if not Dead then
		local dis,pl= Settings.ShotDistance.Value ,nil -- Range of the Enemy
		for _,v in ipairs(game.Players:GetPlayers())do
			if v.Character and v.Character:FindFirstChild'Humanoid'and v:DistanceFromCharacter(h.Position)<dis then
				dis,pl=v:DistanceFromCharacter(h.Position),v
			end
		end
		if pl then
			return pl.Character:GetModelCFrame(),dis,CFrame.new(pl.Character.Humanoid.WalkToPoint).lookVector
		else
			return nil
		end
	end
end
