TalSh Posted May 15, 2016 Share Posted May 15, 2016 (edited) Hello everyone. A mod I wrote allows players to sew upgraded hiking bags using existing hiking bags. I've found a bug where if one of the hiking bags used to make the upgraded version is equipped on the player's back, the resulting backpack is unequipped, and the player no longer has an option to equip anything on his/her back, as if the original bag is still equipped. There are no options to unequip, as the game thinks nothing is equipped. The resulting bag (and any others) can only be equipped as primary and secondary. The only solution is starting a new game. I've just tested again, and this issue does not occur when the bag is equipped as primary and secondary, only when it is equipped on the player's back. Here is the code I used for the upgraded bag, and for creating the recipe: item SmallUpgradedHikingBag { WeightReduction = 85, Weight = 0.6, Type = Container, Capacity = 27, DisplayName = Small Upgraded Hiking Bag, Icon = SmallUpgradedHikingBag, CanBeEquipped = Back, OpenSound = PZ_OpenBag, CloseSound = PZ_CloseBag, PutInSound = PZ_PutInBag, } recipe Make Small Upgraded Hiking Bag { keep Needle, keep Scissors, Thread=2, NormalHikingBag=2, Result:SmallUpgradedHikingBag, Time:250.0 } Has anyone seen or been able to fix this? What am I missing? Sorry if this has already been covered. I've tried searching but couldn't find anything related. Thanks in advance! Edited May 15, 2016 by TalSh Link to comment Share on other sites More sharing options...
TalSh Posted May 16, 2016 Author Share Posted May 16, 2016 After more testing, and after specifying that the required recipe items are destroyed during the crafting, the problem only occurs when you right click an equipped bag and use that to start the crafting process. If you craft through the dedicated crafting menu, it will never use an equipped bag, nor will it count towards the recipe requirements. Link to comment Share on other sites More sharing options...
Berdryn Posted October 13, 2016 Share Posted October 13, 2016 Not sure if you are still working on this but I think the problem is you need a comma after the time in the recipe. Link to comment Share on other sites More sharing options...
tommysticks Posted October 15, 2016 Share Posted October 15, 2016 I noticed this issue with hdryocraft. If you remove the bag from your back and then restart the game, or relog onto the server, the problem should be resolved. I am on my phone so I can't take a proper look at your coding, but a work around may be something like this: getPlayer():setClothingItem_Back(nil) ...hook that into crafting and it should unequip anything that's equipped to the back. Berdryn 1 Link to comment Share on other sites More sharing options...
nolanri Posted October 19, 2016 Share Posted October 19, 2016 On 2016-10-15 at 7:06 AM, tommysticks said: I noticed this issue with hdryocraft. If you remove the bag from your back and then restart the game, or relog onto the server, the problem should be resolved. I am on my phone so I can't take a proper look at your coding, but a work around may be something like this: getPlayer():setClothingItem_Back(nil) ...hook that into crafting and it should unequip anything that's equipped to the back. To elaborate on this: put OnCreate:RemoveBackPack, in your recipies, eg: recipe Make Small Upgraded Hiking Bag { keep Needle, keep Scissors, Thread=2, NormalHikingBag=2, Result:SmallUpgradedHikingBag, OnCreate:RemoveBackPack, Time:250.0, } Then make a lua/client/ folder in your media folder, make a file called RemoveBackPack.lua in that file put: function RemoveBackPack(items, result, player) player:setClothingItem_Back(nil) ; end which should force remove the backoack after the craft so the option to equip should be available afterwards Link to comment Share on other sites More sharing options...
TalSh Posted April 25, 2017 Author Share Posted April 25, 2017 (edited) Sorry for resurrecting this old thread, but using the tips provided by tommysticks and nolanri, I was able to fix the bag equipping issue. Thank you both! The other annoying issue persists: items in your equipped bag are lost if it is used in the crafting process. I understand this issue also existed in Hydrocraft, so I assumed it couldn't be fixed. Is this still true? Any way to get around it other than warning users to empty their bags before crafting? Edited April 26, 2017 by TalSh Typos Link to comment Share on other sites More sharing options...
tommysticks Posted April 26, 2017 Share Posted April 26, 2017 function itemCheck(item, resultItem, player) local pInv = player:getInventory(); local iTab2 = {}; --need an empty table later local dItem; for i = 0, (item:size()-1) do --item = number of items required for recipe dItem = item:get(i); if dItem:getCategory() == "Container" then --if any items in recipe are bags... print("Container detected") if player:getClothingItem_Back() == dItem then --...and are equiped on the back... player:setClothingItem_Back(nil); end if player:getPrimaryHandItem() == dItem then --...or are equiped primary... player:setPrimaryHandItem(nil); end if player:getSecondaryHandItem() == dItem then --...or are equiped secondary... player:setSecondaryHandItem(nil); --remove them from being equipped end dInv = dItem:getInventory(); --get the inventory of recipe item dInvItems = dInv:getItems(); --get the size of the inventory if dInvItems:size() >= 1 then --if container is empty we are finished i.e. less than 1 item for i2 = 0, (dInvItems:size()-1) do --if not, iterate over each item invItem = dInvItems:get(i2); table.insert(iTab2, invItem) --add each item to empty table print(invItem:getType()); end end end end for i3, k3 in ipairs(iTab2) do print (k3:getType()..": removing from container.") dInv:Remove(k3); --remove items from container in recipe pInv:AddItem(k3); --add items to player inventory end end Try pasting that over Nolan's original code and everything should work. I did some limited testing. Rainoa 1 Link to comment Share on other sites More sharing options...
TalSh Posted April 26, 2017 Author Share Posted April 26, 2017 1 hour ago, tommysticks said: function itemCheck(item, resultItem, player) local pInv = player:getInventory(); local iTab2 = {}; --need an empty table later local dItem; for i = 0, (item:size()-1) do --item = number of items required for recipe dItem = item:get(i); if dItem:getCategory() == "Container" then --if any items in recipe are bags... print("Container detected") if player:getClothingItem_Back() == dItem then --...and are equiped on the back... player:setClothingItem_Back(nil); end if player:getPrimaryHandItem() == dItem then --...or are equiped primary... player:setPrimaryHandItem(nil); end if player:getSecondaryHandItem() == dItem then --...or are equiped secondary... player:setSecondaryHandItem(nil); --remove them from being equipped end dInv = dItem:getInventory(); --get the inventory of recipe item dInvItems = dInv:getItems(); --get the size of the inventory if dInvItems:size() >= 1 then --if container is empty we are finished i.e. less than 1 item for i2 = 0, (dInvItems:size()-1) do --if not, iterate over each item invItem = dInvItems:get(i2); table.insert(iTab2, invItem) --add each item to empty table print(invItem:getType()); end end end end for i3, k3 in ipairs(iTab2) do print (k3:getType()..": removing from container.") dInv:Remove(k3); --remove items from container in recipe pInv:AddItem(k3); --add items to player inventory end end Try pasting that over Nolan's original code and everything should work. I did some limited testing. This is amazing. Thank you so much. Those annotations are so great! I really appreciate you taking the time to do this. Link to comment Share on other sites More sharing options...
tommysticks Posted April 26, 2017 Share Posted April 26, 2017 13 minutes ago, TalSh said: This is amazing. Thank you so much. Those annotations are so great! I really appreciate you taking the time to do this. I try to give thorough annotations when I help out so people have a chance to learn, though I'm sure my shit could be cleaned up quite a bit. I'm still learning. Lemme know if anything doesn't work as expected. GoodOldLeon 1 Link to comment Share on other sites More sharing options...
TalSh Posted April 26, 2017 Author Share Posted April 26, 2017 Working great according to a bit of testing! Thanks again! Link to comment Share on other sites More sharing options...
Dezert Posted July 1, 2018 Share Posted July 1, 2018 On 26.04.2017 at 8:01 PM, tommysticks said: function itemCheck(item, resultItem, player) local pInv = player:getInventory(); local iTab2 = {}; --need an empty table later local dItem; for i = 0, (item:size()-1) do --item = number of items required for recipe dItem = item:get(i); if dItem:getCategory() == "Container" then --if any items in recipe are bags... print("Container detected") if player:getClothingItem_Back() == dItem then --...and are equiped on the back... player:setClothingItem_Back(nil); end if player:getPrimaryHandItem() == dItem then --...or are equiped primary... player:setPrimaryHandItem(nil); end if player:getSecondaryHandItem() == dItem then --...or are equiped secondary... player:setSecondaryHandItem(nil); --remove them from being equipped end dInv = dItem:getInventory(); --get the inventory of recipe item dInvItems = dInv:getItems(); --get the size of the inventory if dInvItems:size() >= 1 then --if container is empty we are finished i.e. less than 1 item for i2 = 0, (dInvItems:size()-1) do --if not, iterate over each item invItem = dInvItems:get(i2); table.insert(iTab2, invItem) --add each item to empty table print(invItem:getType()); end end end end for i3, k3 in ipairs(iTab2) do print (k3:getType()..": removing from container.") dInv:Remove(k3); --remove items from container in recipe pInv:AddItem(k3); --add items to player inventory end end Try pasting that over Nolan's original code and everything should work. I did some limited testing. Equiped primary and secondary hand does not work. And also if the container is not empty. How to fix it? Link to comment Share on other sites More sharing options...
Rainoa Posted May 9, 2019 Share Posted May 9, 2019 This is amazing!!! I have been looking for a fix for my bag dye mod i have been working on to auto remove items & keep original bag name if was re-named I have tested with bag equipped primary + secondary + back, With & without items in them! all seems to work perfect ty so much @tommysticks just need to see if i can get help/figure out how to also make bag keep its original rename! tommysticks 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