HeroEngine Forums
Welcome, Guest. Please login or Register for HeroCloud Account.
Pages: [1] 2

Author Topic: Simple ability cooldown display  (Read 6328 times)

LastJudge

  • General Accounts
  • *
  • Posts: 215
    • View Profile
Simple ability cooldown display
« on: Jan 08, 12, 04:11:53 PM »

Now we are gonna make a cooldown display for abilities

What we are trying to achieve:



1. We need to add a label above ability icon and delete the abilityShutter (you can still use it if you want to but I don't think it's necessary anymore as we are going to have cooldown shown by numbers.



2. Now we change position and properties
visible = False (we don't want it to be visible normally)
name = abilityCooldownLabel
scale =   ... this is up you, use whatever scale you feel is appropriate
autoCenter = True, True (so our label is always in the middle)
text =    ... I use a number here to actually see where my text will be shown
displayfont = ... use any font you feel is appropriate




Save the xml and close it afterwards.


3. Now we need to create a GUI animation to make this thing work. Open DOM editor and create a new client class. Call it GUIA_Cooldown.
Name: GUIA_Cooldown
Archetype: data
Field: timeIndex


And now we'll need to do the coding part.
Logged

LastJudge

  • General Accounts
  • *
  • Posts: 215
    • View Profile
Re: Simple ability cooldown display
« Reply #1 on: Jan 08, 12, 04:26:50 PM »

4. Create new client script and call it GUIA_Cooldown.
Important: do not write following code into GUIA_CooldownClassMethods as it will not work. You have to make a script called GUIA_Cooldown to make this work.

Code: [Select]
shared function GUIAnimation_init(animation as NodeRef of Class GUIAnimation) as Boolean
  where animation is kindof GUIA_Cooldown
    //this will split the single argument string into a list of the arguments
    SplitBy(animation.GUIanimationArgs, ",", animation.argsList)
 
    if animation.argsList.length != 2
      println("Invalid number of arguments for the fade animation, arguments=" + animation.GUIanimationArgs)
      return false
    .
 
    //record when this animation started
    animation.timeIndex = SYSTEM.TIME.NOW
  .
  return true
.

shared function GUIAnimation_stop(animation as NodeRef of Class GUIAnimation)
  if hasMethod(animation.controlToAnimate, "onAnimationDone")
    animID as String = animation.argsList[2]
    animation.controlToAnimate.onAnimationDone(animID)
  else if (animation.controlToAnimate.script != None)
    if hasFunction(animation.controlToAnimate.script, "onAnimationDone")
      animID as String = animation.argsList[2]
      animation.controlToAnimate.script:onAnimationDone(animation.controlToAnimate, animID)
    .
  .
  if(animation != None)
    destroyNode(animation)
  .
.

shared function GUIAnimation_tick(animation as NodeRef of Class GUIAnimation)
  where animation is kindof GUIA_Cooldown
    //copy the animation arguments into readable variables
    duration as Float = animation.argsList[1]
 
    //this is how much time has elapsed since the animation started
    elapsed as TimeInterval = SYSTEM.TIME.NOW - animation.timeIndex
 
    //if the animation has been running the desired amount of time stop it
    if elapsed.secondsTotal > duration
      GUIAnimation_stop(animation)
      return
    .
 
    //calculate what the alpha should be based on how far along in the animtion it is
    cdlabel as NodeRef of Class GUILabel = animation.controlToAnimate
    cdleft as Integer = Round(duration - elapsed.secondsTotal)
    cdlabel.text = cdleft
    if (cdleft > 10)
      cdlabel.defaultStatePresentation.color.r = 1
      cdlabel.defaultStatePresentation.color.g = 1
      cdlabel.defaultStatePresentation.color.b = 1
    else if (cdleft > 5)
      cdlabel.defaultStatePresentation.color.r = 1
      cdlabel.defaultStatePresentation.color.g = 1
      cdlabel.defaultStatePresentation.color.b = 0
    else if (cdleft > 0)
      cdlabel.defaultStatePresentation.color.r = 1
      cdlabel.defaultStatePresentation.color.g = 0
      cdlabel.defaultStatePresentation.color.b = 0
    else
      cdlabel.visible = false
    .
  .
.

In GUIAnimation_init we initialize the animation. We see if we have 2 arguments and if yes, the animation will proceed.
In GUIAnimation_stop we stop the animation and try to call the OnAnimationDone method of the control that called this animation.
In GUIAnimation_tick we do whatever we need to do during the tick. In our case we calculate the cooldown to display and according to it's value we change the label color to white, yellow or red.


5. Now as we have our new script done, we need to call the animation from our ability bar script, which is E_AbilityBarClassMethods if you don't have you own ability bar yet.

First we change OnAnimationDone method to look like this
Code: [Select]
shared function onAnimationDone(control as NodeRef of Class GUIControl, animID as String)
  control.visible = false
  //  control.size.x = 101
  foreach child in control.parent.children
    if child != control
      child.defaultStatePresentation.color.a = 1
      child.hoverStatePresentation.color.a = 1
    .
  .
.

Just comment out the line where control.size.x =    is. This was there because of the abilityShutter we no longer use.


6. Now we change timeoutability function. We need to remove the old code for shutter and write a new one for our label.

Code: [Select]
remote function timeoutability(abilityname as String, cooldowntime as Float)
  control as NodeRef of Class GUIControl
  number as Integer
  when tolower(abilityname)
    is "weapon strike"
      // 3 seconds
      number = 1
    .
    is "fireball"
      number = 2
      // 3 seconds
    .
    is "heal"
      //15 seconds
      number = 3
    .
  .
 
  control = FindGUIControlByName(0,"game.E_AbilityBar.ButtonHolder.AbilityHolder" + number + ".Ability" + number)
  control.defaultStatePresentation.color.a = .3
  control.hoverStatePresentation.color.a = .3
  control.size.y = 87
  abilityCooldownLabel as NodeRef of Class GUILabel = FindGUIControlByName(control.parent,"abilityCooldownLabel")
  abilityCooldownLabel.visible = true
 
//  1 cooldown in seconds(Float)
//  2 ID(String), the ID of the animation
 
  animationString as String = cooldowntime
  animationString = animationString + ",cooldownLabel"
  abilityCooldownLabel.script = SYSTEM.EXEC.THISSCRIPT
  GUIAnimation:addAnimation(abilityCooldownLabel, "Cooldown", animationString)
  println("start animation")
.

We set aplha of the ability icon to a lower value so it appears darker.
We create a new NodeRef of our cooldown label and make it visible.
Our animation string consists of 2 parameters - cooldown and animation ID.
Once we have created this, we call "Cooldown" animation.


7. Now it all should be working :)
Logged

Jamielea

  • General Accounts
  • *
  • Posts: 11
    • View Profile
Re: Simple ability cooldown display
« Reply #2 on: Jan 11, 12, 03:52:33 PM »

This is really kool. I am tr5ying to put this in but I get 1 error message. I think when I can find out how to fix this error (I am new to this engine so will take me a month or so to get the hang of it) it should be working.

I am getting an erro on this line:

Code: [Select]
abilityCooldownLabel as NodeRef of Class GUILabel = FindGUIControlByName(control.parent,"abilityCooldownLabel")
  abilityCooldownLabel.visible = true

Any thoughts as to why I am getting this mate?

Thanks,
J
Logged

LastJudge

  • General Accounts
  • *
  • Posts: 215
    • View Profile
Re: Simple ability cooldown display
« Reply #3 on: Jan 11, 12, 04:24:08 PM »

If you could write your error message here, it would help :)
Logged

