• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

Making an ability with limited casts

Status
Not open for further replies.
Level 24
Joined
Feb 28, 2007
Messages
3,480
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

  • Abilities' limited cast.w3x
    17.7 KB · Views: 53
Level 24
Joined
Feb 28, 2007
Messages
3,480
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.
 
Level 24
Joined
Feb 28, 2007
Messages
3,480
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.
 
Level 9
Joined
Apr 25, 2009
Messages
468
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.
 
Level 33
Joined
Mar 27, 2008
Messages
8,035
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.
Top