• 🏆 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!

[Spell] Need help making this 'when cast add/remove ability' spell

Status
Not open for further replies.
Level 4
Joined
Jan 6, 2009
Messages
100
It's called Earthslam. When the hero casts it (I've based it on the Beserk ability), he replaces his passive spell with Earthslam Passive, which lets him bash for one attack and then removes it.

Problem is, all the hero's abilities add and remove passive spells. How can I have each ability remove whatever passive he has currently and add the new one in?

+rep for anybody who helps :]
 
Last edited:
Level 7
Joined
Jul 3, 2011
Messages
251
I actually got frustrated reading the description over and over in an effort to understand what it is you're asking, as spinnaker said, please elaborate. Not entirely sure what you are asking but are you asking how to remove a passive when he casts another spell that adds a passive?
 
Level 7
Joined
Jun 14, 2009
Messages
235
I can tell what you want the ability to do... but I have no idea what the problem is...

I "think" you mean by the last part that all the spells the hero has function in the same way (Cast to get passive ability then switch back to the original), but I don't see your problem. Do you want it so that only one passive ability will be on at a time?
 
Level 4
Joined
Jan 6, 2009
Messages
100
Ok, I hope this makes it a little easier to understand.

- Hero starts the map with the ability No Passive
- Hero casts the ability Earthslam
- Hero replaces the No Passive ability with Earthslam (passive)
- (at this point, earthslam passive either goes away after 10 seconds or gets used and replaced with No Passive.)

Problem is: what if, while the hero has Earthslam (passive) he casts another spell? No Passive doesn't exist, because the hero doesn't have it. I was asking if there was a way to set the current '(passive)' spell to a variable so that could be replaced, instead of writing a whole bunch of if/then/else statements for if he has a certain (passive) or not.

I hope that makes a little more sense >.<

(Sorry to everyone who got frustrated.)
 
You can make a list of abilities, sorted out with an array'd variable:
  • Tr
  • Events
    • Map Initialization
  • Conditions
  • Actions
    • Set PassiveAbilities[1] = No Passive
    • Set PassiveAbilities[2] = Earthslam (Passive)
    • Set PassiveAbilities[3] = SomeAbility (Passive)
    • Set PassiveAbilities[4] = SomeOtherAbility (Passive)
    • Set PassiveAbilities[5] = SomeOtherAbilityOther (Passive)
    • Set MaximumIndex = 5
  • Trigger
  • Events
    • Unit - A unit starts the effect of an ability
  • Conditions
  • Actions
    • For each (Integer C) from 1 to MaximumIndex, do (Actions)
      • Loop - Actions
        • If (All conditions are true) then do (Then actions) else do (Else actions)
          • If - Conditions
            • (Level of PassiveAbilities[C] for (Triggering unit)) Greater than 0
          • Then - Actions
            • Unit - Remove PassiveAbilities[C] from (Triggering unit)
            • Skip Remaining Actions
          • Else - Actions
Using a hashtable, you can save the raw id of the passive ability to the raw id of the active ability, to add the proper one to the unit, when it casts the respective ability. Example:
Say the passive ability'd raw id is 'A001' and the active one 'A000' (= 'A001' is the Earthslam (Passive) and 'A000' the Earthslam (Active)).
  • Trigger
  • Events
    • Map Initialization
  • Conditions
  • Actions
    • -------- Initialize the hashtable, a hashtable variable named "Hash" --------
    • Custom script: set udg_Hash = InitHashtable()
    • -------- Save the passive ability's id to the active's one --------
    • Custom script: call SaveInteger (udg_Hash, 'A000', 0, 'A001')
with the trigger above:
  • Trigger2
  • Events
    • Unit - A unit starts the effect of an ability
  • Conditions
  • Actions
    • For each (Integer C) from 1 to MaximumIndex, do (Actions)
      • Loop - Actions
        • If (All conditions are true) then do (Then actions) else do (Else actions)
          • If - Conditions
            • (Level of PassiveAbilities[C] for (Triggering unit)) Greater than 0
          • Then - Actions
            • Unit - Remove PassiveAbilities[C] from (Triggering unit)
            • Custom script: set udg_LoadAbility = LoadInteger (udg_Hash, GetSpellAbilityId(), 0)
            • Custom script: call UnitAddAbility (GetTriggerUnit(), udg_LoadAbility)
            • Skip Remaining Actions
          • Else - Actions
LoadAbility, C, MaximumIndex are Integer variables.
PassiveAbilities[] is an Ability variable (Array ticked).
 
Level 33
Joined
Mar 27, 2008
Messages
8,035
Instead of removing and adding ability (which is inefficient), you can just Enable/Disable the ability, it works more nicely (but it does not support multiplayer nor multi-unit)

The good side of this action, if for instance you have a cooldown of 10 seconds for the Earthslam (Active) spell, once it is changes to Earthslam (Passive) and once you made a damage to enemy unit, the spell will of course turns back to Earthslam (Active) back, right ?
The interesting fact is, that the cooldown is conserved.

Meaning, if you have 15 seconds cooldown, and once you use it and once it turns back to its active form, the cooldown still plays its part

You can download the test map below.

Credits to Weep for GDD.
 

Attachments

  • Earthslam.w3x
    21.3 KB · Views: 38
Status
Not open for further replies.
Top