Hello,
Is it possible to spawn a combatant via their index number in code?

If so, can you give me example of this?
  • In fact, is it also possible to do this via schematic ?
  • edited March 2023
    In schematics there's the Spawn Combatant node for that - but it spawns a selected combatant or combatant group. So, you can't type in an ID or something like that, just regular popup selection :)

    Via code is also possible, check out the combatant scripting documentation.
    Post edited by gamingislove on
    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!
  • Smashing, thanks. Does the same apply for adding items to the combatant, equipment etc? It would be handy to be able to use the index
  • Well, yeah, most data can be accessed like that and used to do stuff.

    Some things are no longer referenced by the main project, though, and can only be accessed via their individual data assets. Check out the scripting overview documentation for details.
    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 March 2023
    Thanks, can I get a more detailed explanation please? The api and scripting documents may be fine for a seasoned coder but I can’t seem to get things to work via their index number.
    Post edited by cookereptiles on
  • Well, that depends on what you want to do :)

    E.g. adding an item to a combatant's inventory:
    combatant.Inventory.Add(new ItemShortcut(ORK.Items.Get(index), quantity), true, true, true);
    combatant is the instance of the combatant.
    index is the ID/index of the item.
    quantity is, well, the quantity :)
    The rest of the parameters are just for showing notifications, console texts and marking the item as new.
    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!
  • Excellent, thank you
  • edited March 2023
    If I try a similar thing but with equipping equipment, when I use EquipShortcut I get an error saying ‘EquipShortcut’ cannot be used like a method?

    GamingIsLove.ORKFramework.Combatants.CombatantsEquipment.Equip(-1, EquipShortcut(ORK.Equipment.Get(2), 1, 1), combatant, combatant, true);

    combatant being the current selected combatant component on the game object.
    Post edited by cookereptiles on
  • You're missing the new before EquipShortcut to instantiate it :)
    Also, you need to do this on an instance of a combatant, e.g. like this:
    combatant.Equipment.Equip(null, new EquipShortcut(ORK.Equipment.Get(index), 1, 1), null, combatant.Inventory, true);

    The first argument (null in this case) would be the equipment slot, passing null will use the first matching slot.
    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 March 2023
    Thanks,
    I’m getting: cannot convert GamingIsLove.ORKFramework.Inventory to GamingIsLove.ORKFramework.Combatant

    Also, can we bypass taking it from the inventory and giving directly to the combatant or do I need to add it to the inventory first?
    Post edited by cookereptiles on
  • If I set combatant.Inventory to null it works
  • Thanks very much
  • edited March 2023
    Ah, yeah, you can just pass the combatant, not the inventory - there was a change :)
    So, this doesn't take it from inventory and puts whatever is currently equipped into the combatant's inventory:
    combatant.Equipment.Equip(null, new EquipShortcut(ORK.Equipment.Get(index), 1, 1), null, combatant, true);
    Post edited by gamingislove on
    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 March 2023
    Thanks for the help.

    How do I retrieve the index number of an equipped item. I know how to assign to a shortcut but how do I get the index number of item?

    Post edited by cookereptiles on
  • You can directly access the equipment slots and their equipment via:
    combatant.Equipment[index]
    index being the ID/index of the equipment slot.

    E.g. access to the equipped equipment:
    combatant.Equipment[index].Equipment

    And getting it's ID/index:
    combatant.Equipment[index].Equipment.ID

    Do a null check on the Equipment first, or check if the slot is equipped (does the same thing):
    if(combatant.Equipment[index].Equipped)
    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.