Official Everybody Edits Forums

Do you think I could just leave this part blank and it'd be okay? We're just going to replace the whole thing with a header image anyway, right?

You are not logged in.

#1 2016-10-14 22:38:38

SmittyW
Member
Joined: 2015-03-13
Posts: 2,085

[Help] How do I make a Cooldown Timer?

I've seen those wicked sick bots where you shoot blocks and then there's a cooldown period. How do I keep track of a lot of players shooting then having to wait before shooting again? I wouldn't want to use stopwatches that count every tick for every player, right? Would I store the time when the player shoots and then check when they press shoot again if the difference between current time and previous time is greater than cooldown period?

Offline

#2 2016-10-14 22:40:09

Slabdrill
Formerly 12345678908642
From: canada
Joined: 2015-08-15
Posts: 3,402
Website

Re: [Help] How do I make a Cooldown Timer?

latter


suddenly random sig change

Offline

#3 2016-10-14 23:08:04

Kaslai
Official Caroler
From: SEAͩT̓͑TLͯͥͧͪ̽ͧE͑̚
Joined: 2015-02-17
Posts: 787

Re: [Help] How do I make a Cooldown Timer?

Indeed, you want the second option. Timestamps with millisecond accuracy should suffice for anything game related.

When a button is pressed, simply compare the current time in milliseconds to the time the last bullet was fired for the player. If the difference is greater than your timeout, then fire away.

This is the approach that should be taken for just about anything timing related where you don't need an event fired at regular intervals.

You do need to be somewhat careful though, as a 32 bit integer can only represent an interval of about 49.7 days in milliseconds. If your bot runs for longer than that, you might get some issues if you don't account for overflow. Or... You can use a 64 bit integer, which can represent an interval of up to 584,550,048 years in milliseconds...

Offline

Wooted by:
Kaslai1476482884629739

Board footer

Powered by FluxBB

[ Started around 1732211382.4002 - Generated in 0.044 seconds, 11 queries executed - Memory usage: 1.36 MiB (Peak: 1.45 MiB) ]