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

local Settings = script.Parent.ACS_Modulo:WaitForChild("Config")

local ACS_Storage = workspace:WaitForChild("ACS_WorkSpace")

local Modulos = Engine:WaitForChild("Modulos")

local Hitmarker = require(Modulos:WaitForChild("Hitmarker"))
local Ragdoll = require(Modulos: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

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


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.Hit:FireAllClients(nil,Position,HitPart,Normal,Material,nil)
	
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)*FallOfDamage
	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 (BulletPenetration) < Helmetfactor.Value  then
					damage = Traveleddamage * ((BulletPenetration)/Helmetfactor.Value)
					HelmetDamage = (Traveleddamage * ((100 - BulletPenetration)/Helmetfactor.Value))
				
					if HelmetDamage <= 0 then
					HelmetDamage = 0.5
					end
					
				elseif Helmet.Value > 0 and (BulletPenetration) >= Helmetfactor.Value then
					damage = Traveleddamage
					HelmetDamage = (Traveleddamage * ((100 - BulletPenetration)/Helmetfactor.Value))
					
					if HelmetDamage <= 0 then
					HelmetDamage = 1
					end				

				elseif Helmet.Value <= 0 then
					damage = Traveleddamage
	
				end
			else
				if Vest.Value > 0 and (BulletPenetration) < Vestfactor.Value  then
					damage = Traveleddamage * ((BulletPenetration)/Vestfactor.Value)
					VestDamage = (Traveleddamage * ((100 - BulletPenetration)/Vestfactor.Value))
				
					if VestDamage <= 0 then
					VestDamage = 0.5
					end
					
				elseif Vest.Value > 0 and (BulletPenetration) >= Vestfactor.Value then
					damage = Traveleddamage
					VestDamage = (Traveleddamage * ((100 - 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()
		wait(3) -- How long the Enemy reloads
		ammo= Settings.Ammo.Value
		if w then
			w=.14
		end
		r=false
	elseif boo then
		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
