blazerdrive09 Posted June 23, 2016 Share Posted June 23, 2016 I am currently making a composter mod to help increase the rate at which food spoils. I am also making it possible for the food to turn into guano if it rots inside the composter. I have successfully made it possible to do so in don't starve single player as well as in Don't Starve Together. However, I noticed that an extra rot spawns in the world on the ground when a food item decays within the composter and turns into guano. This didn't happen in Don't Starve single player and this doesn't happen when a food item simply rots inside a player inventory (and turns into rot and not guano in the player inventory). If somebody can help me figure out why an extra rot spawns in the world when a food item rots in the composter that would helpful. Here is the code i modified in the perishable lua file for this to occur. function Perishable:Perish() if self.updatetask ~= nil then self.updatetask:Cancel() self.updatetask = nil end if self.perishfn ~= nil then self.perishfn(self.inst) end if self.inst:IsValid() then self.inst:PushEvent("perished") end --NOTE: callbacks may have removed this inst! if self.inst:IsValid() and self.onperishreplacement ~= nil then local goop = SpawnPrefab(self.onperishreplacement) if goop ~= nil then local owner = self.inst.components.inventoryitem ~= nil and self.inst.components.inventoryitem.owner or nil if owner:HasTag("composter") then goop = SpawnPrefab("guano") end if goop.components.stackable ~= nil and self.inst.components.stackable ~= nil then goop.components.stackable:SetStackSize(self.inst.components.stackable.stacksize) end local holder = owner ~= nil and (owner.components.inventory or owner.components.container) or nil if holder ~= nil then local slot = holder:GetItemSlot(self.inst) self.inst:Remove() holder:GiveItem(goop, slot) else local x, y, z = self.inst.Transform:GetWorldPosition() self.inst:Remove() goop.Transform:SetPosition(x, y, z) end end end end Link to comment Share on other sites More sharing options...
Aquaterion Posted June 23, 2016 Share Posted June 23, 2016 local goop = SpawnPrefab(self.onperishreplacement) goop = SpawnPrefab("guano") isnt that 2 prefabs spawned? Link to comment Share on other sites More sharing options...
blazerdrive09 Posted June 23, 2016 Author Share Posted June 23, 2016 (edited) Wait so does the game spawn, the prefab then change its location with the food then remove the food so it spawns two prefabs as a result of the code running twice? i thought goop was just the prefab that would be spawned in. Edited June 23, 2016 by blazerdrive09 Link to comment Share on other sites More sharing options...
Aquaterion Posted June 23, 2016 Share Posted June 23, 2016 local goop = SpawnPrefab(self.onperishreplacement) --spawn a prefab, and keep track of it under the variable "goop" if goop ~= nil then -- if goop prefab exists local owner = self.inst.components.inventoryitem ~= nil and self.inst.components.inventoryitem.owner or nil if owner:HasTag("composter") then -- if owner has the tag composter goop = SpawnPrefab("guano") -- spawn ANOTHEr prefab, and keep track of it under the viarable "goop", which means we lost track of the first prefab, but it still exists end so: if owner:HasTag("composter") then goop:Remove() goop = SpawnPrefab("guano") end Link to comment Share on other sites More sharing options...
blazerdrive09 Posted June 24, 2016 Author Share Posted June 24, 2016 Yup, thanks. 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