Randomized Spawn Location

Darkrevenger

New Member
Reaction score
1
I'm trying to create a randomized spawning system for my map, but I can't quite get it to work.

I need it to only allow the location to be used once, but I can't think of a way to randomize the location without restricting it so that players don't spawn on top of each other.

I have 20 spawn locations marked out on the map, all I need is a way to randomly move the players' heroes onto the spawn locations without the overlap.

I tried making a trigger for this already, but for some reason it seems to bug, and runs multiple times without stopping when it initializes "Backup".

In worse cases, the player's hero isn't moved at all and he ends up stuck being unable to do anything, since the camera boundaries have moved and he can't see his own hero any more.

I have included my current spawn triggers below, as follows:

Trigger:
  • Play spawn
    • Events
      • Time - Elapsed game time is 1.00 seconds
    • Conditions
    • Actions
      • Set PlaySPoint[1] = (Center of Play Spawn 01 <gen>)
      • Set PlaySPoint[2] = (Center of Play Spawn 02 <gen>)
      • Set PlaySPoint[3] = (Center of Play Spawn 03 <gen>)
      • Set PlaySPoint[4] = (Center of Play Spawn 04 <gen>)
      • Set PlaySPoint[5] = (Center of Play Spawn 05 <gen>)
      • Set PlaySPoint[6] = (Center of Play Spawn 06 <gen>)
      • Set PlaySPoint[7] = (Center of Play Spawn 07 <gen>)
      • Set PlaySPoint[8] = (Center of Play Spawn 08 <gen>)
      • Set PlaySPoint[9] = (Center of Play Spawn 09 <gen>)
      • Set PlaySPoint[10] = (Center of Play Spawn 10 <gen>)
      • Set PlaySPoint[11] = (Center of Play Spawn 11 <gen>)
      • Set PlaySPoint[12] = (Center of Play Spawn 12 <gen>)
      • Set PlaySPoint[13] = (Center of Play Spawn 13 <gen>)
      • Set PlaySPoint[14] = (Center of Play Spawn 14 <gen>)
      • Set PlaySPoint[15] = (Center of Play Spawn 15 <gen>)
      • Set PlaySPoint[16] = (Center of Play Spawn 16 <gen>)
      • Set PlaySPoint[17] = (Center of Play Spawn 17 <gen>)
      • Set PlaySPoint[18] = (Center of Play Spawn 18 <gen>)
      • Set PlaySPoint[19] = (Center of Play Spawn 19 <gen>)
      • Set PlaySPoint[20] = (Center of Play Spawn 20 <gen>)


This is my trigger for setting the variables that I use for play spawn, I don't think there's anything wrong with it but I'm including it just in case.

Trigger:
  • Spawning
    • Events
    • Conditions
    • Actions
      • For each (Integer A) from 1 to 12, do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Hero[(Integer A)] is alive) Equal to True
            • Then - Actions
              • Unit - Reset ability cooldowns for Hero[(Integer A)]
              • Unit - Set life of Hero[(Integer A)] to 100.00%
              • Unit - Set mana of Hero[(Integer A)] to 100.00%
              • Unit - Make Hero[(Integer A)] Vulnerable
              • Camera - Set the camera bounds for (Player((Integer A))) to play area <gen>
              • Set SpawnUsed[21] = (Random integer number between 1 and 20)
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • SpawnUsed[SpawnUsed[21]] Equal to 0
                • Then - Actions
                  • Unit - Move Hero[(Integer A)] instantly to PlaySPoint[SpawnUsed[21]]
                  • Set SpawnUsed[SpawnUsed[21]] = 1
                  • Camera - Pan camera for (Player((Integer A))) to PlaySPoint[SpawnUsed[21]] over 0.00 seconds
                  • Game - Display to (All players) the text: (|cffffd78a + ((Name of (Player((Integer A)))) + verified as spawning correctly via random number.))
                • Else - Actions
                  • Game - Display to (All players) the text: (|cff76581d + (Random spawn failed for + (Name of (Player((Integer A))))))
                  • Set SpawnUsed[22] = (Integer A)
                  • Trigger - Run Spawning Backup <gen> (checking conditions)
            • Else - Actions
              • Do nothing


This is the base spawning trigger that I use for randomizing the locations.

Trigger:
  • Spawning Backup
    • Events
    • Conditions
    • Actions
      • For each (Integer A) from 1 to 20, do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • SpawnUsed[(Integer A)] Equal to 0
            • Then - Actions
              • Unit - Move Hero[SpawnUsed[22]] instantly to PlaySPoint[(Integer A)]
              • Set SpawnUsed[(Integer A)] = 1
              • Game - Display to (All players) the text: (((|cffb88888 + (Name of (Player(SpawnUsed[22])))) + |r|r) + ( spawned via 1-20 at + (String((Integer A)))))
              • Skip remaining actions
            • Else - Actions
              • Do nothing


This is the backup trigger that I made. My intention is for it to run when the "randomized number" for the base spawning trigger fails, and sets it to a location that has already been used(this is checked by checking if SpawnUsed[number] is 1).

It should then spawn the hero at the lowest possible spawning location, starting from 1 and running to 20.

I don't really understand why this occasionally bugs right now, so any help would be greatly appreciated.
 

Komaqtion

You can change this now in User CP.
Reaction score
469
This is what you need:
Trigger:
  • For each (Integer A) from 1 to 12, do (Actions)
    • Loop - Actions
      • -------- Add the condition here ! --------
      • For each (Integer A) from 1 to 1, do (Actions)
        • Loop - Actions
          • Set TempInt = (Random integer number between 1 and 20)
          • Custom script: exitwhen udg_SpawnUsed[udg_TempInt] != 0
      • -------- Now, use the variable "TempInt" as the array value of the spawn point. --------
      • -------- And also, you need to set &quot;SpawnUsed[TempInt]&quot; to 1 after this <img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite8" alt=":D" title="Big Grin :D" loading="lazy" data-shortname=":D" /> --------
 
General chit-chat
Help Users

      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