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

[Trigger] Defend ability issue.

Status
Not open for further replies.
Level 5
Joined
Dec 25, 2018
Messages
110
Point of my trigger is to gain armor whenever Defend is active while draining 20 mana per second but I am having some issues.


upload_2018-12-25_23-47-6.png



Problems:
upload_2018-12-25_23-50-23.png

This part is not detected, its purpose is to remove mana per second cost and armor when Stop Defending is used.


If I do this in seperate trigger then theres issues with multiple units with this spell:
upload_2018-12-25_23-51-57.png

(2.50 seconds acts as 'cooldown')


Another issue is this mana per second cost:
upload_2018-12-25_23-52-24.png

For example unit 1 uses defend and then unit 2 uses defend= unit 1 doesnt lose mana, unit 2 loses 40 mana.

I tried setting up local variables but perhaps I failed, if anyone could be so kind to help me fix this code.
Its my first trigger and I would really like to get it working...
 

Attachments

  • upload_2018-12-25_23-51-14.png
    upload_2018-12-25_23-51-14.png
    4.9 KB · Views: 19
Level 7
Joined
Apr 17, 2017
Messages
316
1- all gui variables have udg prefix in them, so what you should be doing is local unit udg_udg_Caster or change the name to Caster and type local unit udg_Caster.
2- Using waits in loops messes up everything. Also that issued order line not working because you filtered your with issued order equal to order(defend), so it only triggers when the order is defend. What you should be doing instead is moving your conditions block to if then else statements and check if order is defend or undefend.
3-You need a trigger with periodic events like every 1 second ..... so you need 2 triggers to set it's manacost and order event. But you can't use locals in another so you might have to change your local system to dynamic indexing

Here's a little demonstration:

  • Order
    • Events
      • Unit - A unit Is issued an order with no target
    • Conditions
      • (Issued order) Equal to (Order(defend))
    • Actions
      • Set Maxindex = (Maxindex + 1)
      • Set Unit[Maxindex] = (Triggering unit)
      • Unit - Add Armor to Unit[Maxindex]
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • Maxindex Equal to 1
        • Then - Actions
          • Trigger - Turn on Manacost <gen>
          • Else - Actions


  • Manacost
    • Events
      • Time - Every 1.00 seconds of game time
    • Conditions
    • Actions
      • For each (Integer CurrentIndex) from 1 to Maxindex, do (Actions)
        • Loop - Actions
          • Unit - Set mana of Unit[CurrentIndex] to ((Mana of Unit[CurrentIndex]) - 20.00)
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Mana of Unit[CurrentIndex]) Less than 20.00
            • Then - Actions
              • Unit - Remove Armor from Unit[CurrentIndex]
              • Unit - Order Unit[CurrentIndex] to Human Footman - Stop Defend
              • Set Unit[CurrentIndex] = Unit[Maxindex]
              • Set Maxindex = (Maxindex - 1)
              • Set CurrentIndex = (CurrentIndex - 1)
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • Maxindex Equal to 0
                • Then - Actions
                  • Trigger - Turn off (This trigger)
                • Else - Actions
            • Else - Actions

You might add some boolean conditions to check if a unit ordered undefend to turn off the second trigger.
 
Last edited:
Level 5
Joined
Dec 25, 2018
Messages
110
Thanks a lot, it works now. Do you have any good method to make this spell go on cooldown for 2 seconds after pressing stop defend? or is removing it and wait 2 sec only option.

Also another quick question
upload_2018-12-26_17-21-45.png

I want spell to apply permament buff to unit, when this spell is casted on another unit, buffs from previous unit dissapear. Do I have to make double array or something? Because now if hero1 uses buff on unit1 and then hero2 uses buff on unit2, buff dissapears from unit1.
I want to have scenario like this:
Red team hero uses ability on unit1, Blue team hero uses ability on unit2= unit 1 and unit 2 have buffs.
 
Last edited:
Level 7
Joined
Apr 17, 2017
Messages
316
1-Defend is hardcoded so it can't have cooldowns directly in object editor, but let me see if it can be set with new natives.
2- You don't need array of arrays as world editor doesn't support them, what you can do is in this trigger, as you wont be using any other trigger related to this, you can set local variables. like this
  • Whatever
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
      • (Ability being cast) Equal to Squire
    • Actions
      • Custom script: local unit udg_unit
      • Set unit = (Target unit of ability being cast)
      • Unit - Add Item Damage Bonus (+15) to unit
      • Unit - Add Inspire Buff to unit
      • Custom script: set udg_unit = null
 
Level 5
Joined
Dec 25, 2018
Messages
110
I used array because I want to delete buffs from the previous unit. (Point of the spell is to grant buff to one unit, if used on second unit, buffs from previous one dissapear)
Is it doable on local variables?
 
Status
Not open for further replies.
Top