edited August 2014 in ORK Scripting
This code removes the item from the player inventory:


if( new Rect(WIDTHOFFSET, HEIGHTOFFSET+ (cnt * BUTTONSIZE), BUTTONSIZE,BUTTONSIZE).Contains(e.mousePosition)) {
if(e.type == EventType.mouseDown && e.button == 1){

IShortcut item = _inventPlayer1W[cnt];

c1.Inventory.Remove(c1.Inventory.GetEquipment(item.ID, itemDropType.Weapon),1, true, true);

_inventPlayer1W.Remove(_inventPlayer1W[cnt]); //removes item from the display list
//even if there is still an item with that "ID" in the inventory

_inventPlayer1W = c1.Inventory.GetContent(c1, false, false, true, false);
}
}


But is there a better way that does NOT involve copying all other weapons back into the player inventory, which is this line "_inventPlayer1W = c1.Inventory.GetContent(c1, false, false, true, false);"

That line is necessary because if you have one item more than once it does not create a new entry in the inventory it just increases some value and I don't know which.

I tried to encapsulate the "_inventPlayer1W.Remove(_inventPlayer1W[cnt]);" with "if( c1.Inventory.GetEquipment(item.ID, itemDropType.Weapon).Quantity == 0) " but that throws a "Null Reference" exception.
Post edited by gamingislove on
  • You can just use Inventory.Remove(IShortcut item, bool showNotification, bool showConsole) to remove it from the inventory. Since you already have the shortcuts you can let the inventory do the rest :)

    You can use Inventory.GetWeaponCount(int index) to get the quantity of a weapon in the inventory - you get a null exception because the weapon you're looking for isn't in the inventory and you try to access a property on it.
    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 that worked.
Sign In or Register to comment.