I am dicking around with a round based team gamemode and currently am trying to figure out how to spawn a model into a random location into the map at the beginning of the round. I have most of the code working successfully, but the problem is I’m using…
Target1 = (player.GetByID( 1 ):GetShootPos()) Target2 = (player.GetByID( 2 ):GetShootPos()) SpawnRandomModel(Target1 + (Vector(<randomized vector code here>) SpawnRandomModel(Target2 + (Vector(<randomized vector code here>)
…which spawns the model based randomly around the first two players to join the server.
The problem with doing the above is that if one of the first two players to join the server leaves the server, the gamemode breaks.
In the situation the following situation, player 1, 2, 3 and 4 join a server. This are going well. Player 2 leaves the server and a new player joins. The GetByID’s now look like 1,3,4,5. Because of that, (I believe due to testing, I could be wrong, I’m a 2 week lua noob), I can’t use a math.random because of the missing gap, as well as the fact that I don’t want it to choose the same number twice.
I’m seeking a more elegant solution, if possible, that spawns two models randomly in the map, (I have the randomization code all set, just need the delivery). I had thought that perhaps using the map’s spawnpoints would be a better constant to use, but I couldn’t figure out how to use Team.GetSpawnPoint without quickly getting all the Steam lua error achievements because of an insane loop I had created inadvertently.
So, ideas would be to use the players or spawnpoints. I’m not sure which other direction to go into that also wouldn’t choose the same number again. That would cause model in model again that I don’t think people would be ready for.
Any ideas are extremely welcome. Thank you everyone for reading