How do I code this?

Status
Not open for further replies.
Level 19
Joined
Oct 7, 2014
Messages
2,209
I've made a spell where a building uses a custom Metamorphosis and when it transforms I give it a spellbook. The problem is how do I if the duration of the metamorphosis ends how do I detect the duration so I can also remove the spellbook?
 

EdgeOfChaos

E

EdgeOfChaos

A timer. When the unit uses Metamorphosis, start a Timer registered to the unit (recommend TimerUtils here) with duration equal to metamorphosis duration. After timer fires, remove the spell book.
 
Level 19
Joined
Oct 7, 2014
Messages
2,209
  • AntiMagic Tower
    • Events
      • Unit - A unit Finishes casting an ability
    • Conditions
      • (Ability being cast) Equal to Anti-Magic Mode
    • Actions
      • Set MagicMode_TowerUnit = (Casting unit)
      • Set MagicMode_ID = (Custom value of MagicMode_TowerUnit)
      • Countdown Timer - Start MagicMode_Timer[MagicMode_ID] as a One-shot timer that will expire in 60.00 seconds
      • Unit - Add Anti-Magic Tower Spell Book to MagicMode_TowerUnit
I created another trigger which fires when the Timer expires but the MagicMode_Timer doesn't show the index MagicMode_ID.
 

EdgeOfChaos

E

EdgeOfChaos

Actually on second thought, why not just add the desired ability onto the Alternate Form that you get via metamorphosis? I'm fairly sure that works, and only the alternate unit will have it.
 

EdgeOfChaos

E

EdgeOfChaos

Sorry but I'm not really understanding you. You just want the unit to get a Spell Book when he transforms, and lose it when he untransforms right? You don't need any coding to do that, look at this: (use Test Map, learn Metamorphosis on the demon hunter, and try it)
 

Attachments

  • Metamorph System.w3x
    16.1 KB · Views: 68
Level 8
Joined
Jan 28, 2016
Messages
486
To hide the spellbook, disable it for every player at map initialisation. If it's just for one player though, you can skip the player group and simply have the player action.

  • Map Init
    • Events
      • Map initialization
    • Conditions
    • Actions
      • Player Group - Pick every player in (All players) and do (Actions)
        • Loop - Actions
          • Player - Disable Spellbook for (Picked player)
That way you can add spellbook to the alternate form, as EdgeOfChaos has done in his map, without worrying about adding ot removing it! :D
 
Level 8
Joined
Jan 28, 2016
Messages
486
Right, it's a building. My bad. Yeah just tried it again and you're right it doesn't disable it like it should... that's weird. What DracoLich said about detecting the morph orders is probably the best way to go.

Edit: Did some more testing to no avail. Apparently there is a bug when disabling the spellbook ability on buildings. Actually, disabling the ability on buildings works as intended as the disable function is used in the campaigns to restrict certain upgrades or units from being used in a map. So in the case of buildings using the spellbook trick to provide an iconless passive, it complete disables it as it should (the spellbook and all its abilities). The one time Blizzard make something work and it's no good to us! :p
 
Last edited:
Level 7
Joined
Oct 19, 2015
Messages
286
You don't have to remove the ability actually, when the building morphs back it should loose the ability automatically.
 
Level 8
Joined
Jan 28, 2016
Messages
486
We need a new patch for this. :)

We could add this to the Wishlist I guess. That's unless Blizzard decided to correct the spellbook ability and make it properly disabled via triggers! :p

You don't have to remove the ability actually, when the building morphs back it should loose the ability automatically.

That does work but once you disable the spellbook, it will also disable the abilities within it. Therefore you can't add any hidden passives on buildings using the conventional method unfortunately.
 
Level 8
Joined
Jan 28, 2016
Messages
486
Anitarf suggestion will work, since the data of the unit will be reverted back to the default one.

That works but the problem is this:
I wanted to hide the abilities so I placed them in the spell book.

It seems that when you disable a spellbook on a building, it disables the book and all the abilities within it ironically. As I stated earlier, I tried a few different combinations to add a disabled spellbook onto a building but it just wouldn't work. :(
 
Level 19
Joined
Oct 7, 2014
Messages
2,209
Tested that and it works.


154463d1462443227-how-do-i-code-problem.jpg

Another problem is shown in the image. The metamorphosis progress bar doesn't show in the towers.
Also the feedback hidden in the spell works but the barrage doesn't.
 

Attachments

  • Problem.jpg
    Problem.jpg
    152.7 KB · Views: 126
Level 8
Joined
Jan 28, 2016
Messages
486
Well I'm all out of ideas; I'll look into again in the near future.

And apologies to Anitarf and Daffa, I didn't explicitly state that the problem was about add a spellbook to a building after morphing.
 
Last edited:
Level 8
Joined
Jan 28, 2016
Messages
486
I know this is a bit of a necro but I thought I'd better wrap things up here once and for all. I was convinced that adding the spellbook to a morph building didn't work for the wrong reasons, which is why I want to tie up all the loose ends here and avoid posting incorrect information. The following summary applies to all units, not just buildings.

The Issue with Morph Abilities
After numerous tests and some research, I have found the cause of the disappearing spellbook; the morph process itself.

Apparently when morphing, [POST=1155294]all abilities added via triggers are reset[/POST] unless they are given permanence using the Jass native UnitMakeAbilityPermanent . Therefore if you're adding a disabled spellbook to a unit dynamically, making it permanent will prevent this problem. The catch: the abilities inside the spellbook also have to be made permanent.

This isn't necessarily a problem; more of a nuisance. There is the possibility of avoiding this mess thanks to Ceday's post in this year-old thread: Metamorphosis and Bear Form Remove Abilities. By changing the event to Unit - A unit Finishes casting an ability and checking the unit-type of the triggering unit, you can add the disabled spellbook without worrying about permanence at all.

For those moments when there is no need to add a spellbook dynamically, adding it to the alternate unit in the object editor will also work; just make sure to disable it in the triggers! :p
 
Last edited:
Status
Not open for further replies.
Top