Making a NextBot randomly break off from a path and walk somewhere else, then making them go back to the path

Hi. I’m making a Nextbot that uses weapons, and so far it’s going well. However, I feel as if the ChaseEnemy function from the example NextBot on the Gmod Wiki is kinda boring for this concept in it’s current state:

function ENT:ChaseEnemy( options )

	local options = options or {}

	local path = Path( "Follow" )
	path:SetMinLookAheadDistance( options.lookahead or 300 )
	path:SetGoalTolerance( options.tolerance or 20 )
	path:Compute( self, self:GetEnemy():GetPos() )		-- Compute the path towards the enemies position

	if ( !path:IsValid() ) then return "failed" end

	while ( path:IsValid() and self:HaveEnemy() ) do

		if ( path:GetAge() > 0.1 ) then					-- Since we are following the player we have to constantly remake the path
			path:Compute( self, self:GetEnemy():GetPos() )-- Compute the path towards the enemy's position again
		path:Update( self )								-- This function moves the bot along the path

		if ( options.draw ) then path:Draw() end
		-- If we're stuck, then call the HandleStuck function and abandon
		if ( self.loco:IsStuck() ) then
			return "stuck"



	return "ok"


You see, what I want to do is make the nextbot randomly break off from the path they’re following, and move somewhere within 400 units, then get back to the path. This would kinda simulate how not all players(this is meant to be a bot for TDM-type stuff) just run up and shoot, and often seek cover at places or move somewhere else before following their target. Not a big deal if no one can help, but I feel as if this will be useful if I can find a way to add this in.

Seems like you need something else besides ChaseEnemy, maybe have different routines for different things and have the AI switch between those and ChaseEnemy as the situation changes.

You want your bot to stop chasing its enemy and move to a certain position?

Just break that while loop when you want your bot to stop chasing the enemy.
Then just call “self:MoveToPos()” to move your bot somewhere, and once the bot reaches that position, call “self:ChaseEnemy()” again.