Timer for Cooldown skill

Blitz3D Forums/Blitz3D Beginners Area/Timer for Cooldown skill

Giuliani(Posted 2014) [#1]
Hi,

I would to create a put a timer into a slot.
So that when I use a spell or skill, I know exactly how many time left before I could use again.
Today, the code works fine but I cannot know exactly how many time left, so If I click again on the spell, the timer restart each time to zero.. Not very efficient
Here is the code for the moment...
(The last lines have been commented out)

			; Spell
			If ActionBarSlots(Slot) < 0
				If RequireMemorise
					Num = ActionBarSlots(Slot) + 10
					RechargeTime = SpellsList(Me\KnownSpells[Me\MemorisedSpells[Num]])\RechargeTime
					Pa$ = RCE_StrFromInt$(Me\KnownSpells[Me\MemorisedSpells[Num]], 2)
				Else
					Num = ActionBarSlots(Slot) + 1000
					RechargeTime = SpellsList(Me\KnownSpells[Num])\RechargeTime
					Pa$ = RCE_StrFromInt$(Me\KnownSpells[Num], 2)
				EndIf
				; Recharged
				If Me\SpellCharge[Num] <= 0
					If PlayerTarget > 0
						AI.ActorInstance = Object.ActorInstance(PlayerTarget)
						Pa$ = Pa$ + RCE_StrFromInt$(AI\RuntimeID, 2)
					EndIf
					RCE_Send(Connection, PeerToHost, P_SpellUpdate, "F" + Pa$, True)
					Me\SpellCharge[Num] = RechargeTime
				; Not recharged
				Else
					Output(LanguageString$(LS_AbilityNotRecharged), 255, 50, 50)
				EndIf
			; Item
			ElseIf ActionBarSlots(Slot) < 65535
				For i = 0 To Slots_Inventory
					If Me\Inventory\Items[i] <> Null
						If Me\Inventory\Items[i]\Item\ID = ActionBarSlots(Slot)
							PlaySound(GY_SBeep)
							UseItem(i, 1)
							Exit
						EndIf
					EndIf
				Next
			EndIf
		EndIf
;		If ActionBarCooldownTimer(Slot, 0) > 0
;			If ActionBarCooldownTimer(Slot, 1) = 0
;				ActionBarCooldownTimer(Slot, 1) = MilliSecs()
;				ActionBarCooldownLABEL(Slot) = GY_CreateLabel(Parent, X#, Y#, Label$, cR = 255, cG = 255, cB = 255, Just = Justify_Left)
;				If ActionBarCooldownTimer(Slot, 1) < MilliSecs() - 999
;					ActionBarCooldownTimer(Slot, 0) = Int(MilliSecs() - ActionBarCooldownTimer(Slot, 1))


Thanks in advance for your guidance


RemiD(Posted 2014) [#2]
Example to track time with millisecs()
Graphics3D(640,480,32,2)
SetBuffer(BackBuffer())

ThingStart% = MilliSecs()
ThingTime% = 0
While(KeyDown(1)<>1)
 
 If(KeyHit(57)=1)
  ThingStart = MilliSecs()
 EndIf

 ThingTime = MilliSecs() - ThingStart

 SetBuffer(BackBuffer())
 ClsColor(000,000,000)
 Cls()

 Color(255,255,255)
 Text(0,0,"ThingStart = "+ThingStart)
 Text(0,20,"ThingTime = "+ThingTime)

 Flip(1)

Wend

End()


If you want to forbid the use of a spell before a certain amount of time, simply replace :
If(KeyHit(57)=1)
  ThingStart = MilliSecs()
 EndIf

by something like that :
 If(KeyHit(57)=1)
  If(ThingTime => 5000) ;5000ms = 5s
   ;cast spell here
   ThingStart = MilliSecs()
  endif
 EndIf



Talavar(Posted 2014) [#3]
To keep track of the exact time you could use something like this.



Giuliani(Posted 2014) [#4]
Thanks a lot RemiD and Talavar.
I will look further into this.

And sorry for the delay, I was very busy. ^^

Thanks again guys