• 🏆 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] Dummy Unit Can't Cast Spell

Status
Not open for further replies.
Level 2
Joined
Nov 28, 2019
Messages
3
So I'm trying to make a spell for the Admiral Proudmoore model (the flavor being ships) with a "Call Battleship" ability that causes an off-screen "battleship" to shoot the target and stun it.
However the dummy unit I'm using doesn't cast the spell properly.
I'm currently using GUI, obviously proper code would be ideal but I'm still familiarizing myself with how everything works and GUI is easier atm.

Anyway here is the 'code':

Call Battleship
Events
Unit - A unit Starts the effect of an ability
Conditions
(Ability being cast) Equal to Call Battleship (dummy)
Actions
Unit - Create 1 Dummy for (Owner of (Casting unit)) at ((Center of (Playable map area)) offset by (0.00, 0.00)) facing Default building facing degrees
Unit - Add Call Battleship (real) to (Last created unit)
Unit - Set level of Call Battleship (real) for (Last created unit) to (Level of Call Battleship (dummy) for (Casting unit))
Unit - Order (Last created unit) to Human Mountain King - Storm Bolt (Target unit of ability being cast)
Wait 3.00 seconds
Unit - Order (Last created unit) to Human Mountain King - Storm Bolt (Target unit of ability being cast)
Wait 3.00 seconds
Unit - Order (Last created unit) to Human Mountain King - Storm Bolt (Target unit of ability being cast)
Wait 3.00 seconds
Unit - Kill (Last created unit)


Originally I thought it was doing something because the target unit was stunned indefinitely and the buff icon leveled up with the ability. However this was just because I based it off of the storm bolt ability originally. Even though I removed all effect fields and buffs it still stunned it...
It occurred to me this might a possibility while writing this and sure enough when I switched to a different spell it did nothing at all. (side note: what are good dummy spells to use that don't have weird hard coded interactions?)

If anyone could explain the obvious thing that I'm overlooking with my lack of experience that would be really appreciated.

And one more thing, is there a better way to refer to the dummy than "Last created unit"? I have a feeling this may conflict with other triggers later if left the way it is.
 
Level 24
Joined
Feb 9, 2009
Messages
1,787
Obligatory requirement when requesting aid involving triggers!

For the casual observers -and myself-:
  • Call Battleship
  • Events
  • Unit - A unit Starts the effect of an ability
  • Conditions
  • (Ability being cast) Equal to Call Battleship (dummy)
  • Actions
  • Unit - Create 1 Dummy for (Owner of (Casting unit)) at ((Center of (Playable map area)) offset by (0.00, 0.00)) facing Default building facing degrees
  • Unit - Add Call Battleship (real) to (Last created unit)
  • Unit - Set level of Call Battleship (real) for (Last created unit) to (Level of Call Battleship (dummy) for (Casting unit))
  • Unit - Order (Last created unit) to Human Mountain King - Storm Bolt (Target unit of ability being cast)
  • Wait 3.00 seconds
  • Unit - Order (Last created unit) to Human Mountain King - Storm Bolt (Target unit of ability being cast)
  • Wait 3.00 seconds
  • Unit - Order (Last created unit) to Human Mountain King - Storm Bolt (Target unit of ability being cast)
  • Wait 3.00 seconds
  • Unit - Kill (Last created unit)
On with your trigger:
Now with dummy units I find a troubleshooting list as a most efficacious when I run into troubles with the horrors of ventriloquist ... the horror...
  1. Does the ability the dummy is casting have mana?
  2. Does the casting time of your allow enough time for the dummy to cast it?
  3. Does the target field of the ability being cast by your dummy allow for dummy to target the desired unit?
  4. Is the target visible to the dummy?
 
Level 39
Joined
Feb 27, 2007
Messages
5,013
For the casual observers -and myself-:
If you 'reply' their post you will see the trigger properly formatted (hive just removes leading spaces in text):

  • Call Battleship
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
      • (Ability being cast) Equal to Call Battleship (dummy)
    • Actions
      • Unit - Create 1 Dummy for (Owner of (Casting unit)) at ((Center of (Playable map area)) offset by (0.00, 0.00)) facing Default building facing degrees
      • Unit - Add Call Battleship (real) to (Last created unit)
      • Unit - Set level of Call Battleship (real) for (Last created unit) to (Level of Call Battleship (dummy) for (Casting unit))
      • Unit - Order (Last created unit) to Human Mountain King - Storm Bolt (Target unit of ability being cast)
      • Wait 3.00 seconds
      • Unit - Order (Last created unit) to Human Mountain King - Storm Bolt (Target unit of ability being cast)
      • Wait 3.00 seconds
      • Unit - Order (Last created unit) to Human Mountain King - Storm Bolt (Target unit of ability being cast)
      • Wait 3.00 seconds
      • Unit - Kill (Last created unit)

Originally I thought it was doing something because the target unit was stunned indefinitely and the buff icon leveled up with the ability. However this was just because I based it off of the storm bolt ability originally. Even though I removed all effect fields and buffs it still stunned it...
Storm bolt stuns, that's just what it does. This is hardcoded into the game engine. If you set the stun duration to 0 it will actually stun forever; most duration fields on spells take 0 to be infinite. The shortest duration you can put in them is 0.01. Buffs are just visual and do not actually do anything in the spell, so removing them will not change the spell behavior. Additionally, many abilities apply the default buff for that ability if you remove all of them, since the game wants to use some buff and you didn't tell it which one to use.
It occurred to me this might a possibility while writing this and sure enough when I switched to a different spell it did nothing at all.
This is likely because you didn't change the order you were giving the dummy or the cast range on the spell was too short and the dummy couldn't target the right unit because it wasn't in range.
side note: what are good dummy spells to use that don't have weird hard coded interactions?
Acid Bomb.
And one more thing, is there a better way to refer to the dummy than "Last created unit"? I have a feeling this may conflict with other triggers later if left the way it is.
This is kind of the crux of the problem with this spell; last created unit does indeed get overwritten the next time any unit is created with a trigger. To get around this normally you would store the unit in a variable and then reference that unit variable instead of last created unit. However, that will make this spell only able to be cast by one unit at a time (not MUI--multi unit instanceable). If only one unit can potentially cast this at once (say there is only ever one copy of the Proudmoore unit) then this will be fine. If that is not sufficient you will have to make that global unit variable function like a local variable in the trigger. Here's a tutorial that shows you how to do that: local udg_

In general Waits are not recommended in triggers and the preferable method is using a timer. However, this will be okay here because not much is dependent on the true timing of the wait. Wait progresses even while the game is paused or lagging, Wait Game-Time only progresses while the game is actually being played. I would suggest the latter in most situations you want to use a Wait. This trigger could also be improved by incorporating a loop so it's easy to configure the number of cannon balls fired. However, the Integer A/B variables are also globals that can and will be overwritten during a wait. If you want to use a loop here you will have to use the For each integer <Variable> do (Actions) command and then locally shadow the counter variable as in the tutorial I posted above. The event response Target Unit of Ability Being Cast will also be overwritten/unusable after a wait (more on which ones are and which ones aren't usable here: Event Response Myths), and so must also be stored in a variable. Most of the time if you can use Triggering Unit instead of the other more specific response (in this case Casting Unit), you should use it because TU will never be overwritten and always works after a wait.

