edited August 2014 in ORK Scripting
How do I get access to the inventory if I have set it to be a group inventory and then how do I get the current amount of items in the inventory?

I tried "ORK.Game.ActiveGroup.GetMember(0).Inventory.GetCount()" but that doesn`t work.

EDIT: I remember it being said somewhere here on the forum or in one of the tutorials that you can set up ORK Framework to use your inventory system. Do I remember that correctly? Does it involve recompiling the DLL? Or is there some option somewhere that I have overlooked?
Post edited by Kashrlyyk on
  • There currently is no count function to get the overall count of items in the inventory, you can only get the count of specific items by ID. I'll add functions for that in the next update.

    You can use your own inventory system if you like - but that will require you to do your own scripting, so you wont get around recompiling the DLL :)
    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 2014
    Oh, please do because having to do this:


    for(int cnt = 0; cnt < (c1.Inventory.GetItemCount(0)+
    c1.Inventory.GetItemCount(1) +
    c1.Inventory.GetItemCount(2) +
    c1.Inventory.GetItemCount(3) +
    c1.Inventory.GetItemCount(4) +
    c1.Inventory.GetItemCount(5)); cnt++ )
    {
    _inventoryORKParty.Add(c1.Inventory.GetItem(cnt));
    }

    for(int cnt = 0; cnt < (c1.Inventory.GetWeaponCount(0)+
    c1.Inventory.GetWeaponCount(1) +
    c1.Inventory.GetWeaponCount(2) +
    c1.Inventory.GetWeaponCount(3) +
    c1.Inventory.GetWeaponCount(4) +
    c1.Inventory.GetWeaponCount(5)+
    (c1.Inventory.GetArmorCount(0)+
    c1.Inventory.GetArmorCount(1) +
    c1.Inventory.GetArmorCount(2) +
    c1.Inventory.GetArmorCount(3) +
    c1.Inventory.GetArmorCount(4) +
    c1.Inventory.GetArmorCount(5))); cnt++ )
    {
    _inventoryORKParty.Add(c1.Inventory.GetEquipment(cnt,0));
    }
    c1.Inventory.Clear();


    to move all the items from the inventory into a list of "IShortcut" is not practical.
    Post edited by Kashrlyyk on
  • Will be coming in the next update :)
    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 2014
    I have copied the content of the inventory into the new list and now I try to display the icon and name of all the entries in that list. The only icon that is displayed by this line:

    GUI.DrawTexture(inventoryRect, _inventoryORKParty[cnt].GetIcon());

    where "cnt" goes from zero to "_inventoryORKParty.Count" is the healing potion icon.

    The other items in the "IShortcut" List are two weapons and one armor. They cause this:

    "NullReferenceException: Object reference not set to an instance of an object
    Inventory.InventoryWindow (Int32 id) (at Assets/Scripts/CharacterMechanic/Inventory.cs:263)
    UnityEngine.GUI.CallWindowDelegate (UnityEngine.WindowFunction func, Int32 id, UnityEngine.GUISkin _skin, Int32 forceRect, Single width, Single height, UnityEngine.GUIStyle style) (at C:/BuildAgent/work/d63dfc6385190b60/artifacts/EditorGenerated/GUI.cs:1402)"

    So the only way to display the entire list of items in the inventory is by using the menu screen as shown in "http://orkframework.com/game-tutorial/2013/12/30/35-menu-screens-1/" by checking "Add Weapons, Add Armors".

    EDIT: I had to use "_inventoryORKParty = c1.Inventory.GetContent(c1,false,true,true,true);" instead of the two for loops from my post above. I found that line in "InventoryMenuPart.cs".
    Post edited by Kashrlyyk on
  • Using the GetContent function of the inventory is a way better choice, since you'll get all the stuff that's in there this way (and a lot faster than getting everything individually). The IShortcut interface has a Quantity property, so you'll just need to combine those of all from the list to get the total quantity.

    I can't really tell you what's wrong with your code without seeing more.
    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 2014
    I have added it to my smaller project and the inventory window there consists only of this:


    private void InventoryWindow(int id) {
    /*******************************************/

    //ORK STUFF
    for(int cnt = 0; cnt < (c1.Inventory.GetItemCount(0)+c1.Inventory.GetItemCount(1) +c1.Inventory.GetItemCount(2) +c1.Inventory.GetItemCount(3) +
    c1.Inventory.GetItemCount(4) +c1.Inventory.GetItemCount(5)); cnt++ ) {
    InventoryTest.Add(c1.Inventory.GetItem(cnt));
    }

    for(int cnt = 0; cnt < (c1.Inventory.GetWeaponCount(0)+c1.Inventory.GetWeaponCount(1) +c1.Inventory.GetWeaponCount(2) +c1.Inventory.GetWeaponCount(3) +
    c1.Inventory.GetWeaponCount(4) +c1.Inventory.GetWeaponCount(5)+(c1.Inventory.GetArmorCount(0)+c1.Inventory.GetArmorCount(1) +c1.Inventory.GetArmorCount(2) +c1.Inventory.GetArmorCount(3) +
    c1.Inventory.GetArmorCount(4) +c1.Inventory.GetArmorCount(5))); cnt++ ) {
    InventoryTest.Add(c1.Inventory.GetEquipment(cnt,0));
    }

    for(int cnt = 0; cnt < InventoryTest.Count; cnt++){
    inventoryRect = new Rect(50,50*cnt,40,40);
    }
    if(InventoryTest[0].GetName() != "" ) {
    GUI.DrawTexture(inventoryRect, InventoryTest[0].GetIcon());}
    if(InventoryTest[1].GetName() != "" ) {
    GUI.DrawTexture(inventoryRect, InventoryTest[1].GetIcon());}
    if(InventoryTest[2].GetName() != "" ) {
    GUI.DrawTexture(inventoryRect, InventoryTest[2].GetIcon());}
    if(InventoryTest[3].GetName() != "" ) {
    GUI.DrawTexture(inventoryRect, InventoryTest[3].GetIcon());}
    if(InventoryTest[4].GetName() != "" ) {
    GUI.DrawTexture(inventoryRect, InventoryTest[4].GetIcon());}



    }


    The error I got points to this line:

    if(InventoryTest[1].GetName() != "" ) {

    "NullReferenceException: Object reference not set to an instance of an object
    NewBehaviourScript1.InventoryWindow (Int32 id) (at Assets/_prefab/NewBehaviourScript1.cs:108)
    UnityEngine.GUI.CallWindowDelegate (UnityEngine.WindowFunction func, Int32 id, UnityEngine.GUISkin _skin, Int32 forceRect, Single width, Single height, UnityEngine.GUIStyle style) (at C:/BuildAgent/work/d63dfc6385190b60/artifacts/EditorGenerated/GUI.cs:1402)"

    I have also used a different order in the item collector box. The first item in the InventoryTest list is now a weapon.
    Post edited by Kashrlyyk on
  • Don't just assume stuff is there ... check if it is null and if the list/array is that large before accessing it :)
    If that line is throwing a null exception, it's probably because the item is null.
    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.