[Trigger] Missile not working?

Status
Not open for further replies.
Level 6
Joined
Feb 16, 2014
Messages
193
So i'm trying to make a missile that when you use an ability then it spawns a dummy unit(missile) and that dummy unit follows the target unit of the ability,but my problem is when i use the ability then it spawns the missile,BUT the missile just stays in the place where it spawned,how do i fix that?,and also how can i make it MUI? or is it already MUI?
  • FireMissile
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
      • (Ability being cast) Equal to Fire Missile
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • MissileMax_Index[1] Equal to 1
        • Then - Actions
          • Trigger - Turn on MoveExplode <gen>
        • Else - Actions
      • Set MissileMax_Index[1] = (MissileMax_Index[1] + 1)
      • Set MissileMax_Index[2] = (MissileMax_Index[2] + 1)
      • Set Missile_Shooter[MissileMax_Index[2]] = (Casting unit)
      • Set Missile_Target[MissileMax_Index[2]] = (Target unit of ability being cast)
      • Set Missile_Damage[MissileMax_Index[2]] = (Random real number between 300.00 and 420.00)
      • Set Missile_Loc[0] = (Position of Missile_Shooter[MissileMax_Index[2]])
      • Set Missile_Loc[1] = (Position of Missile_Target[MissileMax_Index[2]])
      • Set Missile_Angle[MissileMax_Index[2]] = (Angle from Missile_Loc[0] to Missile_Loc[1])
      • Set Missile_Active[MissileMax_Index[2]] = True
      • Unit - Create 1 Missile for (Owner of Missile_Shooter[MissileMax_Index[2]]) at (Position of Missile_Shooter[MissileMax_Index[2]]) facing Missile_Angle[MissileMax_Index[2]] degrees
      • Set Missile_Dummy[MissileMax_Index[2]] = (Last created unit)
      • Unit - Add a 2.50 second Generic expiration timer to Missile_Dummy[MissileMax_Index[2]]
      • Unit Group - Add Missile_Dummy[MissileMax_Index[2]] to MissileGroup
      • Custom script: call RemoveLocation(udg_Missile_Pos[udg_MissileMax_Index[2]])
      • Custom script: call RemoveLocation(udg_MissileTarget_Pos[udg_MissileMax_Index[2]])
When the unit fires the missile.
  • MoveExplode
    • Events
      • Time - Every 0.03 seconds of game time
    • Conditions
    • Actions
      • For each (Integer MissileMax_Index[3]) from 1 to MissileMax_Index[2], do (Actions)
        • Loop - Actions
          • Unit Group - Pick every unit in MissileGroup and do (Actions)
            • Loop - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • Missile_Active[MissileMax_Index[3]] Equal to True
                • Then - Actions
                  • Set Missile_Loc[0] = (Position of Missile_Dummy[MissileMax_Index[3]])
                  • Set Missile_Loc[1] = (Missile_Loc[0] offset by 35.00 towards Missile_Angle[MissileMax_Index[3]] degrees)
                  • Set MissileMax_Index[1] = (MissileMax_Index[1] - 1)
                  • Set MissileMax_Index[2] = (MissileMax_Index[2] - 1)
                  • Unit - Move Missile_Dummy[MissileMax_Index[3]] instantly to Missile_Loc[1], facing Missile_Angle[MissileMax_Index[3]] degrees
                • Else - Actions
      • Set Missile_Explode = (Units within 100.00 of (Position of Missile_Dummy[MissileMax_Index[3]]) matching (((Matching unit) is A flying unit) Equal to True))
      • Unit Group - Pick every unit in Missile_Explode and do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Distance between (Position of Missile_Dummy[MissileMax_Index[3]]) and (Position of (Picked unit))) Less than or equal to 100.00
            • Then - Actions
              • Unit - Add a 0.01 second Generic expiration timer to Missile_Dummy[MissileMax_Index[3]]
              • Unit - Cause Missile_Shooter[MissileMax_Index[3]] to damage (Picked unit), dealing Missile_Damage[MissileMax_Index[3]] damage of attack type Normal and damage type Normal
            • Else - Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • MissileMax_Index[1] Equal to 0
        • Then - Actions
          • Set MissileMax_Index[2] = 0
          • Trigger - Turn off (This trigger)
        • Else - Actions
      • Custom script: call RemoveLocation(udg_Missile_Loc[0])
      • Custom script: call RemoveLocation(udg_Missile_Loc[1])
