Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Professional Discussion / Help with attack cool down

Author
Message
Jamie_Leigh
14
Years of Service
User Offline
Joined: 15th Dec 2011
Location:
Posted: 5th Mar 2012 12:24
I need help to add some sort of cool down so that you cant attack 10 times a second!

How would one go about doing this?

Thanks!
WLGfx
18
Years of Service
User Offline
Joined: 1st Nov 2007
Location: NW United Kingdom
Posted: 5th Mar 2012 13:41
You could have a percentage strength counter. Each attack reduces the strength by so much percentage. When your character is not doing anything then it will start increasing again. The more continuous attacks reduces the strength of the attack.

Mental arithmetic? Me? (That's for computers) I can't subtract a fart from a plate of beans!
Warning! May contain Nuts!
TheComet
18
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 5th Mar 2012 17:29
Something like this will do it:



TheComet

New World Order
21
Years of Service
User Offline
Joined: 31st Oct 2004
Location:
Posted: 6th Mar 2012 20:06
Or, if you just want to be able to attack, say once every second, you could make it timer-based:

This will make the cooldown period purely dependent on time and independent from the framerate. The timer counts on and when it is 1 second further than the timestamp of when you last attacked, a new attack will be possible. (note the timer works with milli seconds, so "1000" = 1s)
TheComet
18
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 6th Mar 2012 21:42
@ New World Order

Good solution, however if I had a really bad computer and the game ran only half as fast, I'd actually be able to attack twice as fast as a person who has a good computer and can run the game at full speed. That's why I like to avoid that kind of cooldown.

TheComet

New World Order
21
Years of Service
User Offline
Joined: 31st Oct 2004
Location:
Posted: 6th Mar 2012 23:36
ah, yepp, I see what you mean..^^ but that could be tackled by trying to make almost everything timer dependent (including movement etc), couldn't it? that would guarantee the same gaming pace for every player, albeit jerky performance for slower machines.. i guess?^^
but maybe i was just thinking too much in terms of "This weapon has a cooldown of X seconds."
Millenium7
21
Years of Service
User Offline
Joined: 13th Dec 2004
Location:
Posted: 7th Mar 2012 01:09
I posted this last night in another thread but applies directly here



You can also implement locking/unlocking of states, so that a pistol for instance will not fire automatically. The mouse button must be released and pressed again



However this still abides by the timer rule, so even if you mash the button you can't make it shoot faster than the fire rate specified

This code is timer based and not framerate/loop based, and will run the same on any machine. Please also note that if you run the example code with a sync rate of 0 (or greater than your monitor refresh rate) it may appear as though the firing sequence is not being activated. It is though the 'text' command is only appearing once per loop, so it may appear and disappear before the screen has a chance to refresh. I assure you it's still firing, use a sound or increase the text duration to double check
Ortu
DBPro Master
18
Years of Service
User Offline
Joined: 21st Nov 2007
Location: Austin, TX
Posted: 7th Mar 2012 01:31 Edited at: 7th Mar 2012 01:35
Never mind misread

Neuro Fuzzy
19
Years of Service
User Offline
Joined: 11th Jun 2007
Location:
Posted: 7th Mar 2012 21:48
Quote: "Good solution, however if I had a really bad computer and the game ran only half as fast, I'd actually be able to attack twice as fast as a person who has a good computer and can run the game at full speed. That's why I like to avoid that kind of cooldown."

Wait... maybe I'm having a brain fart but... wouldn't it be the other way around?

Your (thecomet's) way has bullet.cooldown decreasing once a frame and new world order's way has the attack happening once a second or slower. If my computer ran the program at 80 frames per second, then I could attack 4 times a second, but if it ran at 20 frames per second I could only attack once per second. In new world order's method I could attack once per second.

TheComet
18
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 7th Mar 2012 23:05 Edited at: 7th Mar 2012 23:06
@ Neuro

Nah, you're not having a brain fart. My point of view was from the standpoint of the game loops. So when I said "you can attack twice as fast when your game is running twice as slow", I meant that the Bullet.Cooldown variable would take twice as long to count down, but the timer() allows you to "cheat" and slash away in the game twice as fast as usual.

We said the same thing, only your statement was an inversion of my own.

TheComet

Login to post a reply

Server time is: 2026-07-09 00:08:39
Your offset time is: 2026-07-09 00:08:39