• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

Charged Ability Tutorial

Charged Ability Tutorial
By:
Radamantus

What is this?
Answer:
This is a tutorial of how to make an ability with a charge.This allows you to cast the ability many times even without cooldown but has limits and allows you to not duplicate a spell many times and use the action "Add blahblah to blahblah"
and"Set Level of blahblah to blahblah".
How can we make it?
Answer:
The ability triggers include of 4 parts:Initialization,Learn,Cast,Loop.
We will start first in Initialization

We create first the hastable,either of the two you can use:
[trigger=]
Hashtable - Create a hashtable
Set Hash = (Last Created Hashtable)[/trigger]

or

[trigger=] Custom script : set udg_Hash = InitHashtable()[/trigger]

There we have it.

Now,we will use some configuration for our spell.

We will start first with the charges color.

I will choose 4 charges as a max charge so that we could use the colors red,orange,yellow,green and if empty black.If you want other colors go here:
http://www.hiveworkshop.com/forums/...278/warcraft-iii-color-tags-linebreaks-31386/

[trigger=]
-------- GENERAL --------
-------- Determines the max charges --------
Set MaxCharges = 4
-------- Determines the color of charges --------
-------- if 0(Black) --------
Set Color[0] = |c00000000
-------- if 1(Red) --------
Set Color[1] = |c00FF0000
-------- if 2(Orange) --------
Set Color[2] = |c00FF7F00
-------- if 3(Yellow) --------
Set Color[3] = |c00FFFF00
-------- if 4(Green) --------
Set Color[4] = |c0000FF00[/trigger]

There you have it.Next we will use the Floating Text.I will use letter "I" so that we could easily see the Charges.

[trigger=]
-------- Determines the text for the charges --------
-------- if 0 --------
Set ChargeText[0] = (Color[0] + I I I I|r)
-------- if 1 --------
Set ChargeText[1] = (Color[1] + (I|r + (Color[0] + I I I|r)))
-------- if 2 --------
Set ChargeText[2] = (Color[2] + (I I|r + (Color[0] + I I|r)))
-------- if 3 --------
Set ChargeText[3] = (Color[3] + (I I I|r + (Color[0] + I|r)))
-------- if 4 --------
Set ChargeText[4] = (Color[4] + I I I I|r)[/trigger]

There,so the charges will look like this:

I I I I
I I I I
I I I I
I I I I
I I I I


After that,we will use the time to make a new charge.Lets use 5 as a cooldown.
[trigger=] Set ChargeCooldown = 5.00[/trigger]

Now,Let's Put the Starting Charge when learned and the charge number when the learner dies.

[trigger=] Set StartingCharge = 1[/trigger]

We are now finish with the Initialization,The trigger will look like this

[trigger=]Initialization
Events
Map Initialization
Conditions
Actions
Custom script : set udg_Hash = InitHashtable()
-------- GENERAL --------
-------- Determines the max charges --------
Set MaxCharges = 4
-------- Determines the color of charges --------
-------- if 0(Black) --------
Set Color[0] = |c00000000
-------- if 1(Red) --------
Set Color[1] = |c00FF0000
-------- if 2(Orange) --------
Set Color[2] = |c00FF7F00
-------- if 3(Yellow) --------
Set Color[3] = |c00FFFF00
-------- if 4(Green) --------
Set Color[4] = |c0000FF00
-------- Determines the text for the charges --------
-------- if 0 --------
Set ChargeText[0] = (Color[0] + I I I I|r)
-------- if 1 --------
Set ChargeText[1] = (Color[1] + (I|r + (Color[0] + I I I|r)))
-------- if 2 --------
Set ChargeText[2] = (Color[2] + (I I|r + (Color[0] + I I|r)))
-------- if 3 --------
Set ChargeText[3] = (Color[3] + (I I I|r + (Color[0] + I|r)))
-------- if 4 --------
Set ChargeText[4] = (Color[4] + I I I I|r)
-------- Determines the charge cooldown --------
Set ChargeCooldown = 5.00
-------- Determines the starting charge --------
Set StartingCharge = 1[/trigger]

Now let's conclude with the Learn Trigger.This is the shortest trigger here.

Let's make the events and conditions.
[trigger=]Learn
Events
Unit - A unit Learns a skill
Conditions
(Learned Hero Skill) Equal to (Your Ability)[/trigger]

After that,we will put some important variables.Let's Start with the key(hashtable)

[trigger=]
Set Learner = (Learning Hero)
Custom script: set udg_LearnerKey = GetHandleId(udg_Learner)[/trigger]

