woobla Posted June 12, 2022 Share Posted June 12, 2022 (edited) 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 June 12, 2022 by woobla Link to comment Share on other sites More sharing options...
Hugo Qwerty Posted June 12, 2022 Share Posted June 12, 2022 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 Link to comment Share on other sites More sharing options...
stuck1a Posted December 15, 2022 Share Posted December 15, 2022 (edited) 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 December 15, 2022 by stuck1a Hugo Qwerty 1 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now