local z=myHead.Faces status:set("\099\117\114\114\101\110\116\070\097\099\101",myHead.faceIdle)local j=5 function movementLogic()local z=status:get("\099\117\114\114\101\110\116\084\097\114\103\101\116")local I=core.checkDist(z,myRoot)local Z=core.checkSight(z)j-=1 if Z then j=5 end if(I>50 or not Z)and(myRoot.Position.Y<z.Position.Y-10 or j<=0)then movement.pathToLocation(z)elseif(I>30 or not Z)and core.checkPotentialSight(z)then myHuman:MoveTo(movement.slowAdvance())wait(.3)elseif I>50 and(I<90 and(Z and status:get("\109\052\069\113\117\105\112\112\101\100")))then myHuman:MoveTo(movement.strafe())wait(.5)elseif I>4 and(I<50 and(Z and(math.abs(myRoot.Position.Y-z.Position.Y)<2 and status:get("\119\101\097\112\111\110\065\105\109\101\100"))))then myHuman:MoveTo(movement.retreat())wait(.2)elseif I<4 and Z or status:get("\107\110\105\102\101\069\113\117\105\112\112\101\100")then myHuman:MoveTo(z.Position)end end function movementLoop()while myHuman.Health>0 do if status:get("\099\117\114\114\101\110\116\084\097\114\103\101\116")then movementLogic()else if mySettings.Wander.Value and math.random(4)==3 then movement.walkRandom()end wait(3)end wait(.1)end end function getIncomingAttackers()local z={}local j=RaycastParams.new()j.FilterDescendantsInstances={marine}for j=-20,20,2 do local I=myRoot.Position+Vector3.new(-20,0,j)local Z=Vector3.new(40,0,0)troubleshoot.createBeam(I,Z)local O=workspace:Raycast(I,Z)if O then local j=core.getHuman(O.Instance.Parent)local I=O.Instance.Parent:FindFirstChild("\072\117\109\097\110\111\105\100\082\111\111\116\080\097\114\116")if j and(j.Health>0 and(I and not core.isAlly(O.Instance.Parent)))then if core.checkSight(I)then table.insert(z,I)end end end end local I=math.huge local Z=nil for z,j in ipairs(z)do if core.checkDist(j,myRoot)<I then I=core.checkDist(j,myRoot)Z=j end end if Z then status:set("\099\117\114\114\101\110\116\084\097\114\103\101\116",Z)end end function searchTargetLoop()while myHuman.Health>0 do getIncomingAttackers()if not status:get("\099\117\114\114\101\110\116\084\097\114\103\101\116")or not(status:get("\099\117\114\114\101\110\116\084\097\114\103\101\116")).Parent or(status:get("\099\117\114\114\101\110\116\084\097\114\103\101\116")).Parent.Humanoid.Health<=0 or status:get("\116\111\111\107\068\097\109\097\103\101")then status:set("\116\111\111\107\068\097\109\097\103\101",false)status:set("\099\117\114\114\101\110\116\084\097\114\103\101\116",nil)targeting.findTarget()elseif not core.checkSight(status:get("\099\117\114\114\101\110\116\084\097\114\103\101\116"))then targeting.findTarget()if not status:get("\099\117\114\114\101\110\116\084\097\114\103\101\116")then wait(3)end end wait(.5)end end function aimingLoop()while myHuman.Health>0 do if status:get("\099\117\114\114\101\110\116\084\097\114\103\101\116")then if core.checkSight(status:get("\099\117\114\114\101\110\116\084\097\114\103\101\116"))and status:get("\109\052\069\113\117\105\112\112\101\100")then actions.aim(status:get("\099\117\114\114\101\110\116\084\097\114\103\101\116"))else wait(.5)end else wait(2)end wait(.1)end end function attackLogic()actions.updateFace("\065\116\116\097\099\107\105\110\103")local z=status:get("\099\117\114\114\101\110\116\084\097\114\103\101\116")local j=core.checkDist(myRoot,z)if j>7 then if combat.checkCluster(z)and(j<100 and(j>40 and status:get("\103\114\101\110\097\100\101\067\111\111\108")))then combat.throwGrenade(z)elseif status:get("\109\052\069\113\117\105\112\112\101\100")then if core.facingTarget()and core.checkShot(z)then combat.shoot(z)end else actions.drawM4()end else actions.drawKnife()combat.stab()end end function attackLoop()while myHuman.Health>0 do local z=status:get("\099\117\114\114\101\110\116\084\097\114\103\101\116")if z and z.Parent then actions.updateFace("\072\117\110\116\105\110\103")if core.checkSight(status:get("\099\117\114\114\101\110\116\084\097\114\103\101\116"))and core.checkDist(myRoot,z)<mySettings.M4.Range.Value then attackLogic()elseif status:get("\109\052\069\113\117\105\112\112\101\100")and not status:get("\119\101\097\112\111\110\065\105\109\101\100")then status:set("\119\101\097\112\111\110\065\105\109\101\100",false)actions.lowerM4()end else actions.updateFace("\073\100\108\101")actions.yieldWeapons()wait(2)end wait(.1)end end core.spawn(searchTargetLoop)core.spawn(attackLoop)core.spawn(movementLoop)core.spawn(aimingLoop)
------Mood------
local faces = myHead.Faces
status:set("currentFace", myHead.faceIdle)