Now,let's save the variables to the key.

[trigger=]
-------- Saving --------
Hashtable - Save (CurrentCharges + StartingCharge) as 0 of LearnerKey in Hash
Hashtable - Save Timer as 2 of LearnerKey in Hash[/trigger]

The timer will be used for the looping action of the cooldown.

Next,let's start the loop.

[trigger=]
-------- Starting Loops --------
Unit Group - Add Learner to LoopGroup
Trigger - Turn on Loop <gen>[/trigger]

Now we are finish with the Learn Trigger,2 more triggers to go!

Here is what the trigger will look like:

[trigger=]Learn
Events
Unit - A unit Learns a skill
Conditions
(Learned Hero Skill) Equal to (Your Ability)
Actions
Set Learner = (Learning Hero)
Custom script: set udg_LearnerKey = GetHandleId(udg_Learner)
-------- Saving --------
Hashtable - Save (CurrentCharges + StartingCharge) as 0 of LearnerKey in Hash
Hashtable - Save Timer as 2 of LearnerKey in Hash
-------- Starting Loops --------
Unit Group - Add Learner to LoopGroup
Trigger - Turn on Loop <gen>[/trigger]

Now let's start with the Loop.

So first let's start the loop event.

You could use either 0.03 or 0.04,but ill prefer 0.04.

[trigger=]Loop
Events
Time - Every 0.04 seconds of game-time[/trigger]

Now, for the actions.Let's first pick the group

[trigger=] Unit Group - Pick every unit in LoopGroup and do (Actions)
Loop - Actions[/trigger]

Now,let's load the variables,but first we will create the key.

[trigger=]
Set Picked = (Picked Unit)
Custom script : set udg_PickedKey = GetHandleId(udg_Picked)[/trigger]

Now,Loading Variables

[trigger=]
-------- Load --------
Set CurrentCharges = (Load 0 of PickedKey from Hash)
Set Timer = (Load 2 of PickedKey from Hash)[/trigger]

Let's Check if the Picked Unit is Alive,if alive then:
[trigger=]
-------- Checking --------
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
(Picked is alive) Equal To True
Then - Actions[/trigger]

Now,let's put the actions for the Then Actions.We will start first with the floating text

[trigger=]
Then - Actions
-------- Destroying the currently created floating text --------
-------- (That means in the last loop) --------
Floating Text - Destroy (Load (Key FTXT) of PickedKey in HashIf the label is not found, this function returns NULL.)
-------- Creating Floating Text --------
Floating Text - Create floating text that reads ChargeText[CurrentCharges] above Picked with Z offset 0.00, using font size 15.00, color (100.00%, 100.00%, 100.00%), and 0.00% transparency
-------- Saving the Floating Text so that we could destroy it on the next Loop. --------
Hashtable - Save Handle Of(Last created floating text) as (Key FTXT) of PickedKey in Hash[/trigger]

There we have it,next we will hide the Floating Text from the Enemies so they wont know that you have any charges left.

[trigger=]
Set Enemies = (All enemies of (Owner of Picked))
-------- Hiding Floating Text --------
Floating Text - Hide (Last created floating text) for Enemies
-------- Clean Leak --------
Custom script : call DestroyForce(udg_Enemies)[/trigger]

Now,lets conclude with the charge cooldown.

[trigger=]
-------- Adding Charge --------
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
Timer Greater than or equal to ChargeCooldown
Then - Actions
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
CurrentCharges Less than MaxCharges
Then - Actions
-------- Because it is less than the max,we will add one --------
Hashtable - Save (CurrentCharges + 1) as 0 of PickedKey in Hash
Else - Actions
-------- Reset Timer --------
Hashtable - Save (Timer x 0.00) as 2 of PickedKey in Hash
Else - Actions
-------- Saving Timer --------
Hashtable - Save (Timer + 0.04) as 2 of PickedKey in Hash[/trigger]

Now,lets make the Else Actions of the Main If/Then/Else

[trigger=]
Else - Actions
-------- Destroys Floating Text --------
Floating Text - Destroy (Load (Key FTXT) of PickedKey in HashIf the label is not found, this function returns NULL.)
-------- Turns Charges to 1 --------
Hashtable - Save StartingCharge as 0 of PickedKey in Hash[/trigger]

Note:Don't Clean the child hastables or else it will bug!

