Remove item from inventory?

Im working on a small script that add items to a storage box inventory using the add item node. And its works very well.
But HOW do i remove a number of items from the box again using a script?
I need it to ramdom remove between 1-2 items from a item stack. But don’t know how to make the script. There is a remove item node but don’t know how to use it?

Can someone help me out :)?

IncrementItemQuantity function, give it a -(neg) number that will remove items

On the add item node? Sure about that?
I tried it last time and did not work. but i can try again :smiley:

Well there is “addItem” and that gives a new stack/item. Then there is “IncrementItemQuantity” which acts against an existing stack, I know this works much better as I used to directly set the stack size, which caused issues, this function properly adds, and removes (if you give it a -neg value like -3) however if you have two stacks of wood (100 each total of 200) and you wanted to say “IncrementItemQuantity -300” it would only take away one stack.

So you may need to make some helper functions and an int too store the “needs to consume amount”. one function checks the inventory or your desired item, adding up all the quantities. then you compare the total quantities against the ‘needs to consume’ you can then loop around the inventory again calling another function that 1st compares the stacks current itemQuantity against the “needs to consume” if the need is greater you can use a clamp function where the max is supplied by the item quantity, this clamped value then subtracks from the need to consume, and calls the IncrementItemQuantity using that clamped value * -1 (turns it into a neg) now that is how you’d consume the correct amount.

But I think you’re just saying “Can I remove 1-2 items at random” less logic, but same final method “IncrementItemQuantity”

Ok im home now and look at it. Was not the IncrementItemQuantity i tried :S
But have tried to set it up using the IncrementItemQuantity but can’t really find out how to get it all to work.
Way do it has to be difficult to remove an item when its so easy to add one :stuck_out_tongue:

Yeah I normally just loop through the entire inventory, cast the default return object found to the item I’m looking for, then apply logic. You could loop through, create an array of ints for the inventory array indexes to directly reference the items in the inventory in a smaller loop rather than doing two full loops (cpu optimization).

And I know right? It took me a few weeks to figure out the correct way to manipulate item stack sizes (quantities*, used to mod Minecraft) because setting the itemQuantity to 0 doesn’t remove it, just now it’s weightless (altho dropping it and picking it up results in nothing, better to use the function that Wildcard created as it handles the removal of the item)

Has been gone for some time.
But is back on the mod. And tried to get it to work with the Increment Item Quantity. But never godt it to work :S

When I get home I’ll post some code that I use for an Item that auto upgrades itself my consuming items.

That would be very nice :smiley:

Here is my function code that is used to consume item stacks
I pass in the master Item’s current ItemRating value (master Item is what is getting the upgrade), Item that is to be consumed, the targets current item quantity (I could have just grabbed that in the function since I have the item there but meh), and a value I pass that is needed to be consumed (1,2 or 4) if that stack doesn’t meet that requirement it just breaks out and looks for another stack. If it is >= then it takes that consume amount * -1 so it’s now a -(neg) value it will consume from that stack (if the stack was 2, and I increment by -2 it will destroy the stack also don’t forget to check “Is from consumption”)

Now this is not perfect because if I needed to consume 3 of something, and I had 3 stacks of 1. My code won’t consume anything. If I wanted to do that I’d need to create arrays, and loop through and collect all the item stacks, and slowly consume from them until my amount needed is met. And that’s if the total found stacks do add up to 3 or greater. So this logic can be made better. But I have other things to learn before I sink time into perfecting this (as it will take time to set it all up correctly, and not have it cause lag with too many loops)

Thx :slight_smile: Is not home right now but will take a look at it when im home again.
But i might have one stupid question :S
How do this know what item type/stack to consume the item from?

The thing is i have a special type og torch. and i need it to remove one item from a fuel stack that is not being burned everytime you light the fire.

so to start the fire it burns 2 fuel items?

Well 1st off you can read my reply on a similar topic (checking to see if an item is one you want)

However it all depends on how you want to implement it, Currently I think ARK burns fuel from weakest to strongest (Thatch, Wood, Sparkpowder,??)
if you want to go for that route, you will have to create a PrimalItem var that holds the “most eligible” fuel item to consume.

So as you cycle through the inventory (you can probably see the foreachloop in my post linked above) you compare the item (from the inventory) and check the var (isValid) if the var is empty (as the 1st round it is) check to see the inventory item is a fuel item, if the var is populated (round 2 and up) you will have to check to see if is what I found before a better fuel source or worse and do you assignment there.

if you happen to only have 1 stack in the inventory you might have to default to consuming from it as there is no other stacks. Because the quick a dirty way is to just say consume item from inventory index of [1] (which in code means slot 2 as indexes start at 0 in the code world) but you still run into the issue of 1 item inventories.

Depending if you want the quick and dirty is inventory array length > 1 consume index [1] or [0] (I’m pretty sure you can’t access the light fire command if there is no fuel) but you run into “Is it really a fuel item in the second slot?” so to make your logic/code do what you want you can cheap out and just say fk it, or you can create your “business rule” then the acceptance criteria and then the plan of attack

“When the torch is lit (start trigger) I want it to consume 2 fuel(?) items”
Acceptance Criteria
If there is more than one stack, it will take split the consumption between two stacks
If there is only one stack check to make sure that its quantity is greater than one so there is 1 used to start the fire, and the remainder is for the extra consumption
(Unless if there is just 1 stack you don’t want it to light the fire at all)
Plan of Attack (more or less plan out what you need to complete this coding wise)

In whitch class/blueprint did you put your grap? I’am trying to understand this devkit and UR4 but having a hard time. In whitch classes are the actual inventoryitems stored? I assume there is some listobject to iterate throug but where can i find this. i hope to get some pointers or nice tutorials about inventory handling.