Jamielea

  • General Accounts
  • *
  • Posts: 11
    • View Profile
Re: Simple ability cooldown display
« Reply #4 on: Jan 11, 12, 04:27:03 PM »

Oh never mind haha. I restarted HeroBlade and it worked. This is bloody awesome mate well done.
Logged

LastJudge

  • General Accounts
  • *
  • Posts: 215
    • View Profile
Re: Simple ability cooldown display
« Reply #5 on: Jan 11, 12, 05:42:38 PM »

Oh never mind haha. I restarted HeroBlade and it worked. This is bloody awesome mate well done.

Thanks ;)
Logged

piluve

  • Developer
  • *
  • Posts: 25
  • Spain Development
    • View Profile
Re: Simple ability cooldown display
« Reply #6 on: Jan 12, 12, 02:55:32 PM »

Really good tutorial!!!

Can you make a tutorial related with casters?

See you!
Logged

LastJudge

  • General Accounts
  • *
  • Posts: 215
    • View Profile
Re: Simple ability cooldown display
« Reply #7 on: Jan 12, 12, 04:09:01 PM »

Really good tutorial!!!

Can you make a tutorial related with casters?

See you!

Thanks. I'm glad you like it.

What do you mean by casters? Maybe give me an example or some nice explanation.

I will make more tutorials once I "fix" my world. For last two or three days I've been changing everything beginning with E_ prefix to my own prefix and also making some adjustments to characters that are specific for my game. So once I finish recreating every E_ class, field and changing the scripts and glom some of them somewhere, I will try to make another tutorial ... right now I can't even create a new character and even if I logged something in I wouldn't be able to move or do anything meaningful. :D

In the meantime, you can give me some ideas for future tutorials (try to keep it simple though, I'm still quite new to the engine, so I can't do any miracles yet :D) and I'll see if they are useful to me and eventually make some more tutorials from them. :)
Logged