End of Loop Trigger:
[trigger=]Loop
Events
Time - Every 0.04 seconds of game-time
Conditions
Actions
Unit Group - Pick every unit in LoopGroup and do (Actions)
Loop - Actions
Set Picked = (Picked Unit)
Custom script : set udg_PickedKey = GetHandleId(udg_Picked)
-------- Load --------
Set CurrentCharges = (Load 0 of PickedKey from Hash)
Set Timer = (Load 2 of PickedKey from Hash)
-------- Checking --------
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
(Picked is alive) Equal To True
Then - Actions
-------- Destroying the currently created floating text --------
-------- (That means in the last loop) --------
Floating Text - Destroy (Load (Key FTXT) of PickedKey in HashIf the label is not found, this function returns NULL.)
-------- Creating Floating Text --------
Floating Text - Create floating text that reads ChargeText[CurrentCharges] above Picked with Z offset 0.00, using font size 15.00, color (100.00%, 100.00%, 100.00%), and 0.00% transparency
-------- Saving the Floating Text so that we could destroy it on the next Loop. --------
Hashtable - Save Handle Of(Last created floating text) as (Key FTXT) of PickedKey in Hash
Set Enemies = (All enemies of (Owner of Picked))
-------- Hiding Floating Text --------
Floating Text - Hide (Last created floating text) for Enemies
-------- Clean Leak --------
Custom script : call DestroyForce(udg_Enemies)
-------- Adding Charge --------
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
Timer Greater than or equal to ChargeCooldown
Then - Actions
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
CurrentCharges Less than MaxCharges
Then - Actions
-------- Because it is less than the max,we will add one --------
Hashtable - Save (CurrentCharges + 1) as 0 of PickedKey in Hash
Else - Actions
-------- Reset Timer --------
Hashtable - Save (Timer x 0.00) as 2 of PickedKey in Hash
Else - Actions
-------- Saving Timer --------
Hashtable - Save (Timer + 0.04) as 2 of PickedKey in Hash
Else - Actions
-------- Destroys Floating Text --------
Floating Text - Destroy (Load (Key FTXT) of PickedKey in HashIf the label is not found, this function returns NULL.)
-------- Turns Charges to 1 --------
Hashtable - Save StartingCharge as 0 of PickedKey in Hash[/trigger]

Now let's Start with the Cast Trigger

First we will put the events and conditions.

[trigger=]Cast
Events
Unit - A unit Starts the effect of an ability
Conditions
(Ability being cast) Equal to (Your Ability)[/trigger]

Then The Actions of the Trigger

We will start first with loading and setting important variables.

[trigger=]
-------- Variables --------
Set Caster = (Triggering unit)
Custom script: set udg_CasterKey = GetHandleId(udg_Caster)
Set CurrentCharges = (Load 0 of CasterKey from Hash)[/trigger]

Now,let's check if the charges is not 0 or empty.

[trigger=]
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
CurrentCharges Greater than 0[/trigger]

Now for the Then Actions

[trigger=]
Then - Actions
-------- Decrease a charge --------
-------- But first we will check if the charges is greater than 0 so it wont bug --------
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
Current Charges Greater than 0
Then - Actions
Hashtable - Save (CurrentCharges - 1 ) as 0 of CasterKey in Hash
Else - Actions[/trigger]

Now for the Else Actions for the Main If/Then/Else

[trigger=]
Else - Actions
-------- Disables casting --------
Set Levels = (Level of (Your Ability) for Caster)
Unit - (Your Ability) from Caster
Unit - Add (Your Ability) to Caster
Unit - Set level of (Your Ability) for Caster to Levels
-------- Text that Indicates you have no more charges left. -------
Set Self = (Player group(Triggering Player))
Game - Display to Self the text: |cffffcc00No More Charges Left.
Custom script: call DestroyForce(udg_Self)[/trigger]

Now we are done with the Cast Trigger.

Here is the overall trigger:

[trigger=]Cast
Events
Unit - A unit Starts the effect of an ability
Conditions
(Ability being cast) Equal to (Your Ability)
Actions
-------- Variables --------
Set Caster = (Triggering unit)
Custom script: set udg_CasterKey = GetHandleId(udg_Caster)
Set CurrentCharges = (Load 0 of CasterKey from Hash)
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
CurrentCharges Greater than 0
Then - Actions
-------- Decrease a charge --------
-------- But first we will check if the charges is greater than 0 so it wont bug --------
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
Current Charges Greater than 0
Then - Actions
Hashtable - Save (CurrentCharges - 1 ) as 0 of CasterKey in Hash
Else - Actions
Else - Actions
-------- Disables casting --------
Set Levels = (Level of (Your Ability) for Caster)
Unit - (Your Ability) from Caster
Unit - Add (Your Ability) to Caster
Unit - Set level of (Your Ability) for Caster to Levels
-------- Text that Indicates you have no more charges left. -------
Set Self = (Player group(Triggering Player))
Game - Display to Self the text: |cffffcc00No More Charges Left.
Custom script: call DestroyForce(udg_Self)[/trigger]

