Got a problem with my Missile System :(

Status
Not open for further replies.
Level 6
Joined
Feb 16, 2014
Messages
193
I'm trying to make a missile system, everything works fine but after the very first missile that I shoot gets removed then all missiles that I try to shoot just gets removed at the very first time they spawn...
Code:
When unit uses the ability:
  • Machine Gun
    • Events
      • Unit - A unit Begins casting an ability
    • Conditions
      • (Ability being cast) Equal to Machine Gun
    • Actions
      • Set MS_Index = (MS_Index + 1)
      • Set MS_Missile_Type[MS_Index] = 1
      • Set MS_MaxTravel_Distance[MS_Index] = 3000.00
      • Set MS_ProjectileSpeed[MS_Index] = 35.00
      • Set MS_CollisionSize[MS_Index] = 10.00
      • Set MS_Shooter[MS_Index] = (Triggering unit)
      • Set MS_Damage[MS_Index] = (Random real number between 3.00 and 10.00)
      • Set MS_DamageAreaRange[MS_Index] = 10.00
      • Set MS_FlyHeight[MS_Index] = (Current flying height of (Triggering unit))
      • Set Unit_Pos = (Position of (Triggering unit))
      • Unit - Create 1 Bullet for (Owner of (Triggering unit)) at Unit_Pos facing (Facing of (Triggering unit)) degrees
      • Set MS_Missile[MS_Index] = (Last created unit)
      • Set MS_OwnerOfMissile[MS_Index] = (Owner of (Last created unit))
      • Custom script: call RemoveLocation(udg_Unit_Pos)
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • MS_Index Greater than or equal to 1
        • Then - Actions
          • Trigger - Turn on System <gen>
        • Else - Actions
The loop:(Initially turned-off)
  • System
    • Events
      • Time - Every 0.03 seconds of game time
    • Conditions
    • Actions
      • For each (Integer MS_Integer) from 1 to MS_Index, do (Actions)
        • Loop - Actions
          • Set Temp_Point[1] = (Position of MS_Missile[MS_Integer])
          • Set Temp_Point[2] = (Temp_Point[1] offset by MS_ProjectileSpeed[MS_Integer] towards (Facing of MS_Missile[MS_Integer]) degrees)
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • MS_Traveled_Distance[MS_Integer] Greater than or equal to MS_MaxTravel_Distance[MS_Integer]
            • Then - Actions
              • Unit - Cause MS_Missile[MS_Integer] to damage circular area after 0.00 seconds of radius MS_DamageAreaRange[MS_Integer] at Temp_Point[1], dealing MS_Damage[MS_Integer] damage of attack type Pierce and damage type Normal
              • Unit - Remove MS_Missile[MS_Integer] from the game
              • -------- ==========Recycle Indexes========== --------
              • Set MS_CollisionSize[MS_Integer] = MS_CollisionSize[MS_Index]
              • Set MS_Damage[MS_Integer] = MS_Damage[MS_Index]
              • Set MS_DamageAreaRange[MS_Integer] = MS_DamageAreaRange[MS_Index]
              • Set MS_FlyHeight[MS_Integer] = MS_FlyHeight[MS_Index]
              • Set MS_Traveled_Distance[MS_Integer] = MS_Traveled_Distance[MS_Index]
              • Set MS_MaxTravel_Distance[MS_Integer] = MS_MaxTravel_Distance[MS_Index]
              • Set MS_Missile[MS_Integer] = MS_Missile[MS_Index]
              • Set MS_Missile_Type[MS_Integer] = MS_Missile_Type[MS_Index]
              • Set MS_OwnerOfMissile[MS_Integer] = MS_OwnerOfMissile[MS_Index]
              • Set MS_ProjectileSpeed[MS_Integer] = MS_ProjectileSpeed[MS_Index]
              • Set MS_Shooter[MS_Integer] = MS_Shooter[MS_Index]
              • Set MS_Integer = (MS_Integer - 1)
              • Set MS_Index = (MS_Index - 1)
              • -------- ========End Recycle Indexes======== --------
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • MS_Index Less than or equal to 0
                • Then - Actions
                  • Set MS_Index = 0
                  • Set MS_Integer = 0
                  • Trigger - Turn off (This trigger)
                • Else - Actions
            • Else - Actions
              • Unit - Move MS_Missile[MS_Integer] instantly to Temp_Point[2]
              • Animation - Change MS_Missile[MS_Integer] flying height to MS_FlyHeight[MS_Integer] at 500.00
              • Set MS_Traveled_Distance[MS_Integer] = (MS_Traveled_Distance[MS_Integer] + MS_ProjectileSpeed[MS_Integer])
          • Set TempGroup = (Units within MS_CollisionSize[MS_Integer] of Temp_Point[2] matching (((((Matching unit) is A structure) Equal to False) and (((Matching unit) is Mechanical) Equal to False)) and (((((Matching unit) is Magic Immune) Equal to False) and (((Matching unit) is de
          • Unit Group - Pick every unit in (Random 1 units from TempGroup) and do (Actions)
            • Loop - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Number of units in TempGroup) Greater than 0
                • Then - Actions
                  • Unit - Cause MS_Missile[MS_Integer] to damage circular area after 0.00 seconds of radius MS_DamageAreaRange[MS_Integer] at Temp_Point[1], dealing MS_Damage[MS_Integer] damage of attack type Pierce and damage type Normal
                  • Unit - Remove MS_Missile[MS_Integer] from the game
                • Else - Actions
This problem has been bugging me for over day now :ogre_rage: Please help...
 
Level 28
Joined
Sep 26, 2009
Messages
2,545
the bug could be in the loop trigger's damage actions.
Look at the structure of your loop's iteration:
Code:
If (All conditions):
    (traveled distance check)
Then (Actions):
    remove bullet
    deindex
    decrease MS_integer
Else (Actions):
    some actions
Create group       //notice indenting here, this is not part of the ITE above!
Pick units in group
    damage picked units
    remove bullet
Now assume you have bullet[MS_integer] with MS_integer being number 10 and bullet[MS_integer] has traveled the max distance allowed.
For simplicity, let's say that the bullet[MS_integer], which is bullet[10] has red color - I'll refer to it as red bullet.

Because the red bullet has traveled max distance, it is removed from game and the game deindexes bullets. It places the last indexed bullet to the place of red bullet. In this case, the last indexed bullet has yellow color. So the yellow colored bullet is now indexed under index 10 and MS_integer is decreased.

Regardless of whether your bullet traveled max distance or not, you still check if there are any units nearby the bullet.
In this case, the red bullet is removed (replaced by yellow bullet), however you still pick units around where the red bullet was.
If there are any units, you damage them and remove bullet[MS_integer]. But notice this! Red bullet is already removed, in its place is yellow bullet and when you replaced red bullet for yellow bullet, you also decreased MS_integer. So now in the trigger you removed bullet[MS_integer] = bullet[9] which could be for example blue colorer bullet.
So basically blue bullet is removed, yet damage is dealt around where red bullet was (which could be somewhere completely different) although no damage should be dealt.

This inconsistency (and maybe some others are there) is what is most likely causing problems to you.
 
Level 6
Joined
Feb 16, 2014
Messages
193
I re-made and reworked on it and though I'm still not fully finished with it, at least it's working now :D it damages any enemy units nearby, the unit gets removed after it reached the max distance available. Here's the codes:
Making the missile:
  • Machine Gun
    • Events
      • Unit - A unit Begins casting an ability
    • Conditions
      • (Ability being cast) Equal to Machine Gun
    • Actions
      • Set Config_Damage = (Random real number between 3.00 and 10.00)
      • Set Config_DamageAreaRange = 10.00
      • Set Config_FlyHeight = (Current flying height of (Triggering unit))
      • Set Config_UnitType = Bullet
      • Set Config_MaxTravel_Distance = 3000.00
      • Set Config_Missile_Type = 1
      • Set Config_Size = 0.50
      • Set Config_FlyHeight = (Current flying height of (Triggering unit))
      • Set Config_OwnerOfMissile = (Owner of (Triggering unit))
      • Set Config_ProjectileSpeed = 35.00
      • Set Config_ProjectileAngle = (Facing of (Triggering unit))
      • Set Config_Shooter = (Triggering unit)
      • Trigger - Run AddMissile <gen> (checking conditions)
Trigger to add the missile:
  • AddMissile
    • Events
    • Conditions
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • MS_Index Equal to 0
        • Then - Actions
          • Trigger - Turn on System <gen>
        • Else - Actions
      • Set MS_Index = (MS_Index + 1)
      • Set MS_Shots = (MS_Shots + 1)
      • Set MS_Missile_Type[MS_Shots] = Config_Missile_Type
      • Set MS_Damage[MS_Shots] = Config_Damage
      • Set MS_DamageAreaRange[MS_Shots] = Config_DamageAreaRange
      • Set MS_CollisionSize[MS_Shots] = Config_CollisionSize
      • Set MS_OwnerOfMissile[MS_Shots] = Config_OwnerOfMissile
      • Set MS_Shooter[MS_Shots] = Config_Shooter
      • Set MS_ProjectileSpeed[MS_Shots] = Config_ProjectileSpeed
      • Set MS_FlyHeight[MS_Shots] = Config_FlyHeight
      • Set MS_Traveled_Distance[MS_Shots] = 0.00
      • Set MS_MaxTravel_Distance[MS_Shots] = Config_MaxTravel_Distance
      • Set Unit_Pos = (Position of MS_Shooter[MS_Shots])
      • Set MS_ModelSize[MS_Shots] = Config_Size
      • Set MS_UnitType[MS_Shots] = Config_UnitType
      • Set MS_ProjectileAngle[MS_Shots] = Config_ProjectileAngle
      • Unit - Create 1 Bullet for MS_OwnerOfMissile[MS_Shots] at Unit_Pos facing (Facing of MS_Shooter[MS_Shots]) degrees
      • Set MS_Missile[MS_Shots] = (Last created unit)
      • Animation - Change MS_Missile[MS_Shots]'s size to ((100.00 x MS_ModelSize[MS_Shots])%, (100.00 x MS_ModelSize[MS_Shots])%, (100.00 x MS_ModelSize[MS_Shots])%) of its original size
      • Animation - Change MS_Missile[MS_Shots] flying height to MS_FlyHeight[MS_Shots] at 0.00
      • Custom script: call RemoveLocation(udg_Unit_Pos)
The loop:
  • System
    • Events
      • Time - Every 0.03 seconds of game time
    • Conditions
    • Actions
      • For each (Integer MS_Integer) from 1 to MS_Shots, do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • MS_Missile[MS_Integer] Not equal to No unit
            • Then - Actions
              • Set MS_TempPoints[1] = (Position of MS_Missile[MS_Integer])
              • Set MS_TempPoints[2] = (MS_TempPoints[1] offset by MS_ProjectileSpeed[MS_Integer] towards (Facing of MS_Missile[MS_Integer]) degrees)
              • Set MS_Traveled_Distance[MS_Integer] = (MS_Traveled_Distance[MS_Integer] + MS_ProjectileSpeed[MS_Integer])
              • Unit - Move MS_Missile[MS_Integer] instantly to MS_TempPoints[2], facing MS_ProjectileAngle[MS_Integer] degrees
              • Animation - Change MS_Missile[MS_Integer] flying height to MS_FlyHeight[MS_Integer] at 0.00
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • MS_Traveled_Distance[MS_Integer] Greater than or equal to MS_MaxTravel_Distance[MS_Integer]
                • Then - Actions
                  • Unit - Cause MS_Missile[MS_Integer] to damage circular area after 0.00 seconds of radius MS_DamageAreaRange[MS_Integer] at MS_TempPoints[1], dealing MS_Damage[MS_Integer] damage of attack type Pierce and damage type Normal
                  • Unit - Remove MS_Missile[MS_Integer] from the game
                  • Set MS_Missile[MS_Integer] = No unit
                  • Set MS_Index = (MS_Index - 1)
                • Else - Actions
              • Set TempGroup = (Units within MS_DamageAreaRange[MS_Integer] of MS_TempPoints[1] matching ((((Matching unit) is A structure) Equal to False) and (((Matching unit) Not equal to MS_Missile[MS_Integer]) and (((Matching unit) belongs to an ally of MS_OwnerOfMissile[MS_Integer])
              • Unit Group - Pick every unit in TempGroup and do (Actions)
                • Loop - Actions
                  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    • If - Conditions
                      • (Number of units in TempGroup) Greater than 0
                    • Then - Actions
                      • Unit - Cause MS_Missile[MS_Integer] to damage circular area after 0.00 seconds of radius MS_DamageAreaRange[MS_Integer] at MS_TempPoints[1], dealing MS_Damage[MS_Integer] damage of attack type Pierce and damage type Normal
                      • Unit - Remove MS_Missile[MS_Integer] from the game
                      • Set MS_Missile[MS_Integer] = No unit
                      • Set MS_Index = (MS_Index - 1)
                      • Custom script: call DestroyGroup(udg_TempGroup)
                    • Else - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • MS_Index Equal to 0
                • Then - Actions
                  • Set MS_Shots = 0
                  • Trigger - Turn off (This trigger)
                • Else - Actions
              • Custom script: call RemoveLocation(udg_MS_TempPoints[1])
              • Custom script: call RemoveLocation(udg_MS_TempPoints[2])
            • Else - Actions
 
Status
Not open for further replies.
Top