• Check out the results of the Techtree Contest #19!
  • 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.
  • Create a void inspired texture for Warcraft 3 and enter Hive's 34th Texturing Contest: Void! Click here to enter!
  • The Hive's 22nd Icon Contest: Creep Abilities is now concluded, time to vote for your favourite set of icons! Click here to vote!

Making an ability with limited casts

Status
Not open for further replies.
Level 24
Joined
Feb 28, 2007
Messages
3,478
Hello.

I am trying to make an ability which can only be cast a limited amount of times (like the Sentinel), but I've ran into problems.

First thing, to make it easy for the player to see how many casts of the ability is left, we've made separate icons with an integer on them representing just how many casts are left. To use these icons, I made one ability per icon. Object editor part done.

As for coding, when you cast the first spell, it's removed and adds the one with the "next" icon and so on until you cast the ability with a "1" on it. Because when that's cast, the spell is removed from the unit and no other is added.

This works just fine for one unit. When you've selected several units, though, and order them to cast this ability, they'll end up with different abilities because one has the one with a "2" on it, one has a "3" on it etc. This means if you select two units with a different amount of casts left, the ability won't show up in the command panel. I've tried stuff but I haven't gotten anywhere. Care to help?

Also, the spell should be point target, so basing it off of Sentinel won't work.

Thanks in advance.
 
You need to use a hashtable:
You will set the abilities, create the hashtable and, in case the bearers of the ability are preset, you will be using the unit group pick, else, the Det one trigger will check whenever such a unit enters the game to add the ability to them.
The loading part checks how many times the unit has casted the ability and accordingly switches it to the next level.
  • Melee Initialization
    • Events
      • Map initialization
    • Conditions
    • Actions
      • Custom script: set udg_Hash = InitHashtable()
      • Custom script: set bj_wantDestroyGroup = true
      • Set Abilities[1] = Reveal (3 uses left)
      • Set Abilities[2] = Reveal (2 uses left)
      • Set Abilities[3] = Reveal (1 use left)
      • Unit Group - Pick every unit in (Units of type Priest) and do (Actions)
        • Loop - Actions
          • Hashtable - Save 1 as (Key uses) of (Key (Picked unit)) in Hash
  • Det one
    • Events
      • Unit - A unit enters (Playable map area)
    • Conditions
      • (Unit-type of (Triggering unit)) Equal to Priest
    • Actions
      • Hashtable - Save 1 as (Key uses) of (Key (Triggering unit)) in Hash
  • Ability
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
      • Or - Any (Conditions) are true
        • Conditions
          • (Ability being cast) Equal to Reveal (1 use left)
          • (Ability being cast) Equal to Reveal (2 uses left)
          • (Ability being cast) Equal to Reveal (3 uses left)
    • Actions
      • Set UsesLoad = (Load (Key uses) of (Key (Triggering unit)) from Hash)
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • UsesLoad Less than 3
        • Then - Actions
          • Unit - Remove Abilities[UsesLoad] from (Triggering unit)
          • Unit - Add Abilities[(UsesLoad + 1)] to (Triggering unit)
          • Hashtable - Save (UsesLoad + 1) as (Key uses) of (Key (Triggering unit)) in Hash
        • Else - Actions
          • Unit - Remove Reveal (1 use left) from (Triggering unit)
I have made a test map as well ;]
 

Attachments

If you select a footman and a priest, you won't see either of the two's abilities, simply because they have different abilities. Same goes for your test map, if you select two priest with different variations of reveal, neither will show up.
 
With one ability per variation. Each ability has a different icon with an integer on it representing number of casts left. This didn't work however, as I said in the first post. So basically it needs to be one ability, but then we can't have different icons.
 
You could also make it really easy.
Such as:

"Event - A Unit begins casting a ability"
"Condition -
And
Ability being cast Equal to <your spell>"
AbilityInteger Less than <number>"
"Action - Set AbilityInteger Equal to (AbilityInteger + 1)"

What does this do?
Well, the event checks when a unit wants to begin casting a ability.
The ability/trigger will only start if the "AbilityInteger" is less than X.
Every time a unit cast the spell, the X will increase by 1.
In other words, if the X becomes over the maximum amount, the trigger wont start.

Might be hard to understand but I can help you more if needed.
Just send me a PM.
Thanks for reading.
 
You could also make it really easy.
Such as:

"Event - A Unit begins casting a ability"
"Condition -
And
Ability being cast Equal to <your spell>"
AbilityInteger Less than <number>"
"Action - Set AbilityInteger Equal to (AbilityInteger + 1)"

What does this do?
Well, the event checks when a unit wants to begin casting a ability.
The ability/trigger will only start if the "AbilityInteger" is less than X.
Every time a unit cast the spell, the X will increase by 1.
In other words, if the X becomes over the maximum amount, the trigger wont start.

Might be hard to understand but I can help you more if needed.
Just send me a PM.
Thanks for reading.

That trigger is pretty easy if you're not making it MUI :)
 
Status
Not open for further replies.
Back
Top