JoshHalls

  • Founding Professional
  • *****
  • Posts: 335
    • View Profile
    • The Repopulation
Re: Simple ability cooldown display
« Reply #8 on: Jan 12, 12, 08:21:17 PM »

One thing that HJ did that I liked is they had a simple texture they cut into little pieces that they used to do a clock like effect with a texture over the icon to show how much time remains. 
Logged
Co-Owner/Programmer - The Repopulation

LastJudge

  • General Accounts
  • *
  • Posts: 215
    • View Profile
Re: Simple ability cooldown display
« Reply #9 on: Jan 13, 12, 01:53:32 AM »

One thing that HJ did that I liked is they had a simple texture they cut into little pieces that they used to do a clock like effect with a texture over the icon to show how much time remains. 

Yeah, I was thinking of adding that, I just didn't take a look at the way they did it yet so I'm not sure how to do it. I'd probably go with creating frames of the animation and then just changing texture's coordinates from one frame to another. I'll take a look at their solution today maybe :)
Logged

FI-ScottZ

  • General Accounts
  • *
  • Posts: 1407
    • View Profile
    • Forever Interactive, Inc.
Re: Simple ability cooldown display
« Reply #10 on: Jan 13, 12, 10:21:28 AM »

There is a GUIA script for playing frames of animation that does just that, changes texture coordinates on a timer.  I don't recall if it was fully implemented in the Clean Engine distribution, but you can at least copy it from HJ Ref scripts.
Logged
Scott Zarnke
Lead Programmer, Visions of Zosimos
CTO, Forever Interactive, Inc.

piluve

  • Developer
  • *
  • Posts: 25
  • Spain Development
    • View Profile
Re: Simple ability cooldown display
« Reply #11 on: Jan 13, 12, 10:35:24 AM »

Really good tutorial!!!

Can you make a tutorial related with casters?

See you!

Thanks. I'm glad you like it.

What do you mean by casters? Maybe give me an example or some nice explanation.

I will make more tutorials once I "fix" my world. For last two or three days I've been changing everything beginning with E_ prefix to my own prefix and also making some adjustments to characters that are specific for my game. So once I finish recreating every E_ class, field and changing the scripts and glom some of them somewhere, I will try to make another tutorial ... right now I can't even create a new character and even if I logged something in I wouldn't be able to move or do anything meaningful. :D

In the meantime, you can give me some ideas for future tutorials (try to keep it simple though, I'm still quite new to the engine, so I can't do any miracles yet :D) and I'll see if they are useful to me and eventually make some more tutorials from them. :)

Haha
OK sorry , i mean for example "casting spells and mana" like World of warcraft

See you!
Logged

LastJudge

  • General Accounts
  • *
  • Posts: 215
    • View Profile
Re: Simple ability cooldown display
« Reply #12 on: Jan 13, 12, 10:40:50 AM »

Really good tutorial!!!

Can you make a tutorial related with casters?

See you!

Thanks. I'm glad you like it.

What do you mean by casters? Maybe give me an example or some nice explanation.

I will make more tutorials once I "fix" my world. For last two or three days I've been changing everything beginning with E_ prefix to my own prefix and also making some adjustments to characters that are specific for my game. So once I finish recreating every E_ class, field and changing the scripts and glom some of them somewhere, I will try to make another tutorial ... right now I can't even create a new character and even if I logged something in I wouldn't be able to move or do anything meaningful. :D

In the meantime, you can give me some ideas for future tutorials (try to keep it simple though, I'm still quite new to the engine, so I can't do any miracles yet :D) and I'll see if they are useful to me and eventually make some more tutorials from them. :)

Haha
OK sorry , i mean for example "casting spells and mana" like World of warcraft

See you!

Sure, I can make an example for that (my game actually used multiple resources to cast spells).

You only need to add GetManaCost() function to all your abilities and make it return an integer (I doubt you want mana cost with decimal numbers). When the spell cast is called, you just check if the caster has enough mana and if yes, you allow him to cast, if not, you print an error message saying "not enough mana". Also you need to make 2 new fields, one for mana and one for mana regeneration ... I'll try to make a nice example of such system somewhere during the next week ;)
Logged

piluve

  • Developer
  • *
  • Posts: 25
  • Spain Development
    • View Profile
Re: Simple ability cooldown display
« Reply #13 on: Jan 13, 12, 12:23:59 PM »

Ok im waiting for it   ;D ;D ;D ;D

See you!

Logged

runningbird

  • General Accounts
  • *
  • Posts: 37
    • View Profile
    • Runningbird Studios
Re: Simple ability cooldown display
« Reply #14 on: Jan 14, 12, 11:54:54 AM »

LastJudge...can't wait to see the next example!

Keep up the great work!
Logged
Pages: [1] 2