Fireball Spell with casting time bar Tutorial

*This tutorial was created by scoterr on the RealmCrafter: Community Edition forums.*

To create casting time bar we will use *ProgressBar*function.

Default fireball script:

> Using "RC\_Core.rcm"
>
>
>
>
>
> Function Main()
>
>
>
>     Player = Actor()
>
>     Target = ContextActor()
>
>
>
>     ;Check if the target is correct?
>
>     If(Target = 0)
>
>         Output(Player, "Target not correct")
>
>         Return
>
>     EndIf
>
>
>
>     ;Check the mana
>
>     ManaLevel = Attribute(Player, "Mana")
>
>     If(ManaLevel < 1)
>
>         Output(Player, "Not enough Mana")
>
>         Return
>
>     EndIf
>
>         SetAttribute(Player, "Mana", ManaLevel -1)
>
>
>
>
>
>     ;Particles and casting animation
>
>     AnimateActor(Player, "Pray", 0.05, 1)
>
>     FireProjectile(Player, Target, "Fireball")
>
>
>
>     DoEvents(2000)
>
>  CreateEmitter(Target, "Waterfall", 10, 100)
>
>     hp = Attribute(Target, "Health")
>
>     damage = Rand(30,60)
>
>     SetAttribute(Target, "Health", hp-damage)
>
>
>
>    ;If (hp-Damage)<1
>
>    ;KillActor(Target, Player)
>
>    ;Endif
>
>
>
>     Return
>
>
>
>
>
>
> End Function
>
>

This part is used for firing the projectile.

> ;Particles and casting animation
>
>
>
> AnimateActor(Player, "Pray", 0.05, 1)
>
>
>
>
> FireProjectile(Player, Target, "Fireball")
>
>

We need to create casting bar before firing the particle.
Whole code for casting bar

> Casting\_Bar = CreateProgressBar(Player,255,0,0,0.01,0.48,0.2,0.04,100,0,"Casting")
>
>

> Casting\_Time = 1
>
>
>
> Repeat
>
>     Casting\_Time = Casting\_Time + 1
>
>     UpdateProgressBar(Player,Casting\_Bar,Casting\_Time)
>
>     DoEvents(25)
>
> Until Casting\_Time > 100
>
>
>
>
> DeleteProgressBar(Player,Casting\_Bar)
>
>

Creating new *ProgressBar*called *Casting\_Bar*for actor *player*, colored red, with max value of 100 and starting on 1.

> Casting\_Bar = CreateProgressBar(Player,255,0,0,0.01,0.48,0.2,0.04,100,1,"Casting")
>
>
>
>

Declaring variable for value of the *ProgressBar*

> Casting\_Time = 1
>
>
>
>

Repeat loop adding 1 to the *Casting\_Time*, updating *ProgressBar*called *Casting\_Bar*for actor *Player*with value of *Casting\_Time*, waiting 25ms and repeating everything until *Casting\_Time*(the value of our *ProgressBar*) is 100.

> Repeat
>
>
>
>     Casting\_Time = Casting\_Time + 1
>
>     UpdateProgressBar(Player,Casting\_Bar,Casting\_Time)
>
>     DoEvents(25)
>
>
>
>
> Until Casting\_Time > 100
>
>

Deleting *ProgressBar*after use

> DeleteProgressBar(Player,Casting\_Bar)
>
>
>
>

And now we can fire our projectile.
Whole script:

> Using "RC\_Core.rcm"
>
>
>
>
> Function Main()
>
>
>
>     Player = Actor()
>
>     Target = ContextActor()
>
>
>
>     ;Check if the target is correct?
>
>     If(Target = 0)
>
>         Output(Player, "Target not correct")
>
>         Return
>
>     EndIf
>
>
>
>     ;Check the mana
>
>     ManaLevel = Attribute(Player, "Mana")
>
>     If(ManaLevel < 1)
>
>         Output(Player, "Not enough Mana")
>
>         Return
>
>     EndIf
>
>         SetAttribute(Player, "Mana", ManaLevel -1)
>
>
>
>
>
>     ;Particles and casting animation
>
>     AnimateActor(Player, "Pray", 0.05, 1)
>
>     Casting\_Bar = CreateProgressBar(Player,255,0,0,0.01,0.48,0.2,0.04,100,0,"Casting")
>
>     Casting\_Time = 1
>
>     Repeat
>
>        Casting\_Time = Casting\_Time + 1
>
>        UpdateProgressBar(Player,Casting\_Bar,Casting\_Time)
>
>        DoEvents(25)
>
>     Until Casting\_Time > 100
>
>     DeleteProgressBar(Player,Casting\_Bar)
>
>     FireProjectile(Player, Target, "Fireball")
>
>
>
>     DoEvents(2000)
>
>  CreateEmitter(Target, "Waterfall", 10, 100)
>
>     hp = Attribute(Target, "Health")
>
>     damage = Rand(30,60)
>
>     SetAttribute(Target, "Health", hp-damage)
>
>
>
>    ;If (hp-Damage)<1
>
>    ;KillActor(Target, Player)
>
>    ;Endif
>
>
>
>     Return
>
>
>
> End Function
>
>
>
>
>

Have fun!