Space Engineers

Space Engineers

AiEnabled v1.9
ogrimdooh Apr 6, 2022 @ 9:14am
I would like 2 new methods in the API
Hello \o/ congratulations for the work on this mod, it is simply very good.
I'm developing a mod that uses AiEnabled and I needed to perform 2 actions with the bots. First, a method to return the bot's Owner ID, passing the bot's entity ID. And another to define the Bot's ToolDefinition allowing the built-in mods to change the bots' weapons.

I did the implementation locally and it's working fine, I'll attach it here.
I hope I'm not being invasive, I just made the code so if it's possible to add these methods to make it less work for you.

FILE: AiSession.cs

public bool SetBotTool(long botEntityId, string toolSubtype)
{
BotBase bot;
if (Bots.TryGetValue(botEntityId, out bot))
{
var definition = MyDefinitionManager.Static.TryGetHandItemForPhysicalItem(new MyDefinitionId(typeof(MyObjectBuilder_PhysicalGunObject), toolSubtype));
if (definition != null)
{
bot.ToolDefinition = definition;
bot.EquipWeapon();
return true;
}
}
return false;
}

public long GetBotOwnerId(long botEntityId)
{
BotBase bot;
if (Bots.TryGetValue(botEntityId, out bot))
return bot.Owner?.IdentityId ?? 0;
return 0;
}

FILE: LocalBotAPI.cs

METHOD: BuildMethodDictionary() new dict entries:

{ "SetBotTool", new Func<long, string, bool>(SetBotTool) },
{ "GetBotOwnerId", new Func<long, long>(GetBotOwnerId) },

NEW METHODS:

/// <summary>
/// Change the weapon or tool equipped on the bot
/// </summary>
/// <param name="botEntityId">The EntityId of the Character</param>
/// <param name="toolId">the SubtypeId of the weapon or tool</param>
/// <returns>true if you managed to change the weapon or tool</returns>
public bool SetBotTool(long botEntityId, string toolSubtype) => AiSession.Instance?.SetBotTool(botEntityId, toolSubtype) ?? false;

/// <summary>
/// Recuperar o codigo da jogador dono do bot
/// </summary>
/// <param name="botEntityId">The EntityId of the Character</param>
/// <returns>Returns the code of the player that owns the bot, if it does not exist, the value is 0</returns>
public long GetBotOwnerId(long botEntityId) => AiSession.Instance?.GetBotOwnerId(botEntityId) ?? 0;

FILE: RemoteBotAPI.cs

METHOD: ReceiveModMessage() new dict entries:

_setBotTarget = dict["SetBotTarget"] as Func<long, object, bool>;
_resetBotTargeting = dict["ResetBotTargeting"] as Func<long, bool>;

NEW METHODS:

private Func<long, string, bool> _setBotTool;
private Func<long, long> _getBotOwnerId;

/// <summary>
/// Change the weapon or tool equipped on the bot
/// </summary>
/// <param name="botEntityId">The EntityId of the Character</param>
/// <param name="toolId">the SubtypeId of the weapon or tool</param>
/// <returns>true if you managed to change the weapon or tool</returns>
public bool SetBotTool(long botEntityId, string toolSubtype) => _setBotTool?.Invoke(botEntityId, toolSubtype) ?? false;

/// <summary>
/// Recuperar o codigo da jogador dono do bot
/// </summary>
/// <param name="botEntityId">The EntityId of the Character</param>
/// <returns>Returns the code of the player that owns the bot, if it does not exist, the value is 0</returns>
public long GetBotOwnerId(long botEntityId) => _getBotOwnerId?.Invoke(botEntityId) ?? 0;

Thanks in advance, and a great job \o/
Last edited by ogrimdooh; Apr 6, 2022 @ 9:20am
< >
Showing 1-3 of 3 comments
jTurp  [developer] Jun 22, 2022 @ 3:37pm 
Hey, yes I can add these. It's probably better to reach me on the Discord as I don't see these discussions
jTurp  [developer] Jun 23, 2022 @ 12:41pm 
I have these added to the next update (v0.16.5b)
ogrimdooh Jun 23, 2022 @ 7:19pm 
Thx
< >
Showing 1-3 of 3 comments
Per page: 1530 50