Invarkul Posted October 22, 2019 Share Posted October 22, 2019 Recently I created my second mod and everything appear to be working, but I found out that my function that makes my item unpickable for other characters crushing my game while putted into chest or at the fight agains toadstool. The game says smth wrong with inventory-dropitem line (nil value). I suggest that non-player inventory such as chest's don't have inventory as their variable. Quote inst.components.inventoryitem.onputininventoryfn = function(inst, player) if player.prefab ~= "bibi" then inst:DoTaskInTime(0.01, function() player.components.inventory:DropItem(inst) player.components.talker:Say("I don't want to cut of my toes with it!") end) endend Link to comment Share on other sites More sharing options...
ShinyMoogle Posted October 23, 2019 Share Posted October 23, 2019 The onputininventory function is called pretty much any time an item gets a new "owner", be it another player or some container. It's specifically called in Container:GiveItem. if in_slot then --weird case where we are trying to force a stack into a non-stacking container. this should probably have been handled earlier, but this is a failsafe if not self.acceptsstacks and item.components.stackable and item.components.stackable:StackSize() > 1 then item = item.components.stackable:Get() self.slots[in_slot] = item item.components.inventoryitem:OnPutInInventory(self.inst) self.inst:PushEvent("itemget", { slot = in_slot, item = item, src_pos = src_pos }) return false end self.slots[in_slot] = item item.components.inventoryitem:OnPutInInventory(self.inst) self.inst:PushEvent("itemget", { slot = in_slot, item = item, src_pos = src_pos }) if not self.ignoresound and self.inst.components.inventoryitem ~= nil and self.inst.components.inventoryitem.owner ~= nil then self.inst.components.inventoryitem.owner:PushEvent("gotnewitem", { item = item, slot = in_slot }) end return true end You can add another condition to your function to verify that the owner is a player, so it'll skip trying to call the function if the new owner is a container: inst.components.inventoryitem.onputininventoryfn = function(inst, player) if player:HasTag("player") and player.prefab ~= "bibi" then inst:DoTaskInTime(0.01, function() player.components.inventory:DropItem(inst) player.components.talker:Say("I don't want to cut of my toes with it!") end) end end Link to comment Share on other sites More sharing options...
Jessie_ Posted October 23, 2019 Share Posted October 23, 2019 the solution i put here should work: Link to comment Share on other sites More sharing options...
Invarkul Posted October 23, 2019 Author Share Posted October 23, 2019 8 hours ago, ShinyMoogle said: The onputininventory function is called pretty much any time an item gets a new "owner", be it another player or some container. It's specifically called in Container:GiveItem. if in_slot then --weird case where we are trying to force a stack into a non-stacking container. this should probably have been handled earlier, but this is a failsafe if not self.acceptsstacks and item.components.stackable and item.components.stackable:StackSize() > 1 then item = item.components.stackable:Get() self.slots[in_slot] = item item.components.inventoryitem:OnPutInInventory(self.inst) self.inst:PushEvent("itemget", { slot = in_slot, item = item, src_pos = src_pos }) return false end self.slots[in_slot] = item item.components.inventoryitem:OnPutInInventory(self.inst) self.inst:PushEvent("itemget", { slot = in_slot, item = item, src_pos = src_pos }) if not self.ignoresound and self.inst.components.inventoryitem ~= nil and self.inst.components.inventoryitem.owner ~= nil then self.inst.components.inventoryitem.owner:PushEvent("gotnewitem", { item = item, slot = in_slot }) end return true end You can add another condition to your function to verify that the owner is a player, so it'll skip trying to call the function if the new owner is a container: inst.components.inventoryitem.onputininventoryfn = function(inst, player) if player:HasTag("player") and player.prefab ~= "bibi" then inst:DoTaskInTime(0.01, function() player.components.inventory:DropItem(inst) player.components.talker:Say("I don't want to cut of my toes with it!") end) end end I really appreciate your help, but I think you should definetly check Jessie's code. It seem to be easier. Anyway thank you :3 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