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