To make a bot target a different bot or any IObject
Code: Select all
IObject targetObj = ...
IPlayer player = ...
player.SetGuardTarget(targetObj);
var bs = Player.GetBotBehaviorSet();
bs.GuardRange = 1f;
bs.ChaseRange = 1f;
player.SetBotBehaviorSet(bs);
I need to find a way to make my bot hunt down a specific target, in my case only melee is sufficient. This code is the closest I can get for now
Code: Select all
using SFDGameScriptInterface;
namespace SFDScript.Test
{
public class TargetChasing : GameScriptInterface
{
/// <summary>
/// Placeholder constructor that's not to be included in the ScriptWindow!
/// </summary>
public TargetChasing() : base(null) { }
public void OnStartup()
{
var pos = Game.GetPlayers()[0].GetWorldPosition();
pos.X -= 50;
var bot = Game.CreatePlayer(pos);
bot.SetBotBehaviorSet(BotBehaviorSet.GetBotBehaviorPredefinedSet(PredefinedAIType.BotA));
bot.SetBotBehaviorActive(true);
Events.UpdateCallback.Start(OnUpdate);
}
private bool m_attacking = false;
private void OnUpdate(float obj)
{
var target = Game.GetPlayers()[0];
var bot = Game.GetPlayers()[1];
var attackRadius = 75;
Game.DrawCircle(target.GetWorldPosition(), attackRadius, Color.Red);
if (Vector2.Distance(bot.GetWorldPosition(), target.GetWorldPosition()) < attackRadius)
{
if (!m_attacking && Game.IsEditorTest)
Game.CreateDialogue("Attack", bot);
bot.SetGuardTarget(null);
m_attacking = true;
}
else
{
if (m_attacking && Game.IsEditorTest)
Game.CreateDialogue("Move", bot);
bot.SetGuardTarget(target);
m_attacking = false;
}
}
}
}