Marmalade Posted October 28, 2023 Share Posted October 28, 2023 (edited) I am making a modded character that I want to refuse equipping hand slot items that don't fit the criteria. Still, I'm having some trouble making the item the player wanted to equip safely go back into their inventory. Here's what the code in my character's master_postinit looks like that is responsible local old_Equip = inst.components.inventory.Equip inst.components.inventory.Equip = function(self, item, ...) if item.components.equippable.equipslot == EQUIPSLOTS.HANDS and item:HasTag("weapon") and not item:HasTag("tool") then inst.components.talker:Say(GetString(inst, "ANNOUNCE_NO_WEAPON_FOR_ME_THANKS")) inst.puff = SpawnPrefab(item) inst.components.inventory:GiveItem(inst.puff) item:DoTaskInTime(0, item.Remove) return false end return old_Equip(self, item, ...) end Also, whenever I equip an item that triggers this function to happen, the specific line of code that causes the game to crash is "inst.puff = SpawnPrefab(item)" Edited October 28, 2023 by Marmalade solved Link to comment Share on other sites More sharing options...
_zwb Posted October 28, 2023 Share Posted October 28, 2023 It should be SpawnPrefab(item.prefab) Link to comment Share on other sites More sharing options...
Marmalade Posted October 28, 2023 Author Share Posted October 28, 2023 Ah I didn't know it would be that simple to solve- Thanks for your help! Link to comment Share on other sites More sharing options...
Marmalade Posted October 28, 2023 Author Share Posted October 28, 2023 I soon realized that items with components and stats like durability and skins would be completely reset, getting set back to their max durability and default skin when they were spawned, so I created a different method that keeps these the same New code: local old_Equip = inst.components.inventory.Equip inst.components.inventory.Equip = function(self, item, ...) if item.components.equippable.equipslot == EQUIPSLOTS.HANDS and item:HasTag("weapon") and not item:HasTag("tool") then inst.components.talker:Say(GetString(inst, "ANNOUNCE_NO_WEAPON_FOR_ME_THANKS")) self:DropItem(item) self:GiveItem(item) return false end return old_Equip(self, item, ...) end 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