To make the missile move and also make the missile explode when it comes near a unit,i also tried using SetUnitX and SetUnitY for moving the missile but it still doesn't move.
 
Level 24
Joined
Aug 1, 2013
Messages
4,658
I assume that the unit groups are not initialized.
i am not a pro in gui triggers but i assume that "add unit to group" doesnt initialize the group if it doesnt exist

but i wonder why you dont use an existing missile system for this.
what is it that the existing ones cant do what you want?
 
Level 12
Joined
Mar 24, 2011
Messages
1,082
EDIT/// Now that I took a better look at your spell... it looks like something merged from 3 different systems... working in different ways... You have a unity group, and an index, and another index... and some angles which come from nowhere...
If you attach your map, I would gladly fix it for you and comment it how it works. Another thing you can do it redesign it yourself instead of putting together different pieces of code.
//ENDEDIT


  • FireMissile
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
      • (Ability being cast) Equal to Fire Missile
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • MissileMax_Index[1] Equal to 1 //At this point MissileMax_Index is equal to 0, you need to set it before using it. So the FIRST missile will never move untill a second missile is created.
        • Then - Actions
          • Trigger - Turn on MoveExplode <gen>
        • Else - Actions
      • Set MissileMax_Index[1] = (MissileMax_Index[1] + 1) //I do not understand why you are using 2 indexes ? You need only one. Anyway Move this line above. Everything else looks fine.
      • Set MissileMax_Index[2] = (MissileMax_Index[2] + 1)
      • Set Missile_Shooter[MissileMax_Index[2]] = (Casting unit)
      • Set Missile_Target[MissileMax_Index[2]] = (Target unit of ability being cast)
      • Set Missile_Damage[MissileMax_Index[2]] = (Random real number between 300.00 and 420.00)
      • Set Missile_Loc[0] = (Position of Missile_Shooter[MissileMax_Index[2]])
      • Set Missile_Loc[1] = (Position of Missile_Target[MissileMax_Index[2]])
      • Set Missile_Angle[MissileMax_Index[2]] = (Angle from Missile_Loc[0] to Missile_Loc[1])
      • Set Missile_Active[MissileMax_Index[2]] = True
      • Unit - Create 1 Missile for (Owner of Missile_Shooter[MissileMax_Index[2]]) at (Position of Missile_Shooter[MissileMax_Index[2]]) facing Missile_Angle[MissileMax_Index[2]] degrees
      • Set Missile_Dummy[MissileMax_Index[2]] = (Last created unit)
      • Unit - Add a 2.50 second Generic expiration timer to Missile_Dummy[MissileMax_Index[2]]
      • Unit Group - Add Missile_Dummy[MissileMax_Index[2]] to MissileGroup
      • Custom script: call RemoveLocation(udg_Missile_Pos[udg_MissileMax_Index[2]])
      • Custom script: call RemoveLocation(udg_MissileTarget_Pos[udg_MissileMax_Index[2]])
Another thing... I told you to change the thing with the unit group in another thread, but you should actualy completely remove it. I did not look much into your triggers but it was so obvious that it will fail that I missed the real issues around. Edits incoming !!
 
Level 6
Joined
Feb 16, 2014
Messages
193
I'm trying to learn it,i downloaded a Homing Missile System before i started to make this and i'm looking at it and trying to figure it out,though its a bit hard :/
 
Level 12
Joined
Mar 24, 2011
Messages
1,082
Ok then,let me start from here. It is very important to make a spell/system MUI (Multy-unit instanceable) especialy when it is's effect spans over time (poisons, this missile system). Meaning, that it will not cause any bugs or so.

There are a lot of ways to do so, the most common are indexing and hashtables.
I your system you mixed indexing with a unit group, which got a bit deeper after I suggested you to change (last created unit group) to a variable.


<<Casting trigger>>
IndexVar = IndexVar +1
Set creation temp_point
Set target_unit[IndexVar]
Set target temp_point
Create Missile at creation point facing target point
Set Missile custom value = IndexVar
Add it to missile_unit_group
Clean Leaks
If indexVar=1
Start Looping trigger

