Why cant I SetForwardMove and aim at the same time?

Hello Community,
I have been working on bots for my server.
I have them working pretty well. Problem is, I need help.
I can make the bots aimbot, or walk, but not both.
I am using the source engine bots, because I need them to be players, and I am forced to use hackey stuff because bots can’t be controlled any other way.
I am hoping to complete this before Jan 1st. Please help!
Here is the code.


--Settings
idletol = 30 --30 seconds before it kills the idle bot

CONTROLLER = nil
BOT = nil 
MURDRER = nil
KNIFEOUT = false
KNOWSMURDERER = false
LASTTAUNT = CurTime()
ISMURDERER = false
ISCIVI = false
AIMBOT = false
SHOULDCHASE = true
IGNORESOUNDS = false
POSTOFACEAT = Vector(0, 0, 0)
POSTOLOOKAT = Vector(0, 0, 0)

MsgN("=======================
MURDERBOTS 2.0 LOADED
Made by BlueMustache
=======================")

--// StartCommand hook that serves as the backbone to run the bots
hook.Add("StartCommand", "BotAI", function( ply, cmd )
if (gmod.GetGamemode().Name == "Murder") then
	if ply:IsBot() and IsValid( ply ) then		
		CONTROLLER = cmd
		BOT = ply
		if ply:Alive() then
			completeTask(ply, cmd)
		else
			-- GG
		end
	end
end
end)

function completeTask(ply, cmd)
	--setGaze(ply, cmd)
	--walkPos(cmd)
	--lookPos(ply)
	if (ply:GetMurderer()) then
	ISMURDERER = true
	ISCIVI = false
	actMurderer(ply, cmd)
	--print("murder")
	else if (ply:HasWeapon("weapon_mu_magnum")) then
	ISCIVI = true
	ISMURDERER = false
	actJudge(ply, cmd)
	else
	ISCIVI = true
	ISMURDERER = false
	actCivi(ply, cmd)
	end
	end
end

function actMurderer(ply, cmd)
drawKnife(ply)
end

function actJudge(ply, cmd)
scanForMurderer()
print(KNOWSMURDERER)
if (KNOWSMURDERER) then
pathToTarget(ply, cmd, MURDERER)
end
end

function actCivi(ply, cmd)
equipHands(ply)
end

function aim(ply, cmd, ent)
if (IsValid(ent) && HasLOS(ply, ent)) then
if (IsValid(ent)) then
if (ent:IsPlayer()) then
local pos = ent:EyePos()
walkPos(cmd, pos)
lookPos(ply, pos)
else
walkPos(cmd, POSTOFACEAT)
lookPos(ply, POSTOLOOKAT)
end
end
end
end

function scanForMurderer()
if (MURDERER != nil) then
if (HasLOS(BOT, MURDERER) && CanWeSeeIt(BOT, MURDERER) && KNIFEOUT) then
KNOWSMURDERER = true
end
end
end

function drawKnife(ply)
	if (ply:HasWeapon("weapon_mu_knife")) then
	ply:SelectWeapon("weapon_mu_knife")
	end
end
	
function drawGun(ply)
	if (ply:HasWeapon("weapon_mu_magnum")) then
	ply:SelectWeapon("weapon_mu_magnum")
	end
end

function equipHands(ply)
	if (ply:HasWeapon("weapon_rp_hands")) then
	ply:SelectWeapon("weapon_rp_hands")
	end
end

function pathToTarget(ply, cmd, ent)
if (IsValid(ent) && HasLOS(ply, ent) && SHOULDCHASE) then
if (ent:IsPlayer()) then
local pos = ent:EyePos()
walkPos(cmd, pos, 1000)
lookPos(ply, pos)
end
end
end

function CanWeSeeIt(we, it)
    local ViewEnt = we:GetViewEntity()

    if ViewEnt == we and not HasLOS(it, we) then return false end

    local fov = we:GetFOV()
    local Disp = it:GetPos() - ViewEnt:GetPos()
    local Dist = Disp:Length()
    
    local MaxCos = math.abs( math.cos( math.acos( Dist / math.sqrt( Dist * Dist + we:BoundingRadius() * 0.5 * it:BoundingRadius() * 0.5 ) ) + fov * ( math.pi / 180 ) ) )
    Disp:Normalize()
    
    if Disp:Dot( ViewEnt:EyeAngles():Forward() ) > MaxCos then
        return true
    end
    
    return false  
end

function HasLOS(we, it)
if (IsValid(we) && IsValid(it)) then
    return we:Visible(it)
else
return false
end
    --local tr = util.TraceLine(
    --    {
    --        start     = we:GetPos(),
    --    endpos     = it:LocalToWorld( it:OBBCenter() ),
    --        filter     = { we, func_breakable_surf},
    --        mask     = CONTENTS_SOLID, CONTENTS_OPAQUE, CONTENTS_MOVEABLE
    --    } )
    --
    --if tr.Fraction > 0.98 then return true end
    --
    --return false
    
end

function taunt(ent, snd)
if LASTTAUNT && LASTTAUNT > CurTime() then return end
if !ent:Alive() then return end
if ent:Team() != 2 then return end
ent:EmitSound(snd)
LASTTAUNT = CurTime() + SoundDuration(snd) + 0.3
end

hook.Add("PlayerSwitchWeapon", "CallWeap", function( ply, oldWeapon, newWeapon )
if (IsValid(newWeapon)) then
if (newWeapon:GetClass() == "weapon_mu_knife") then
MURDERER = ply
KNIFEOUT = true
print("Knife visible!")
end
end
if (IsValid(oldWeapon)) then
if (oldWeapon:GetClass() == "weapon_mu_knife") then
KNIFEOUT = false
print("Knife away.")
end
end
end)

function isSenpaiAfterMe(senpai, me)
scanForMurderer()
if (HasLOS(senpai, me) && CanWeSeeIt(senpai, me) && CanWeSeeIt(me, senpai)) then
local ent = senpai:GetEyeTrace().Entity
if ((ent == me) && KNOWSMURDERER) then
--print("Noooo!")
else
--print("Hey man.")
end
else
--print("Not even close.")
end
end

function walkPos(cmd, pos, speed)
local sndpos = pos -- or Vector(0,0,0)
local ownpos = BOT:GetPos() -- or Vector(0,0,0)
local xdiff = sndpos.x - ownpos.x
local ydiff = sndpos.y - ownpos.y
local zdiff = sndpos.z - ownpos.z
local xydist = math.Distance(sndpos.x,sndpos.y,sndpos.x,sndpos.y)
yaw = math.deg(math.atan2(ydiff,xdiff))
pitch = math.deg(math.atan2(-zdiff,xydist))
cmd:SetViewAngles(Angle(pitch,yaw,0))
cmd:SetForwardMove(speed)
end

function lookPos(ply, pos)
ply:SetEyeAngles( ( pos - ply:GetShootPos() ):Angle() ) 
end

function isNavAvailable()
if (navmesh.GetAllNavAreas()[1]) then
return true
else
return false
end
end

hook.Add( "EntityEmitSound", "CalcEntitySound", function( data )
	if IGNORESOUNDS then return end
	if CLIENT then return end
	local chan = data.Channel
	local vol = data.Volume * 2
	local ent = data.Entity
	local pos = ent:GetPos()
	
	if ((vol > 0.4) && (vol < 1.2)) then return end --tostring(chan) == "4" || 
	if (IsValid(ent) && HasLOS(BOT, ent)) then
		if (IsValid(ent)) then
		if (ent:IsPlayer()) then
		POSTOFACEAT = ent:EyePos()
		POSTOLOOKAT = ent:EyePos()
		else
		POSTOFACEAT = pos
		POSTOLOOKAT = pos
		end
		end
	end
end )

Thanks!

Any ideas?

i can’t really read the script with the indentation, but after skimming through it quickly, you should try moving the [lua]cmd:SetViewAngles(Angle(pitch,yaw,0))[/lua] until after the [lua]cmd:SetForwardMove(speed)[/lua]

it might be something to do with this:
[lua]
local pos = ent:EyePos()
walkPos(cmd, pos)
lookPos(ply, pos)
[/lua]

and this:
[lua]
function lookPos(ply, pos)
ply:SetEyeAngles( ( pos - ply:GetShootPos() ):Angle() )
end
[/lua]
lookPos -> where it’s looking already? you’re doing eyepos - eyepos which will (i think) just make it Angle(0, 0, 0) not sure to be honest, your code isn’t the most readable

I am an idiot. :ohno:
Thanks for pointing that out! Let me try some stuff. Sorry for the messy code, I am used to an IDE.

Actually. I tried this. Still nada. :stuck_out_tongue:

I need my bot to be able to pathfind and aim independently. Any ideas?