edited August 2015 in ORK Scripting
I'm trying to add an item via script. I could get around this if there were a Game Variable option for the Add To Inventory step, but it only accepts a preset selection.

I searched through the forums and the closest answer I found was here:
forum.orkframework.com/discussion/812/solved-removing-a-weapon-from-the-inventory/p1

But I don't understand how to use an IShortcut item. To me it seems like the code should be like this:

// The ItemID we want to add
int ItemID;

public void AddItem(){
// Get my Combatant / Player
Combatant TestCombatant = ComponentHelper.GetCombatant(gameObject);
// Create an IShortcut. Place the data from the ORK Items database that matches the ItemID.
IShortcut ItemToAdd = ORK.Items.data[ItemID] as IShortcut;
// Add the Item to the player's inventory.
TestCombatant.Inventory.AddItem(ItemToAdd);
}
But the above doesn't even compile, complaining that ItemToAdd is overloading AddItem.

Ideas about what I'm doing wrong here? Thanks in advance.
Post edited by Nixter on
  • You can create an ItemShortcut (the IShortcut implementation of an item) like this:

    ItemShortcut item = new ItemShortcut(int itemID, int quantity);

    itemID is the index/ID of the item, quantity the quantity of the item.
    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 2015
    Thank you for responding, but that doesn't seem to solve the problem.

    Is the final line correct?

    TestCombatant.Inventory.AddItem(item);


    because that is the line that is giving me an overload error.

    error CS1501: No overload for method `AddItem' takes `1' arguments
    Post edited by Nixter on
  • edited August 2015
    Wait, nevermind. I think I have it solved. I assumed that the two bools were not required, but they are.

    Yeah, that was the problem. I ignored filling in all the arguments. Gotta remember not to assume they are default arguments.
    Post edited by Nixter on
  • I had originally used optional parameters, but the Mono 2.0 subset used by Unity doesn't like that when compiling, so I had to remove them all :)
    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!
  • Thanks for your help! It was my fault for being a lazy programmer. :)
Sign In or Register to comment.