Trigger an unit to cast spell at point

Mr_Joke

New Member
Reaction score
1
I would like someone to help me with this trigger. It is supposed to make a computer (players 6-10) controlled unit to cast shockwave at an unit within range when it isn't moving and a small distance ahead of the unit when it's moving. The trigger works fine when the target unit is moving - it casts shockwave ahead of the unit. But it still casts the spell a small distance away when the unit is standing still (movement speed = 0).
I think the problem has to do with the movement speed condition, but I'm not sure why.

Code:
Bot attack
    Events
        Time - Every 2.00 seconds of game time
    Conditions
    Actions
        For each (Integer A) from 6 to 10, do (Actions)
            Loop - Actions
                If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    If - Conditions
                        ((Owner of PlayerUnit[(Integer A)]) controller) Equal to Computer
                    Then - Actions
                        Set BotPosition[(Integer A)] = (Position of PlayerUnit[(Integer A)])
                        Set BotGroup[(Integer A)] = (Units within 800.00 of BotPosition[(Integer A)] matching ((((Matching unit) is alive) Equal to True) and (((Matching unit) belongs to an enemy of (Owner of PlayerUnit[(Integer A)])) Equal to True)))
                        Unit Group - Pick every unit in BotGroup[(Integer A)] and do (Actions)
                            Loop - Actions
                                Set BotAttackPoint1 = (Position of (Picked unit))
                                If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                                    If - Conditions
                                        (Current movement speed of (Picked unit)) Equal to 0.00
                                    Then - Actions
                                        Unit - Order PlayerUnit[(Integer A)] to Orc Tauren Chieftain - Shockwave BotAttackPoint1
                                    Else - Actions
                                        Set BotAttackPoint2 = (BotAttackPoint1 offset by 150.00 towards (Facing of (Picked unit)) degrees)
                                        Unit - Order PlayerUnit[(Integer A)] to Orc Tauren Chieftain - Shockwave BotAttackPoint2
                                        Custom script:   call RemoveLocation(udg_BotAttackPoint2)
                                Custom script:   call RemoveLocation(udg_BotAttackPoint1)
                        Custom script:   call RemoveLocation(udg_BotPosition[GetForLoopIndexA()])
                        Custom script:   call DestroyGroup(udg_BotGroup[GetForLoopIndexA()])
                    Else - Actions

The PlayerUnit is a variable which stores the computer controlled unit.
 

Cetacean

New Member
Reaction score
2
You are correct in that the problem lies with the movement speed condition. This is because movement speed refers to the unit property value, not current velocity. It's not hard to see why the name causes confusion. :) Fortunately, you can fairly easily keep track of unit velocities with a periodic trigger that saves their locations to a hashtable.
 

Mr_Joke

New Member
Reaction score
1
Thank you. Is there a way of checking if unit is moving or not without hashtables? I just need to check if it is standing still, no velocity needed.
 

GFreak45

I didnt slap you, i high 5'd your face.
Reaction score
130
if a unit is moving its command string is move or attack-move
 

KaerfNomekop

Swim, fishies. Swim through the veil of steel.
Reaction score
613
Actually, if it's not channeling a spell, Stop or Hold Position, you can presume that it's moving. Casting a spell on a unit far away likely involves you walking there.

But ignore the unit's orders. Repeatedly save the unit's position and compare with current.
 

Mr_Joke

New Member
Reaction score
1
Thank you for the help so far. I'm very bad with hashtables. I've checked tutorials but I still don't know how to see if an unit is moving or not. Can somebody tell me what I'm doing wrong?

Code:
Untitled Trigger 001
    Events
        Time - Every 0.50 seconds of game time
    Conditions
    Actions
        Unit Group - Pick every unit in (Units in (Playable map area)) and do (Actions)
            Loop - Actions
                Hashtable - Save Handle Of(Position of (Picked unit)) as 0 of (Key (Picked unit)) in Hashtable

Code:
Untitled Trigger 002
    Events
        Time - Every 0.75 seconds of game time
    Conditions
    Actions
        Unit Group - Pick every unit in (Units in (Playable map area)) and do (Actions)
            Loop - Actions
                Hashtable - Save Handle Of(Position of (Picked unit)) as 1 of (Key (Picked unit)) in Hashtable
                If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    If - Conditions
                        ((Region centered at (Load (Key (Picked unit)) of 0 in Hashtable) with size (1.00, 1.00)) contains (Load (Key (Picked unit)) of 1 in Hashtable)) Equal to True
                    Then - Actions
                        Set Moving = False
                        Game - Display to (All players) the text: Not moving
                    Else - Actions
                        Set Moving = True
                        Game - Display to (All players) the text: Moving
                Hashtable - Clear all child hashtables of child (Key (Picked unit)) in Hashtable
 

GFreak45

I didnt slap you, i high 5'd your face.
Reaction score
130
you are using save handle of position of unit, you should be using save position of unit
and you should set it to a variable, save it, then clear it after with:
Trigger:
  • Custom Script: Callremovelocation(UDG_[Your_Variable])
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Staff online

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top