Search the Community
Showing results for tags 'timer'.
-
Using a timer to play a song
ScrewdriverLad posted a topic in [Don't Starve Together] Mods and Tools
So I'm making a character who dies every 22 minutes, called the Hatchling. I have a functional script that will instantly kill the Hatchling after a 22 minute timer... but I wanted a warning system. My plan was that after 20 minutes, (2 minutes before death) a song will start playing. I made a timer script, based on the same timer for the Kill Loop. Here's the scripts I have. If someone can help me, please do! I labelled them with comments, and even put in print() functions, but the print("EndSong plays") appears in the console before the Hatchling even loads in. --Kills the Hatchling after a certain time. At release, it should be 22 minutes. AddPrefabPostInit("hatchling", function(inst) print("AddPrefabPostInit") if not inst.components.timer then inst:AddComponent("timer") end inst.components.timer:StartTimer("when the sun explodes",60*3) --should be "when the sun explodes",60*22) print("Timer start") local function YouGetKilled(inst) if inst.components.health and not inst.components.health:IsDead() then inst.components.health:Kill() print("running YouGetKilled") end end inst:ListenForEvent("timerdone", YouGetKilled) -- revive yourself here -- assume you have a home if inst.components.homeseeker then inst.Transform:SetPosition(inst.components.homeseeker:GetHomePos()) print("Going Home") end -- revive inst:PushEvent("ms_respawnedfromghost") print("respawning") inst:ListenForEvent("ms_respawnedfromghost", function() if inst.components.timer:TimerExists("when the sun explodes") then inst.components.timer:StopTimer("when the sun explodes") print("stopping timer") end inst.components.timer:StartTimer("when the sun explodes",60*3) --should be "when the sun explodes",60*22) print("restarting timer") end) end) --This script should play The End Times when there's 2 minutes left in the Loop AddPrefabPostInit("hatchling", function(inst) print("AddPrefabPostInit") if not inst.components.timer then inst:AddComponent("timer") end inst.components.timer:StartTimer("EndSong",60) --should be "EndSong",60*20) print("EndSong Timer start") inst:ListenForEvent("timerdone") inst.SoundEmitter:PlaySound("sound/customvoice") --adding this causes the game to crash upon loading the Hatchling. It doesn't give me anything useful, though. print("playing song") inst:ListenForEvent("ms_respawnedfromghost", function() if inst.components.timer:TimerExists("EndSong") then inst.components.timer:StopTimer("EndSong") print("stopping EndSong timer") end inst.components.timer:StartTimer("EndSong",60) --should be "when the sun explodes",60*22) print("restarting EndSong timer") end) end) As a note: CustomVoice is the name of the .fev and .fsb files I'm using for the song. I'll be renaming it once I get everything working properly. -
I'm making a character whose main gimmick is that they die every 22 minutes, then can be revived with no Max HP cost. How would I keep their Max HP from going down? Would I put some script into their lua, or would I need to put it in a new revival item unique to them? (My original plan was to add a new revival item for them to use anyway, so that won't be a problem.)
-
i wanted to add an Aura to Butterflies that gives me Sanity standing close to them and losing it when i'm far from them; i did both parts, but the problem is that i wanted to add a timer where, if i'm far from any butterflies, first i don't lose any Sanity, then i start losing it after 5 seconds, like i have a countdown to get close to one This is my code, but it doesn't work, Delta remains 0 even after few seconds, it's like the NightmareMode function doesn't even start Any ideas?
- 4 replies
-
- mod
- sanity aura
-
(and 1 more)
Tagged with:
-
I was looking at a meteor shower then thought that I might be able to use that to make a sort of "PK Starstorm" like attack (Brawl version, not the unavoidable, almost polar opposite, actual version :P) So; would I be able to just add a new component and remove the rock spawning, then add a custom projectile using local projectile = SpawnPrefab("star") or am I missing something? Just asking so I don't spend 5 hours or something doing the wrong thing Thanks for you help, ProtoStar.
-
Case 1: local prefab = "evergreen" --could be anything elselocal interval = 1 --secAddPrefabPostInit(prefab,function(inst) inst:DoPeriodicTask(interval,function(inst) --Do some staff with high CPU load end)end) And case 2: local prefab = "evergreen" --could be anything elselocal interval = 1 --secAddPrefabPostInit(prefab,function(inst) inst:AddTag("some_tag")end)AddPrefabPostInit("forest",function(inst) inst:DoPeriodicTask(interval,function(inst) local ents = GLOBAL.TheSim:FindEntities(0,0,0,1200,{"some_tag"}) for i,v in ipairs(ents) do --Do some staff with high CPU load end end)end)What is better?
- 21 replies