<<Looping Trigger>>
Pick all units in Missile_Unit_Group
if picked unit is alive and target unit is alive do actions
ACTIONS
Set positions (Target and Missile)
Rotate picked unit (the missile) towards target position
Move picked unit towards target point by step (step is the distance traveled every X seconds)
Check if there are targets in detection range
If so deal damage, destroy missile, remove it from unit group.
clean leaks
ELSE ACTIONS
do nothing
(The following is not in else actions, obviously ?)
if unit group is empty
clean leaks
IndexVar = 0;
stop looping trigger



With Index Index Incoming

Edit// Umm... too lazy to explain, just the one with indexing uses A LOT more global variables than one with unit group, which is generally bad.
 
Last edited:
Level 6
Joined
Feb 16, 2014
Messages
193
@nedio95 YESSS!! It worked :ogre_haosis: now its MUI :D
  • FireMissile
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
      • (Ability being cast) Equal to Fire Missile
    • Actions
      • Set MissileMax_Index = (MissileMax_Index + 1)
      • Set Missile_Shooter = (Triggering unit)
      • Set Missile_Loc = (Position of (Triggering unit))
      • Set Missile_Target[MissileMax_Index] = (Target unit of ability being cast)
      • Set MissileTarget_Pos = (Position of Missile_Target[MissileMax_Index])
      • Unit - Create 1 Missile for (Owner of Missile_Shooter) at Missile_Loc facing (Facing of Missile_Shooter) degrees
      • Unit - Set the custom value of (Last created unit) to MissileMax_Index
      • Unit Group - Add (Last created unit) to MissileGroup
      • Custom script: call RemoveLocation(udg_Missile_Loc)
      • Custom script: call RemoveLocation(udg_MissileTarget_Pos)
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • MissileMax_Index Equal to 1
        • Then - Actions
          • Trigger - Turn on MoveExplode <gen>
        • Else - Actions
When a unit uses the ability.
  • MoveExplode
    • Events
      • Time - Every 0.03 seconds of game time
    • Conditions
    • Actions
      • Unit Group - Pick every unit in MissileGroup 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
              • (Missile_Target[MissileMax_Index] is alive) Equal to True
            • Then - Actions
              • Set Missile_Pos[MissileMax_Index] = (Position of (Picked unit))
              • Set Target_Loc[MissileMax_Index] = (Position of Missile_Target[MissileMax_Index])
              • Set Missile_Move_Loc = (Missile_Pos[MissileMax_Index] offset by 30.00 towards (Facing of (Picked unit)) degrees)
              • Set Missile_Dummy[MissileMax_Index] = (Picked unit)
              • Unit - Make (Picked unit) face Missile_Target[MissileMax_Index] over 0.00 seconds
              • Animation - Change (Picked unit) flying height to (Current flying height of Missile_Target[MissileMax_Index]) at 100.00
              • Custom script: call SetUnitX(GetEnumUnit(), GetLocationX(udg_Missile_Move_Loc))
              • Custom script: call SetUnitY(GetEnumUnit(), GetLocationY(udg_Missile_Move_Loc))
              • Set Missile_Explode = (Units within 100.00 of Missile_Pos[MissileMax_Index] matching (((Matching unit) is A flying unit) Equal to True))
              • Custom script: call RemoveLocation(udg_Missile_Pos[udg_MissileMax_Index])
              • Custom script: call RemoveLocation(udg_Target_Loc[udg_MissileMax_Index])
              • Custom script: call RemoveLocation(udg_Missile_Move_Loc)
              • Set Missile_Explode = (Units within 100.00 of (Position of Missile_Dummy[MissileMax_Index]) matching (((Matching unit) is A flying unit) Equal to True))
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Integer((Distance between Missile_Pos[MissileMax_Index] and Target_Loc[MissileMax_Index]))) Equal to 100
                • Then - Actions
                  • Unit - Cause Missile_Shooter to damage Missile_Target[MissileMax_Index], dealing (Random real number between 300.00 and 420.00) damage of attack type Siege and damage type Normal
                  • Unit - Add a 0.01 second Generic expiration timer to (Picked unit)
                  • Unit Group - Remove (Picked unit) from MissileGroup
                • Else - Actions
            • Else - Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (MissileGroup is empty) Equal to True
        • Then - Actions
          • Set MissileMax_Index = 0
          • Custom script: call DestroyGroup(udg_MissileGroup)
          • Trigger - Turn off (This trigger)
        • Else - Actions
