Lumina Posted February 4, 2017 Share Posted February 4, 2017 Hi again, So i have a custom structure and i would like it to disappears a few days after i build it. For example something like 6 days of lifetime. Is it possible ? If my structure is a container, i guess i could use this kind of code to drop all it containt when disappearing ? inst.components.lootdropper:DropLoot() inst.components.container:DropEverything() inst.SoundEmitter:PlaySound("dontstarve/common/destroy_metal") inst:Remove() Thanks for any help. Link to comment https://forums.kleientertainment.com/forums/topic/73818-is-it-possible-to-make-a-structure-disappears-after-a-time/ Share on other sites More sharing options...
Lumina Posted February 5, 2017 Author Share Posted February 5, 2017 Anyone have a clue ? A structure (even a mod) i could use as example ? Because i don't know where to start. Any help will be welcome Link to comment https://forums.kleientertainment.com/forums/topic/73818-is-it-possible-to-make-a-structure-disappears-after-a-time/#findComment-863974 Share on other sites More sharing options...
HabdomeRaider Posted February 5, 2017 Share Posted February 5, 2017 You probably want to look at DoTaskInTime. There are a lot of examples throughout the game code. Link to comment https://forums.kleientertainment.com/forums/topic/73818-is-it-possible-to-make-a-structure-disappears-after-a-time/#findComment-863978 Share on other sites More sharing options...
Lumina Posted February 5, 2017 Author Share Posted February 5, 2017 Thanks a lot, it's very helpful. But isn't "DoTaskInTime" for very short duration ? Right now i am trying something with "DoPeriodicTask", is it better ? Worse ? Link to comment https://forums.kleientertainment.com/forums/topic/73818-is-it-possible-to-make-a-structure-disappears-after-a-time/#findComment-863986 Share on other sites More sharing options...
CarlZalph Posted February 5, 2017 Share Posted February 5, 2017 36 minutes ago, Lumina said: Thanks a lot, it's very helpful. But isn't "DoTaskInTime" for very short duration ? Right now i am trying something with "DoPeriodicTask", is it better ? Worse ? Based on abigail_flower prefab and untested. local TUNING_DURATION = 30 inst.DoDestruction = function(inst) inst.components.lootdropper:DropLoot() inst.components.container:DropEverything() inst.SoundEmitter:PlaySound("dontstarve/common/destroy_metal") inst:Remove() end inst.StartDestruction = function(inst, timeleft) if inst.destroytimer then inst.destroytimer:Cancel() end inst.destroytimer = inst:DoTaskInTime(timeleft, DoDestruction) inst.timestart = GetTime() + timeleft - TUNING_DURATION end inst.OnSave = function(inst, data) if inst.timestart then local timeconsumed = GetTime() - inst.timestart if timeconsumed>0 then data.timeconsumed = timeconsumed end end end inst.OnLoad = function(inst, data) if data and data.timeconsumed then local timeleft = math.max(0, TUNING_DURATION - data.timeconsumed) inst:StartDestruction(timeleft) end end __After the TheWorld.ismastersim check__ inst:StartDestruction(TUNING_DURATION) Link to comment https://forums.kleientertainment.com/forums/topic/73818-is-it-possible-to-make-a-structure-disappears-after-a-time/#findComment-863995 Share on other sites More sharing options...
Lumina Posted February 5, 2017 Author Share Posted February 5, 2017 Thanks I used another way but right now i don't know what is the better resource wise. I'm using something similar to the test to regrow mushroom : local function onsave(inst, data) data.timecheck = inst.timecheck end local function onload(inst, data) if data.timecheck or inst.timecheck then inst.timecheck = data.timecheck or inst.timecheck end end local function checkdestroy(inst) -- print("Time Check") inst.timecheck = inst.timecheck - 1 if inst.timecheck <= 0 then inst.components.lootdropper:DropLoot() inst.components.container:DropEverything() inst.SoundEmitter:PlaySound("dontstarve/common/destroy_metal") inst:Remove() end end inst.timecheck = 44 inst:DoPeriodicTask(TUNING.SEG_TIME*2, checkdestroy, TUNING.SEG_TIME + math.random()*TUNING.SEG_TIME) (and maybe some others code i forgot). It seems to work fine but i don't know if it's a good way to manage it. Anyway thanks a lot, both of you Link to comment https://forums.kleientertainment.com/forums/topic/73818-is-it-possible-to-make-a-structure-disappears-after-a-time/#findComment-863999 Share on other sites More sharing options...
Ricoom Posted February 5, 2017 Share Posted February 5, 2017 You can also check how its done for tent. There are also mod that adds similiar structures into game. It was "additional structures" if I remember correctly. Link to comment https://forums.kleientertainment.com/forums/topic/73818-is-it-possible-to-make-a-structure-disappears-after-a-time/#findComment-864006 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