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

[Solved] Possible loop issue

Status
Not open for further replies.
Level 9
Joined
Apr 23, 2011
Messages
527
I am making a triggered line of sight system for front-only vision by using lines of dummy units in a cone (is this the best way to go about it? it stutters when going up to 24 players)

  • losinit
    • Events
      • Time - Elapsed game time is 0.03 seconds
    • Conditions
    • Actions
      • For each (Integer loop) from 1 to 2, do (Actions)
        • Loop - Actions
          • Set playerunits = (Units owned by (Player(loop)) of type Peasant)
          • Unit Group - Pick every unit in playerunits and do (Actions)
            • Loop - Actions
              • Set unit[loop] = (Picked unit)
              • Set p[0] = (Position of unit[loop])
              • Set facing = ((Facing of unit[loop]) - 150.00)
              • For each (Integer loop2) from 1 to 7, do (Actions)
                • Loop - Actions
                  • For each (Integer loop3) from 1 to 10, do (Actions)
                    • Loop - Actions
                      • Set p[1] = (p[0] offset by (100.00 x (Real(loop3))) towards facing degrees)
                      • Unit - Create 1 Sight for (Player(loop)) at p[1] facing Default building facing degrees
                      • Set sight[sightindex[loop]] = (Last created unit)
                      • Set sightindex[loop] = (sightindex[loop] + 1)
                      • Custom script: call RemoveLocation(udg_p[1])
                  • Set facing = (facing + 30.00)
              • Custom script: call RemoveLocation(udg_p[0])
          • Custom script: call DestroyGroup(udg_playerunits)
  • losloop
    • Events
      • Time - Every 0.50 seconds of game time
    • Conditions
    • Actions
      • For each (Integer loop) from 1 to 2, do (Actions)
        • Loop - Actions
          • Set p[0] = (Position of unit[loop])
          • Set facing = ((Facing of unit[loop]) - 150.00)
          • Set sightindex[loop] = 0
          • For each (Integer loop2) from 1 to 7, do (Actions)
            • Loop - Actions
              • For each (Integer loop3) from 1 to 10, do (Actions)
                • Loop - Actions
                  • Set p[1] = (p[0] offset by (100.00 x (Real(loop3))) towards facing degrees)
                  • Unit - Move sight[sightindex[loop]] instantly to p[1]
                  • Set sightindex[loop] = (sightindex[loop] + 1)
                  • Custom script: call RemoveLocation(udg_p[1])
              • Set facing = (facing + 30.00)
          • Custom script: call RemoveLocation(udg_p[0])
My problem is that the Sight dummy units don't move. I have successfully tested if I indexed the units properly. If I set another point (p[2], not included above) at the position of the Sight dummy before I move it in the loop trigger and create a unit, the unit is created at the same point as p[1]. p[1] works as intended. I noticed the created unit in p[2] was owned by Player 2, which I don't know why it's like that.

What is the issue with how I have coded this? I am testing this on a blank map (attached below).

edit: I think I forgot to remove an unintended action in the testmap (Kill last created unit).
 

Attachments

  • lineofsight.w3x
    14.2 KB · Views: 30
Last edited:
I found out the possible issue with the script above. In the initialization script (0.03), there is the possibility of variable overriding (Start at 0, end at 70, then start at 0 again?). Simply put, it's not MUI. On the periodic trigger, it works as intended, for the most part, except the problem above persisting (Start at 0, end at 70, then start at 0 again?)

Also, there are fogmodifiers for use here, so I think this approach is quite inefficient. I mitigated the need for having to enumerate units all over and over again in the loop and just reduced it to a For Group call (in GUI) in the updated version of your test map.
 

Attachments

  • lineofsight.w3x
    15.5 KB · Views: 29
Status
Not open for further replies.
Top