In general Instead of waiting again and killing the dummy you can just give it an expiration timer. Because of the wait in the loop it's not really necessary here, but keep that method in mind to avoid needing to wait after issuing a spell cast via dummy in the future. Finally, I'm not sure what's up with the location the dummy is being created at. It leaks two points (what is a memory leak? Things That Leak) and just makes a dummy at the center of the map. Where did you want the dummy to be located? Below is a trigger that fixes all of these things:

  • Call Battleship
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
      • (Ability being cast) Equal to Call Battleship (dummy)
    • Actions
      • Custom script: local unit udg_BS_Target
      • Custom script: local unit udg_BS_Dummy
      • Custom script: local integer udg_BS_Counter
      • Set TempPoint = (Center of (Playable map area))
      • Unit - Create 1 Dummy for (Owner of (Triggering unit)) at TempPoint facing Default building facing degrees
      • Set BS_Dummy = (Last created unit)
      • Set BS_Target = (Target unit of ability being cast)
      • Custom script: call RemoveLocation(udg_TempPoint)
      • Unit - Add Call Battleship (real) to BS_Dummy
      • Unit - Set level of Call Battleship (real) for BS_Dummy to (Level of Call Battleship (dummy) for (Triggering unit))
      • For each (Integer BS_Counter) from 1 to 3 do (Actions)
        • Loop - Actions
          • Unit - Order BS_Dummy to Human Mountain King - Storm Bolt BS_Target
          • Wait 3.00 seconds
      • Unit - Remove BS_Dummy
      • Set BS_Target = (No unit) //these prevent reference leaks introduced by making local handle variables
      • Set BS_Dummy = (No unit)
 
Level 2
Joined
Nov 28, 2019
Messages
3
Thank you for the thorough breakdown and links to info of all the basic concepts, it's very helpful. I think the main problem preventing it from working at all was definitely cast range so that was the obvious thing I was overlooking.
It seems strange though that GUI doesn't have a built-in function to prevent leaks. Maybe with reforged? I guess it hasn't been a priority though.
Thanks again!
 
Status
Not open for further replies.
Top