• 🏆 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!
  • 🏆 Hive's 6th HD Modeling Contest: Mechanical is now open! Design and model a mechanical creature, mechanized animal, a futuristic robotic being, or anything else your imagination can tinker with! 📅 Submissions close on June 30, 2024. Don't miss this opportunity to let your creativity shine! Enter now and show us your mechanical masterpiece! 🔗 Click here to enter!

[Solved] How to make a unit cast the item which turns day into night, but the ability?

Level 22
Joined
Dec 3, 2020
Messages
529
So...
How can I trigger a unit to cast the ability of the item that turns day into night (from the night elven ancient of wonders).
But the ability itself must be a unit ability in the Object Editor like Frost Bolt on the Naga Royal Guard.
This will help me out a lot for my project "The Beginning".

Thanks in advance!
 

Uncle

Warcraft Moderator
Level 64
Joined
Aug 10, 2018
Messages
6,583
Items use Abilities basically no different from Unit/Hero abilities and should function exactly the same. That being said, I'm sure you've noticed that the Orders inside of the Trigger Editor are missing for certain abilities especially ones used by Items. You can find them here: List of Order Ids

After a little Control + Find magic I was able to find the order id for the moonstone: 852621

Now we need to use Custom Script to issue this order to our unit. Some variables make this easy to do:
  • Actions
    • Set Variable MyUnit = ...
    • Set Variable OrderId = 852621
    • Custom script: call IssueImmediateOrderById( udg_MyUnit, udg_OrderId )
MyUnit is a Unit variable. OrderId is an Integer variable.
 
Level 22
Joined
Dec 3, 2020
Messages
529
Items use Abilities basically no different from Unit/Hero abilities and should function exactly the same. That being said, I'm sure you've noticed that the Orders inside of the Trigger Editor are missing for certain abilities especially ones used by Items. You can find them here: List of Order Ids

After a little Control + Find magic I was able to find the order id for the moonstone: 852621

Now we need to use Custom Script to issue this order to our unit. Some variables make this easy to do:
  • Actions
    • Set Variable MyUnit = ...
    • Set Variable OrderId = 852621
    • Custom script: call IssueImmediateOrderById( udg_MyUnit, udg_OrderId )
MyUnit is a Unit variable. OrderId is an Integer variable.
Thank you so much sir!
This is perfect!
Very well explained 🙂
 
Level 22
Joined
Dec 3, 2020
Messages
529
Now only 1 final question...
@Uncle :
So I'm using in my current map that I'm making the footman model from johnwar who uses a magical shield with his defend ability.
I want to give him the spell damage reduction ability whenever he uses defend, so he'll now take reduced damage not only from piercing attacks but also from spells.

Then when the unit undefends I want to remove this spell damage reduction ability.

Any idea how to do this, sir?
 

Uncle

Warcraft Moderator
Level 64
Joined
Aug 10, 2018
Messages
6,583
Defend is a special case where you have to rely on Orders to detect when it's toggled on and off. All of the toggle abilities require this:
  • Untitled Trigger 001
    • Events
      • Unit - A unit Is issued an order with no target
    • Conditions
      • (Level of Defend for (Triggering unit)) Greater than 0
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Issued order) Equal to (Order(defend))
        • Then - Actions
          • Unit - Add Elune's Grace to (Triggering unit)
        • Else - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Issued order) Equal to (Order(undefend))
            • Then - Actions
              • Unit - Remove Elune's Grace from (Triggering unit)
            • Else - Actions
Normally, you would use the Events related to a unit casting an ability -> Begins/Starts/Stops casting.

You can add any abilities you want to the unit here.

Also, if you don't want an ability to be visible on the command card then you can set it's Art - Button Position - X to 0 and Art - Button Position - Y to -11 inside of the Object Editor (hold shift when opening a field to allow negative values and bypass most limits). This way you can make it seem like all of the effects are contained inside of the Defend ability rather than a bunch of different abilities all combined into one.
 

Attachments

  • Defend.w3m
    16.9 KB · Views: 2