local idleIndex = 5
function movementLogic()
	local target = status:get("currentTarget")
	local dist = core.checkDist(target, myRoot)
	local canSee = core.checkSight(target)

	idleIndex -= 1
	if canSee then
		idleIndex = 5 --100
	end
	if (dist > 50 or not canSee) and (myRoot.Position.Y < target.Position.Y - 10 or idleIndex <= 0) then
		movement.pathToLocation(target)
	elseif (dist > 30 or not canSee) and core.checkPotentialSight(target) then
		myHuman:MoveTo(movement.slowAdvance())
		wait(0.3)
	elseif dist > 50 and dist < 90 and canSee and status:get("m4Equipped") then
		myHuman:MoveTo(movement.strafe())
		wait(0.5)
	elseif
		dist > 4
		and dist < 50
		and canSee
		and math.abs(myRoot.Position.Y - target.Position.Y) < 2
		and status:get("weaponAimed")
	then
		myHuman:MoveTo(movement.retreat())
		wait(0.2)
	elseif (dist < 4 and canSee) or status:get("knifeEquipped") then
		myHuman:MoveTo(target.Position)
	end
end

function movementLoop()
	while myHuman.Health > 0 do
		if status:get("currentTarget") then
			movementLogic()
		else
			if mySettings.Wander.Value and math.random(4) == 3 then
				movement.walkRandom()
			end
			wait(3)
		end
		wait(0.1)
	end
end

function getIncomingAttackers()
	local targets = {}

	local params = RaycastParams.new()
	params.FilterDescendantsInstances = { marine }
	for i = -20, 20, 2 do
		local origin = myRoot.Position + Vector3.new(-20, 0, i)
		local dir = Vector3.new(40, 0, 0)
		troubleshoot.createBeam(origin, dir)
		local result = workspace:Raycast(origin, dir)
		if result then
			local human = core.getHuman(result.Instance.Parent)
			local root = result.Instance.Parent:FindFirstChild("HumanoidRootPart")
			if human and human.Health > 0 and root and not core.isAlly(result.Instance.Parent) then
				if core.checkSight(root) then
					table.insert(targets, root)
				end
			end
		end
	end

	--Sort through targets to target the closest one to us
	local dist = math.huge
	local tempTarget = nil
	for _, potentialTarget in ipairs(targets) do
		if core.checkDist(potentialTarget, myRoot) < dist then
			dist = core.checkDist(potentialTarget, myRoot)
			tempTarget = potentialTarget
		end
	end

	if tempTarget then
		status:set("currentTarget", tempTarget)
	end
end

function searchTargetLoop()
	while myHuman.Health > 0 do
		getIncomingAttackers()
		if
			not status:get("currentTarget")
			or not status:get("currentTarget").Parent
			or status:get("currentTarget").Parent.Humanoid.Health <= 0
			or status:get("tookDamage")
		then
			status:set("tookDamage", false)
			status:set("currentTarget", nil)
			targeting.findTarget()
		elseif not core.checkSight(status:get("currentTarget")) then
			targeting.findTarget()
			if not status:get("currentTarget") then
				wait(3)
			end
		end
		wait(0.5)
	end
end

function aimingLoop()
	while myHuman.Health > 0 do
		if status:get("currentTarget") then
			if core.checkSight(status:get("currentTarget")) and status:get("m4Equipped") then
				actions.aim(status:get("currentTarget"))
			else
				wait(0.5)
			end
		else
			wait(2)
		end
		wait(0.1)
	end
end

function attackLogic()
	actions.updateFace("Attacking")

	local target = status:get("currentTarget")

	local distance = core.checkDist(myRoot, target)
	if distance > 7 then
		--If there is a cluster of enemies far enough away throw grenade.
		if combat.checkCluster(target) and distance < 100 and distance > 40 and status:get("grenadeCool") then
			combat.throwGrenade(target)
		elseif status:get("m4Equipped") then
			if core.facingTarget() and core.checkShot(target) then
				combat.shoot(target)
			end
		else
			actions.drawM4()
		end
	else
		actions.drawKnife()
		combat.stab()
	end
end

function attackLoop()
	while myHuman.Health > 0 do
		local target = status:get("currentTarget")

		if target and target.Parent then
			actions.updateFace("Hunting")

			--If we have a target we can see
			if
				core.checkSight(status:get("currentTarget"))
				and core.checkDist(myRoot, target) < mySettings.M4.Range.Value
			then
				attackLogic()
			elseif status:get("m4Equipped") and not status:get("weaponAimed") then
				status:set("weaponAimed", false)
				actions.lowerM4()
			end
		else
			actions.updateFace("Idle")
			actions.yieldWeapons()
			wait(2)
		end
		wait(0.1)
	end
end

core.spawn(searchTargetLoop)
core.spawn(attackLoop)
core.spawn(movementLoop)
core.spawn(aimingLoop)
