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

Random region spawning ?

Status
Not open for further replies.
Level 11
Joined
Jan 2, 2016
Messages
472
Can anyone give me an idea how i can do this?My map contains 6 players so i have 6 spawning points.Everytime the map is played the spawning points will be different.Do i need like an array:
  • Map Initialization
  • set Region[1] = 1
  • set Region[2] = 1
  • . . .
  • Unit - Enters Region
  • set Region[1] = 0
  • ...
And then check if Region[Index A] = 0 , if it is go to next region ,if it's not put it the next in line.But with the if statement it would contain many if's.Is there a simpler way for this.
Basicaly i want for every player = user and is playing to have a random region spawn every game.If i didn't explain correctly.
 
Level 11
Joined
Jan 2, 2016
Messages
472
How about this?
  • Set Region[X] = (Random integer number between 1 and X)
This can be useful.

Well yea it would go from 1 to 6.
For example
  • Map Initialization
  • Set P = (Random Integer number between 1 and 6)
  • Set Region = Region_1
  • Set Region[P+1] = Region_2
  • ...
So basically i want an array of numbers but not repeated and then add those numbers to Region.(P+1;just an example cause P can be 6 and then i would have Region[7] which doesn't exist)
EDIT : Actually is there like a continue statement like custom script..
 
Level 13
Joined
Jan 2, 2016
Messages
973
You should more likely do:
Set Region[1] = Region1
Set Region[2] = Region2
Set Region[3] = Region3
.....

Set Max = 6
Loop (Integer A from 1 to 6)
Set P = Random integer from 1 to Max
Spawn Player(Integer A) at Region
Set Region = Region[Max]
Set Max = Max - 1

Note that this Loop messes up the region variable array and you wouldn't be able to use it anymore, without re-setting its values in the end of this trigger (or in some other trigger)
 
Level 11
Joined
Jan 2, 2016
Messages
472
You should more likely do:
Set Region[1] = Region1
Set Region[2] = Region2
Set Region[3] = Region3
.....

Set Max = 6
Loop (Integer A from 1 to 6)
Set P = Random integer from 1 to Max
Spawn Player(Integer A) at Region
Set Region = Region[Max]
Set Max = Max - 1

Note that this Loop messes up the region variable array and you wouldn't be able to use it anymore, without re-setting its values in the end of this trigger (or in some other trigger)

Thanks this is probably it i'll rep+ you.Don't have my pc to try it out right now but i will soon.The spawning points are used only once so no need for re setting.
 
You should more likely do:
Set Region[1] = Region1
Set Region[2] = Region2
Set Region[3] = Region3
.....

Set Max = 6
Loop (Integer A from 1 to 6)
Set P = Random integer from 1 to Max
Spawn Player(Integer A) at Region
Set Region = Region[Max]
Set Max = Max - 1

Note that this Loop messes up the region variable array and you wouldn't be able to use it anymore, without re-setting its values in the end of this trigger (or in some other trigger)

Correct me if I am wrong, but won't this give a chance that a region will spawn more than 1 player?

I think you could just check to make sure there was no unit in the region with an integer condition.

Number of units in Region3 = 0 then Spawn.

This will require a periodic with a counter to shut it off once all units have been placed.
 
Level 13
Joined
Jan 2, 2016
Messages
973
Let me fix you, by explaining what this does step by step:
1) sets the regions ( this one is obvious)
2) choses a random number, representing a region, and spawns a player there
3) replaces the chosen region with the "last" region, and reduces the maximum amount of regions by 1

So let's say he rolls 3 out of 6. The 1-st player will spawn at region 3.
Then he rolls 3 out of 5. BUT then '3' would have the value of the previous '6', so player 2 will spawn at '6'.
Then he rolls 3 again (out of 4), The 3-rd player will spawn at '5'.

No chance for 2 players to spawn at the same spot.
However. I've noticed that so called "random" integers aren't actually random, but they follow some sequence, which is always the same in the begining of the map. This may cause players always to spawn at the same regions ( since this trigger is executed in the map initialization ).
BUT I've also noticed, that this happens when I test the map from the world editor (I always spawn at the same point), but when I test it in the game - it's more random (at least the spawning location). So perhaps this trigger will work.
 
Status
Not open for further replies.
Top