HeroEngine Forums
Welcome, Guest. Please login or Register for HeroCloud Account.

Author Topic: Creating a round timer for a round-based game  (Read 1217 times)

Joseph-B

  • General Accounts
  • *
  • Posts: 5
    • View Profile
Creating a round timer for a round-based game
« on: Dec 05, 16, 07:13:26 AM »

Hi all!

I'm currently trying to make a round timer for a round-based game. (For example, each round will last for 120 seconds, at the end of this timer the round will reset).

I'm used to programming with a main entry point so I'm still getting used to this :) ! From reading the documentation I believe I need to invoke a script through a timer.

( http://hewiki.heroengine.com/wiki/Script_entry_points )
( http://hewiki.heroengine.com/wiki/TIMER )

I believe I need to make a TimeInterval

myNode.myTimer.fireRate = 00:01:20

It seems that so long as the timerState is ON, when the timer reaches 0 it will it will call tick() and start counting down again, and whilst timer state is OFF it will not call tick().

I'm not sure if i'm approaching this correctly or if there is a better method to use, any advice or feedback is greatly appreciated!

Many Thanks,

Joseph.
Logged

Thazager

  • General Accounts
  • *
  • Posts: 1149
  • Never stop learning
    • View Profile
    • Heroes and Villains MMORPG
Re: Creating a round timer for a round-based game
« Reply #1 on: Dec 05, 16, 07:40:17 PM »

This is one way of doing it. The "TimeInterval" will allow you to also keep track of the date. Where a "timer" will only keep track of the time. Either can be used.

When the round starts the timer is initialized, set with a value of 00:01:20. When the timer runs out, becomes 00:00:00 it will do what happens at the end of that time.

An example can be found in server side script E_CommonCharacterClassMethods

in method InitCommonCharacter() the regen timer is started for each character (player and npc).

Code: [Select]
  // start regen tick
  if( me.E_regenTimer.timerState == ON )
    me.E_regenTimer.stop()
  .
  me.E_regenTimer.fireRate = 00:00:01
  me.E_regenTimer.start()


when the timer reaches 0 (after 1 second), This method takes place --> the health (HP) is added to while checking for max of 100.

Code: [Select]
method E_regenTimer_tick()
  if me.IsDead()
    return
  .
  if me.IsInCombat()
    return
  .
  me.EO_HitPoints = MiscUtils:Min( me.EO_HitPoints + 10, 100 )
.


They have a class E_CommonCharacter with field E_regenTimer as a timer. Notice how the _tick is added to make the method name E_regenTimer_tick()
Logged

GlorianLanTarini

  • General Accounts
  • *
  • Posts: 148
    • View Profile
Re: Creating a round timer for a round-based game
« Reply #2 on: Dec 07, 16, 12:00:56 AM »

Hi, Joseph.

Really, there is several way to doing it. I would recommend you the following:

Code: [Select]
method RoundInitialization()
  //all cool staff that may need initialization
  //and then
 
  me.secondsRemain = 120
  me.RoundTimer.fireRate = TimeInSeconds(1.0)
  me.RoundTimer.start()
.

method RoundTimer_tick()
  me.secondsRemain -= 1
  if me.secondsRemain <= 0
    //call end_of_round from here
  .
.

Why this method is better? Because you can replicate field "secondsRemain" to clients and do many useful things on callback. For exemple, change GUI label which show remain time for players. And you can do many things on server too.

Also, TimeInSeconds(seconds as Float) is very useful and recommended, as it allows to avoid mistake: 120 seconds = 00:01:20. (actually 00:02:00.000)
Logged