The movement,though i don't get it why isn't the missile causing damage to the target unit? the missiles just circle around the target unit,the missiles doesn't get removed nor do they do damage,why is it like that?
 
Level 6
Joined
Feb 16, 2014
Messages
193
" (Integer((Distance between Missile_Pos[MissileMax_Index] and Target_Loc[MissileMax_Index]))) Equal to 100"
Because you check if the distance = 100, set it less than or equal to 100.
Yeah the was one of my two problems,apparently also the
  • Custom script: call DestroyGroup(udg_MissileGroup)
was causing problems i removed it and now its working, heres the full code:
  • FireMissile
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
      • (Ability being cast) Equal to Fire Missile
    • Actions
      • Set MissileMax_Index = (MissileMax_Index + 1)
      • Set Missile_Shooter = (Triggering unit)
      • Set Missile_Loc = (Position of (Triggering unit))
      • Set Missile_Target[MissileMax_Index] = (Target unit of ability being cast)
      • Set MissileTarget_Pos = (Position of Missile_Target[MissileMax_Index])
      • Unit - Create 1 Missile for (Owner of Missile_Shooter) at Missile_Loc facing (Facing of Missile_Shooter) degrees
      • Unit - Set the custom value of (Last created unit) to MissileMax_Index
      • Unit Group - Add (Last created unit) to MissileGroup
      • Unit - Add a 2.00 second Generic expiration timer to (Last created unit)
      • Set Missile_Dummy[MissileMax_Index] = (Last created unit)
      • Custom script: call RemoveLocation(udg_Missile_Loc)
      • Custom script: call RemoveLocation(udg_MissileTarget_Pos)
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • MissileMax_Index Equal to 1
        • Then - Actions
          • Trigger - Turn on MoveExplode <gen>
        • Else - Actions
  • MoveExplode
    • Events
      • Time - Every 0.03 seconds of game time
    • Conditions
    • Actions
      • Unit Group - Pick every unit in MissileGroup and do (Actions)
        • Loop - Actions
          • Set Missile_Pos[MissileMax_Index] = (Position of (Picked unit))
          • Set Target_Loc[MissileMax_Index] = (Position of Missile_Target[MissileMax_Index])
          • Set Missile_Move_Loc = (Missile_Pos[MissileMax_Index] offset by 30.00 towards (Facing of (Picked unit)) degrees)
          • Set Missile_Dummy[MissileMax_Index] = (Picked unit)
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • ((Picked unit) is alive) Equal to True
              • (Missile_Target[MissileMax_Index] is alive) Equal to True
            • Then - Actions
              • Unit - Make (Picked unit) face Missile_Target[MissileMax_Index] over 0.00 seconds
              • Animation - Change (Picked unit) flying height to (Current flying height of Missile_Target[MissileMax_Index]) at 100.00
              • Custom script: call SetUnitX(GetEnumUnit(), GetLocationX(udg_Missile_Move_Loc))
              • Custom script: call SetUnitY(GetEnumUnit(), GetLocationY(udg_Missile_Move_Loc))
            • Else - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Integer((Distance between Missile_Pos[MissileMax_Index] and Target_Loc[MissileMax_Index]))) Less than or equal to 100
            • Then - Actions
              • Unit - Cause Missile_Shooter to damage Missile_Target[MissileMax_Index], dealing (Random real number between 300.00 and 420.00) damage of attack type Siege and damage type Normal
              • Unit - Add a 0.01 second Generic expiration timer to (Picked unit)
              • Unit Group - Remove (Picked unit) from MissileGroup
            • Else - Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (MissileGroup is empty) Equal to True
        • Then - Actions
          • Set MissileMax_Index = 0
          • Trigger - Turn off (This trigger)
        • Else - Actions
      • Custom script: call RemoveLocation(udg_Missile_Pos[udg_MissileMax_Index])
      • Custom script: call RemoveLocation(udg_Target_Loc[udg_MissileMax_Index])
      • Custom script: call RemoveLocation(udg_Missile_Move_Loc)
 
Status
Not open for further replies.
Top