Jump to content

remove item after create recipe


woobla

Recommended Posts

Hello. Please helps!
We are making a recipe.
In the recipe, we execute a function in the onCreate event that adds items item1 and item2.
I need to remove item3.
Does anyone know how to do this?
inv:remove("TestMod.Item3"); - does not work

 

function recipe_CreateItems(items, result, player)
	local inv = player:getInventory();
	inv:AddItems("TestMod.Item1",2);
	inv:AddItems("TestMod.Item2",3);
	inv:remove("TestMod.Item3");
end

 

recipe Create Two Items
{
  Result:item3,
  Sound:AddItemInRecipe,
  Time:100.0,
  Category:Farming,
  OnGiveXP:Give10CookingXP,
  NeedToBeLearn:true,
  OnCreate:recipe_CreateItems,
}

 

Issue resolved.
You need to add RemoveResultItem:true to the recipe,

Edited by woobla
Link to comment
Share on other sites

  • 6 months later...
On 6/12/2022 at 1:34 PM, Hugo Qwerty said:

Just FYI, there is no remove function - it's Remove, or RemoveOneOf.  There's also a DoRemoveItem.  I don't know what the difference is between them.

https://zomboid-javadoc.com/41.65/zombie/inventory/ItemContainer.html

 

This is the source of those functions

public void Remove(InventoryItem inventoryItem) {
  for ( int i=0; i < this.Items.size(); ++i ) {
    InventoryItem _item = (InventoryItem)this.Items.get(i);
    if ( _item == inventoryItem ) {
      if ( inventoryItem.uses > 1 ) --inventoryItem.uses; else this.Items.remove(inventoryItem);
      inventoryItem.container = null;
      this.drawDirty = true;
      this.dirty = true;
      if ( this.parent != null ) this.dirty = true;
      if ( this.parent instanceof IsoDeadBody ) ((IsoDeadBody)this.parent).checkClothing(inventoryItem);
      if ( this.parent instanceof IsoMannequin ) ((IsoMannequin)this.parent).checkClothing(inventoryItem);
      return;
    }
  }
}


public void DoRemoveItem(InventoryItem inventoryItem) {
   this.drawDirty = true;
   if ( this.parent != null ) this.dirty = true;
   this.Items.remove(inventoryItem);
   inventoryItem.container = null;
   if ( this.parent instanceof IsoDeadBody ) ((IsoDeadBody)this.parent).checkClothing(inventoryItem);
   if ( this.parent instanceof IsoMannequin ) ((IsoMannequin)this.parent).checkClothing(inventoryItem);
}

 

So DoRemoveItem() simply deletes the item regardless of its type, while Remove() checks if it is a drainable and if so, it subtracts only one consumption unit from it. Any none-drainables will be deleted, too.

Also Remove() uses a loop which seems unecessary since ArrayList.remove() won't throw an error if the argument is not present in it, so I guess, this is a deprecated method which just remains for backwards compat for mods since you can use the usedDelta etc now for drainables

If so, you should prefer DoRemoveItem() for the sake of performance.

 

But tbh, that's just a guess based on the code

 

 

Edited by stuck1a
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...