Jump to content

making a timer immune to the pause function?


pickleplayer

Recommended Posts

Another weird question, I know. d:

 

So I'm trying to do this thing where the game pauses and then un-pauses itself in a specific amount of time, but I guess the DoTaskInTime also pauses when the game does, so I can't un-pause it with that.

 

I remember reading some random tidbit on the DS wiki about a bug with Charlie where if you paused the game during her warning sound, she would attack instantly when you un-paused it, instead of the normal delay.

 

I took a look around in the grue.lua component, but it just looks like more DoTaskInTime timers to me?? Or something with PushEvents that I have no idea what file they go to?  Does this bug even still exist? I'm a little confused.

 

Does anyone know how this bug works, or how I could replicate it for my own use?

 

 

I'll paste grue.lua down here so you don't have to dig it up. it's not too big

local Grue = Class(function(self, inst)    self.inst = inst    self.soundevent = nil    self.warndelay = 1        inst:ListenForEvent("enterdark",         function(inst, data)             self:Start()        end)    inst:ListenForEvent("enterlight",         function(inst, data)             self:Stop()        end)    inst:ListenForEvent("invincibletoggle",        function(inst, data)             if self:CheckForStart() then                self:Start()            end        end)    self.inst:DoTaskInTime(0, function()           if self:CheckForStart() then            self:Start()        end    end)end)function Grue:CheckForStart()    return not self.inst.components.health:IsInvincible() and not self.inst.LightWatcher:IsInLight() and not self.inst.components.health:IsDead()endfunction Grue:Start()    self.inst:StartUpdatingComponent(self)     self.nextHitTime = 5+math.random()*5    self.nextSoundTime = self.nextHitTime* (.4 + math.random()*.4)endfunction Grue:SetSounds(warn, attack)    self.soundwarn = warn    self.soundattack = attackendfunction Grue:Stop()    self.inst:StopUpdatingComponent(self) endfunction Grue:OnUpdate(dt)    if self.inst.components.health:IsDead() or self.inst.components.health:IsInvincible() then        self:Stop()        return    end        if self.nextHitTime > 0 then        self.nextHitTime = self.nextHitTime - dt    end        if self.nextSoundTime > 0 then        self.nextSoundTime = self.nextSoundTime - dt                if self.nextSoundTime <= 0 then            if self.soundwarn then                self.inst.SoundEmitter:PlaySound(self.soundwarn)            end            self.inst:DoTaskInTime(self.warndelay, function() self.inst:PushEvent("heargrue") end)        end            end        if self.nextHitTime <= 0 then            self.nextHitTime = self.nextHitTime - dt        self.nextSoundTime = self.nextSoundTime - dt        self.inst.components.combat:GetAttacked(nil, TUNING.GRUEDAMAGE)		self.inst.components.sanity:DoDelta(-TUNING.SANITY_MEDLARGE)                self.nextHitTime = 5+math.random()*6        self.nextSoundTime = self.nextHitTime* (.4 + math.random()*.4)        if self.soundattack then            self.inst.SoundEmitter:PlaySound(self.soundattack)        end                self.inst:PushEvent("attackedbygrue")    endendreturn Grue

 

Thanks in advance for any help!

Link to comment
Share on other sites

@pickleplayer Couldn't find something that updates automatically while the game is paused, but here's some relevant information.

 

DoTaskInTime, PushEvent, DoPeriodicTask, etc. are all in entityscript.lua

They use the scheduler from scheduler.lua

 

SetPause is in mainfunctions.lua

function SetPause(val,reason)    if val ~= paused then		if val then			paused = true			TheSim:SetTimeScale(0)			TheMixer:PushMix("pause")		else			paused = false			TheSim:SetTimeScale(default_time_scale)			TheMixer:PopMix("pause")			--ShowHUD(true)		end        if PlayerPauseCheck then   -- probably don't need this check            PlayerPauseCheck(val,reason)  -- must be done after SetTimeScale        end	endend

 

Sleep function?

(Check out EntityScript:StartThread too)

 

Try messing with the OnUpdate functions, might work.

 

But, what are you trying to accomplish with this? There might be a better way to do it. Is it something like the Relaxed Crafting mod?

 

something with PushEvents that I have no idea what file they go to?

To find what is listening for that event, just search for this:

ListenForEvent("event_name" 

(No closing bracket because it works with more parameters)

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

Please be aware that the content of this thread may be outdated and no longer applicable.

×
  • Create New...