Good evening,

I've been trying to get a combatant given it's ID and adding it to a group, but what i've been trying doesn't work.

My external class is the following:
public Group backlogTasks;

void Start()
{
backlogTasks = new Group(1); //1 is the enemy faction
}


public void AddTaskById(int taskID)
{
CombatantHandler taskSearch = new CombatantHandler();
Combatant task = taskSearch.Get(taskID);
backlogTasks .Join(task, false, false);

GetTaskList();
}
The thing is that i can't find an error flag in my console and i don't know where the fail is...

How could i get the combatant if i only have the real ID? Is there a more appropiate approach? would it be possible if i search the Combatant by it's name?
  • Based on the code I assume this is for ORK 2?
    Anyway - do you want to get an existing combatant, or create a new combatant?

    The CombatantHandler class manages all existing/spawned combatants, you can access the game's instance via ORK.Game.Combatants and shouldn't create a new one like that (as there'll be nothing in there).
    So, if you want to get an existing combatant:
    Combatant combatant = ORK.Game.Combatants.Get(index);
    index is the ID/index of the combatant in the editor.

    You can create a new combatant like this:
    Combatant combatant = ORK.Access.Combatant.CreateInstance(index, group, true, true);
    index is the ID/index of the combatant in the editor.
    Please consider rating/reviewing my products on the Asset Store (hopefully positively), as that helps tremendously with getting found.
    If you're enjoying my products, updates and support, please consider supporting me on patreon.com!
  • edited August 3
    Yes, it was for ORK2... I forgot to tell

    I will use both: create combatant and getting existing combatants.

    Thanks! I get to do what i was trying! :D

    Post edited by iarrans on
  • I have now another problem...
    Is it possible, given the real ID of a instanced combatant, assuming the combatant is in a group, destroying the instance associated to that group?

    I mean, i've created a combatant A given the RealID Index:
    Combatant combatant = ORK.Access.Combatant.CreateInstance(index, group, true, true);

    and now, as a parameter, i receive the same RealID for deleting it from the group where it was instanciated and destroying the instance.
    How could i do that?

    I've tried the following, but it doesn't delete anything:


    Combatant combatant = ORK.Game.Combatants.Get(realID);
    group.Remove(combatant, true, true, true, true);


    Thanks in advance!
  • @iarrans have you checked this post to make constants out ORK List Classes?
    https://forum.orkframework.com/discussion/3336/resource-generating-ork-constants-for-scripting/p1
    I think would be helpful instead of remembering the Editor Real ID
  • The combatant's real ID is the ID/index in the editor and is the same for all combatants of that kind.

    If you want to remove a combatant from it's group, you can access the group via combatant.Group, e.g. combatant.Group.Remove(combatant, ...)
    Please consider rating/reviewing my products on the Asset Store (hopefully positively), as that helps tremendously with getting found.
    If you're enjoying my products, updates and support, please consider supporting me on patreon.com!
  • Thank you both! I'll be trying both solutions :D
  • Maybe i'made some mistakes in other parts of the code, but here's my method:
    public void ReturnTaskById(int taskID)
    {
    //erase task from group
    Combatant combatant = ORK.Game.Combatants.Get(taskID);
    combatant.Group.Remove(combatant,true,true,true,true);

    //add task to de RealID list of pending tasks
    pBacklogIDs.Add(taskID);
    pBacklogIDs.Sort();

    }
    But, when i iterate pBacklogIDs list (list of RealIDs) and the group the combatant belonged (sprintBacklogTasks, which is used later in the following code), tasks hasn't been erased at all. I've tried placing some debug.log() through the code and i'm sure it stops in the remove step, because it stops printing just after this step. It's like it raises and excepcion...

    I've also read the thread @RustedGames recommended, but sadly i didn't understand how that works...

    The method ReturnTaskById is supposed to be the contrary of this one;
     public void AddTaskById(int taskID)
    {

    bool taskexists = pBacklogIDs.Remove(taskID);

    if (taskexists) {
    Combatant task = ORK.Access.Combatant.CreateInstance(taskID, sprintBacklogTasks, true, true);
    }

    }
    Could the firs method work? The first surely does
  • Well, removing a combatant from it's group doesn't remove it from the game, it'll just be in it's own little group, all alone :)

    If the combatant is spawned, it'll remain in the game. You have to destroy it's prefab:
    GameObject.Destroy(combatant.GameObject);
    Please consider rating/reviewing my products on the Asset Store (hopefully positively), as that helps tremendously with getting found.
    If you're enjoying my products, updates and support, please consider supporting me on patreon.com!
Sign In or Register to comment.