For the Demo Map:

http://www.hiveworkshop.com/forums/spells-569/shadow-shroud-v7-219496/

Ask any questions if you wanted to.
 

Chaosy

Tutorial Reviewer
Level 40
Joined
Jun 9, 2011
Messages
13,219
Last edited:
Charged%20Spell%20GIF.jpg

Charged Spell System v.01.w3x
So here is another version. I've gone about as far as I can with this. It's not MUI and it is hard coded, but it works and it's pretty neat. If anyone wants it or has any use for it, please feel free to make it your own. Also, if anyone is serious about using it, I would be happy to make additional numbered icons. It can most likely be used to be integrated with Almia's hastable system and then it will be MUI. The only thing my system really adds is the icons and icon swapping. I just thought this might be more helpful here than in the Help Zone post.

  • Cast
    • Events
      • Unit - A unit Is issued an order with no target
    • Conditions
      • Or - Any (Conditions) are true
        • Conditions
          • (Issued order) Equal to (Order(manashieldon))
          • (Issued order) Equal to (Order(manashieldoff))
          • (Issued order) Equal to (Order(unimmolation))
    • Actions
      • Set Loc = (Position of Caster)
      • Set Angle = (Facing of Caster)
      • Animation - Play Caster's spell animation
      • Unit - Create 1 Dummy_type for Player 1 (Red) at Loc facing Angle degrees
      • Unit - Add Shockwave (Neutral Hostile) to (Last created unit)
      • Unit - Turn collision for (Last created unit) Off
      • Unit - Order (Last created unit) to Orc Tauren Chieftain - Shockwave (Loc offset by 300.00 towards Angle degrees)
      • Unit - Add a 1.00 second Generic expiration timer to (Last created unit)
      • Unit - Hide (Last created unit)
      • Custom script: call RemoveLocation(udg_Loc)
      • Countdown Timer - Start Clock as a Repeating timer that will expire in 4.00 seconds
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • Or - Any (Conditions) are true
            • Conditions
              • (Issued order) Equal to (Order(manashieldoff))
              • (Issued order) Equal to (Order(unimmolation))
        • Then - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • int Less than 3
            • Then - Actions
              • Trigger - Turn off Cast <gen>
              • Unit - Remove Ability[int] from Caster
              • Set int = (int + 1)
              • Unit - Add Ability[int] to Caster
              • Unit - Order Caster to Neutral Naga Sea Witch - Activate Mana Shield
              • Unit - Order Caster to Night Elf Demon Hunter - Activate Immolation
              • Trigger - Turn on Cast <gen>
            • Else - Actions
              • Trigger - Turn off Cast <gen>
              • Unit - Remove Ability[int] from Caster
              • Unit - Add Ability[int] to Caster
              • Set int = (int + 1)
              • Unit - Order Caster to Neutral Naga Sea Witch - Activate Mana Shield
              • Trigger - Turn on Cast <gen>
        • Else - Actions
  • Reset Charges
    • Events
      • Time - Clock expires
    • Conditions
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • int Equal to 1
        • Then - Actions
          • Countdown Timer - Start Clock as a Repeating timer that will expire in 4.00 seconds
          • Countdown Timer - Pause (Last started timer)
        • Else - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • int Equal to 4
            • Then - Actions
              • Trigger - Turn off Cast <gen>
              • Set int = (int - 1)
              • Unit - Remove Ability[int] from Caster
              • Unit - Add Ability[int] to Caster
              • Unit - Order Caster to Night Elf Demon Hunter - Activate Immolation
              • Unit - Order Caster to Neutral Naga Sea Witch - Activate Mana Shield
              • Trigger - Turn on Cast <gen>
            • Else - Actions
              • Trigger - Turn off Cast <gen>
              • Unit - Remove Ability[int] from Caster
              • Set int = (int - 1)
              • Unit - Add Ability[int] to Caster
              • Unit - Order Caster to Night Elf Demon Hunter - Activate Immolation
              • Unit - Order Caster to Neutral Naga Sea Witch - Activate Mana Shield
              • Trigger - Turn on Cast <gen>
 
Top