horst_onager Posted May 27, 2021 Share Posted May 27, 2021 Hey everybody, I've been trying to get into DST modding and for my first mod, I tried to make a mod that simlpy makes all players poop in a configurable interval (based on the player's hunger decay), and optionally when eating something. It seemed to work fine at first, but when testing for longer periods of time while playing, I noticed that I was unable to pick up some of the manures, but that's definitely not the case for all of them. This is the code I've come up with so far: modmain.lua Spoiler local TUNING = GLOBAL.TUNING TUNING.POOP_INTERVAL = GetModConfigData("poop_interval") TUNING.POOP_RANDOMIZATION = GetModConfigData("poop_randomization") TUNING.POOP_ONEAT = GetModConfigData("poop_oneat") print(TUNING.POOP_INTERVAL, TUNING.POOP_RANDOMIZATION, TUNING.POOP_ONEAT) local function CanSpawnPoop(inst) -- TODO? return true end -- play sound on successful poop local function OnPoopSpawn(player, inst) if CanSpawnPoop(player) and inst ~= nil then inst.SoundEmitter:PlaySoundWithParams("dontstarve/creatures/together/bernie_big/footstep", { size = 1 }) end end -- poop on food eaten local function OnEat(inst) if TUNING.POOP_ONEAT then inst.components.periodicpoopspawner:ForceNextSpawn() end end -- update spawn interval depending on hunger burn rate os player local function UpdatePoopSpawnInterval(inst, data) local delta = (data ~= nil and data.delta or -0.15625) local overtime = (data ~= nil and data.overtime or false) print(delta, overtime) if delta >= 0 or not overtime then return end local basetime = TUNING.POOP_INTERVAL / (-delta) * (1 - TUNING.POOP_RANDOMIZATION) local randtime = basetime * TUNING.POOP_RANDOMIZATION * 2 local remaining_time = (inst.components.periodicpoopspawner.target_time or 0) - GLOBAL.GetTime() local no_reset = inst.components.periodicpoopspawner.task ~= nil and remaining_time < basetime + randtime inst.components.periodicpoopspawner:SetRandomTimes(basetime, randtime, no_reset) -- print(inst.components.periodicpoopspawner:GetDebugString()) end -- add PeriodicPoopSpawner to passed player instance, as well as listeners to update the interval on hunger changes -- and poop when the player eats something local function AddPoopSpawner(inst) inst:AddComponent("periodicpoopspawner") inst.components.periodicpoopspawner:SetSpawnTestFn(CanSpawnPoop) inst.components.periodicpoopspawner:SetOnSpawnFn(OnPoopSpawn) inst:ListenForEvent("hungerdelta", UpdatePoopSpawnInterval) inst:ListenForEvent("oneat", OnEat) UpdatePoopSpawnInterval(inst, { delta = -0.15625, overtime = true }) inst.components.periodicpoopspawner:Start() end -- add poop spawner to all players AddPlayerPostInit(AddPoopSpawner) Flags set in modinfo.lua Spoiler api_version = 10 all_clients_require_mod = false client_only_mod = false dst_compatible = true scripts/components/periodicpoopspawner.lua Spoiler -- separate subclass to not mess anything up in the existing spawners local PeriodicSpawner = require("components/periodicspawner") local PeriodicPoopSpawner = Class(PeriodicSpawner, function(self, inst) PeriodicSpawner._ctor(self, inst) self.prefab = "poop" end) -- add OnSave and OnLoad functions to correctly save and load progress to next poop function PeriodicPoopSpawner:OnSave() if self.target_time ~= nil then return { remaining_time = self.target_time - GetTime() } else return nil end end function PeriodicPoopSpawner:OnLoad(data) if data ~= nil then self:SetRandomTimes(data.remaining_time, 0, false) end end return PeriodicPoopSpawner My guess would be that for some reason the prefab gets only spawned locally and not on the server, if that's even possible? But I have no idea why that would even happen. Does someone have an idea what's going on here? All help is appreciated! Link to comment https://forums.kleientertainment.com/forums/topic/130342-unable-to-pick-up-some-items-spawned-by-my-mod/ Share on other sites More sharing options...
penguin0616 Posted May 28, 2021 Share Posted May 28, 2021 1. Were you testing with caves enabled? 2. Did you check if manure had all the components it should have had (such as inventoryitem)? 1 Link to comment https://forums.kleientertainment.com/forums/topic/130342-unable-to-pick-up-some-items-spawned-by-my-mod/#findComment-1464248 Share on other sites More sharing options...
horst_onager Posted May 28, 2021 Author Share Posted May 28, 2021 1 hour ago, penguin0616 said: 1. Were you testing with caves enabled? I did, and the behaviour was the same inside the caves. Sometimes I could pick up the poop, sometimes I couldnt. 1 hour ago, penguin0616 said: 2. Did you check if manure had all the components it should have had (such as inventoryitem)? It has, It's just the default "poop" prefab that is also spawned by beefalos. I also noticed that the poop I couldnt pick up vanishes when I stop and restart the server. Link to comment https://forums.kleientertainment.com/forums/topic/130342-unable-to-pick-up-some-items-spawned-by-my-mod/#findComment-1464270 Share on other sites More sharing options...
penguin0616 Posted May 28, 2021 Share Posted May 28, 2021 That would mean that the poop only exists on the client, but your modinfo says it is a server mod. I suggest you double check that is the case with a TheWorld.ismastersim check in AddPoopSpawner. 2 Link to comment https://forums.kleientertainment.com/forums/topic/130342-unable-to-pick-up-some-items-spawned-by-my-mod/#findComment-1464343 Share on other sites More sharing options...
horst_onager Posted May 29, 2021 Author Share Posted May 29, 2021 You're right, it seems the mod gets loaded client-side too with default settings, so the ismastersim check fixed it. Thanks a lot! Link to comment https://forums.kleientertainment.com/forums/topic/130342-unable-to-pick-up-some-items-spawned-by-my-mod/#findComment-1464570 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