Level 22
Joined
Dec 3, 2020
Messages
529
Woah :eek:2 !!! Thank you so much!
Good to know about the X-Y stuff.
But I plan to give them the spell damage reduction ability from the bracelet item.
It is not visible in the command card 😁!

May Elune bless you!!!

There is only 1 more thing I have to ask of you, sir...

Do you know how I can make it so when a unit dies, all of its summoned units die (or a specific unit-type of units).
I want to give the Sorceress unit the Summon Water Elemental ability for my campaign (I'm even gonna use the voice line she has for it from the beta files). But I want to make it when a sorceress dies, all of her water elementals die with her.

Thank you again sir...

PS: I've done this for the necromancers but because I gave them the carrion beetles ability which has this data to kill the summons when the caster dies.
 
Last edited:

Uncle

Warcraft Moderator
Level 64
Joined
Aug 10, 2018
Messages
6,583
There is only 1 more thing I have to ask of you, sir...
That one is slightly more advanced, but nothing too difficult:
  • SWE Cast
    • Events
      • Unit - A unit Spawns a summoned unit
    • Conditions
      • (Unit-type of (Summoning unit)) Equal to Sorceress
    • Actions
      • Set VariableSet SWE_CV = (Custom value of (Summoning unit))
      • -------- --------
      • -------- This creates a unique Unit Group that is linked to our Sorceress (only once): --------
      • Custom script: if udg_SWE_Group[udg_SWE_CV] == null then
      • Custom script: set udg_SWE_Group[udg_SWE_CV] = CreateGroup()
      • Custom script: endif
      • -------- --------
      • -------- Track the Water Elemental by adding it to the Sorceress' Unit Group: --------
      • Unit Group - Add (Summoned unit) to SWE_Group[SWE_CV]
      • -------- --------
      • -------- A minor optimization - Only check if a Sorceress dies when we know that at least 1 Water Elemental exists: --------
      • Trigger - Turn on SWE Sorc Dies <gen>
  • SWE Sorc Dies
    • Events
      • Unit - A unit Dies
    • Conditions
      • (Unit-type of (Triggering unit)) Equal to Sorceress
    • Actions
      • Set VariableSet SWE_CV = (Custom value of (Triggering unit))
      • -------- --------
      • -------- If the Sorceress has a Unit Group (meaning she's summoned at least 1 Water Ele) then proceed: --------
      • Custom script: if udg_SWE_Group[udg_SWE_CV] != null then
      • -------- --------
      • -------- Kill each unit that was being tracked inside of the Unit Group: --------
      • Unit Group - Pick every unit in SWE_Group[SWE_CV] and do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • ((Picked unit) is alive) Equal to True
            • Then - Actions
              • Unit - Kill (Picked unit)
            • Else - Actions
      • -------- --------
      • Custom script: call DestroyGroup( udg_SWE_Group[udg_SWE_CV] )
      • -------- --------
      • Custom script: endif
Variables:
SWE_CV = Integer.
SWE_Group = Unit Group (array).

This REQUIRES Bribe's Unit Indexer. It's a lightweight system that automatically assigns a unique Custom Value to each of your units. This allows us to store data to our units by taking advantage of Array variables and using the unit's Custom Value as the [index] of said Arrays. You can see this being done in my triggers with the SWE_CV and SWE_Group variables.

IMPORTANT: Since the system is managing Custom Values that means that YOU should NEVER be changing a unit's Custom Value yourself.
This means that you may need to adjust some of your existing triggers that were changing Custom Value - IF you even have any (you most likely do not). Luckily, the system gives you a far more powerful method for storing data to units which makes changing Custom Value (yourself) obsolete.
 

Attachments

  • Sorc Summon Water Ele 1.w3m
    23.5 KB · Views: 2
Last edited:
Level 22
Joined
Dec 3, 2020
Messages
529
Splendid!
Since you run the game on the latest patch, I cannot open the map(s) but it is fine, you are providing all the triggers and variable info that is needed.
I will just do the triggers step by step while looking at your example.
Thank you sir!

PS: so I also need to copy the trigger from Bribe, right? And then yours.
 
Level 22
Joined
Dec 3, 2020
Messages
529
Uncle 1 final thing (it's not trigger related).
So now the footmen indeed have spell damage reduction when using Defend but I want the AI to also use it. Which it does but only when getting attacked by piercing or magic damage (unless I'm mistaken).
If I order a footman to use it through triggers when for example an enemy unit is within 600 range (for example), will the AI keep the defend on, or will it deactivate it?
I will try to playtest it later but it would be great if you knew the answer :grin:.
 

Uncle

Warcraft Moderator
Level 64
Joined
Aug 10, 2018
Messages
6,583
Uncle 1 final thing (it's not trigger related).
So now the footmen indeed have spell damage reduction when using Defend but I want the AI to also use it. Which it does but only when getting attacked by piercing or magic damage (unless I'm mistaken).
If I order a footman to use it through triggers when for example an enemy unit is within 600 range (for example), will the AI keep the defend on, or will it deactivate it?
I will try to playtest it later but it would be great if you knew the answer :grin:.
I don't know, the AI is a mystery to me, but it's a simple enough thing to test yourself. I would maybe try something like this:
  • Defend AI Spell
    • Events
      • Unit - A unit Begins casting an ability
    • Conditions
      • (Unit-type of (Target unit of ability being cast)) Equal to Footman
      • ((Owner of (Target unit of ability being cast)) controller) Equal to Computer
    • Actions
      • Unit Group - Pick every unit in Footman_Group and do (Actions)
        • Loop - Actions
          • Unit - Order (Picked unit) to Human Footman - Defend.
Now the Footman will react to spells that target them. Note that this tells the whole Footman army to react but you may just want the specific (Target unit of ability being cast) to use Defend. In that case just drop the Unit Group action and Order that unit to Defend directly.

Footman_Group is a Unit Group variable that's meant to contain all of the Computer's footman so you can easily and efficiently reference them at any time.
  • Defend AI Add
    • Events
      • Unit - A unit Finishes training a unit
    • Conditions
      • (Trained unit-type) Equal to Footman
      • ((Owner of (Trained unit)) controller) Equal to Computer
    • Actions
      • Unit Group - Add (Trained unit) to Footman_Group
  • Defend AI Remove
    • Events
      • Unit - A unit Dies
    • Conditions
      • (Unit-type of (Triggering unit)) Equal to Footman
      • ((Owner of (Triggering unit)) controller) Equal to Computer
    • Actions
      • Unit Group - Remove (Triggering unit) from Footman_Group.
How these units get added to the Unit Group depends on your map. If you have pre-placed Footmen then you'll want to account for them as well.
 

Attachments

  • Defend AI.w3m
    17.4 KB · Views: 1
Last edited:
Level 22
Joined
Dec 3, 2020
Messages
529
Hmm interesting. I got a new idea though (based on yours) since for example I'm unsure if this will work against Carrion Swarm.
What I will do is when a footman whose owner is not a player (is a computer) will activate defend when being attacked/takes damage from an enemy.
Maybe I can even specify the unit-type of the enemy since it will be basically Mal'Ganis, the Lich heroes and perhaps the necromancers since I plan on changing their Unholy Frenzy for a new ability that basically deals some damage to the target unit.

Edit: I did what you did but will also add a trigger for when the footman takes damage. But will it use defend after taking the damage?

Edit 2: it seems to work even against carrion swarm. There were like 4 footmen and 1 of them barely took damage from the Carrion Swarm. The others were more injured but because they were fighting ghouls, abominations and skeleton archers so that's why I guess (whereas the footman I was looking at wasn't getting attacked by anything).

Very good Uncle!!! Thank you sir!
 
Last edited:
Level 22
Joined
Dec 3, 2020
Messages
529
@Uncle I need you again...
Do you know how to activate a Waygate during the game?
Like when the maps starts it will be deactivated, but when a player does something (a quest for example), it will activate (waygate 1 and 2 will activate and connect each other; regions will already exist).
 
Top