Random spawns problem
#1

I have made random spawns for my mission. I don't know why but all players spawn at the same position. I want to all the players have their own position. How to fix this.

pawn Код:
new Float:MissionSpawns[ ][ ] = {
{2518.4336, 2773.0366, 10.8203, 269.5839},
{2526.7207, 2773.0366, 10.8203, 270.0226},
{2535.0769, 2773.0366, 10.8203, 270.0226},
{2543.1343, 2773.0366, 10.8203, 270.0226},
{2551.4900, 2773.0366, 10.8203, 270.0226},
{2559.7664, 2773.0366, 10.8203, 270.0226},
{2568.1340, 2773.0366, 10.8203, 270.0226},
{2576.4170, 2773.0366, 10.8203, 270.0226},
{2518.2083, 2750.4985, 10.8203, 268.7066},
{2526.8198, 2750.5911, 10.8203, 270.4612},
{2535.0474, 2750.5227, 10.8203, 268.7066},
{2543.3940, 2750.4734, 10.8203, 270.0225},
{2551.6914, 2750.4685, 10.8203, 269.5838},
{2559.9236, 2750.4087, 10.8203, 269.5838},
{2568.0718, 2750.4451, 10.8203, 270.0225},
{2576.9536, 2750.3796, 10.8203, 269.5838},
{2518.6602, 2730.9292, 10.8130, 268.1190},
{2526.8027, 2730.8000, 10.8130, 273.8218},
{2535.0513, 2730.7705, 10.8203, 268.9964},
{2518.3496, 2716.4863, 10.8203, 270.6022},
{2526.4041, 2716.4065, 10.8203, 269.7249},
{2534.9697, 2716.3647, 10.8203, 269.7249}
};


SetPlayerPos(i, lmsSpawns[rand][0], lmsSpawns[rand][1],lmsSpawns[rand][2]);
SetPlayerFacingAngle(playerid, lmsSpawns[rand][3]);
Reply
#2

Well it doesn't seem that you've even set a randomized number for that variable. I also wonder why you use i in one and playerid in the other.

pawn Код:
new rand = random(sizeof(MissionSpawns));

SetPlayerPos(i, lmsSpawns[rand][0], lmsSpawns[rand][1],lmsSpawns[rand][2]);
SetPlayerFacingAngle(playerid, lmsSpawns[rand][3]);
If you showed us where you actually put this snippet of code then we could help more.
Reply
#3

Quote:
Originally Posted by JaTochNietDan
Посмотреть сообщение
Well it doesn't seem that you've even set a randomized number for that variable. I also wonder why you use i in one and playerid in the other.

pawn Код:
new rand = random(sizeof(MissionSpawns));

SetPlayerPos(i, MissionSpawns[rand][0], MissionSpawns[rand][1],MissionSpawns[rand][2]);
SetPlayerFacingAngle(playerid, lmsSpawns[rand][3]);
If you showed us where you actually put this snippet of code then we could help more.
I see have this thing, i just forgot to show it here. Still the same problem , all the player spawn a the same position.
Reply
#4

Have you tried changing the i to playerid?

pawn Код:
SetPlayerPos(playerid, lmsSpawns[rand][0], lmsSpawns[rand][1],lmsSpawns[rand][2]);
I can't help you without the context of your code.
Reply
#5

Quote:
Originally Posted by JaTochNietDan
Посмотреть сообщение
Have you tried changing the i to playerid?

pawn Код:
SetPlayerPos(playerid, lmsSpawns[rand][0], lmsSpawns[rand][1],lmsSpawns[rand][2]);
I can't help you without the context of your code.
Well actually i need it for all players.
Reply
#6

So you're using a loop to go through all players and generate a random number the size of the array for each of them and then set their position to that area in the array?

pawn Код:
new rand;

for(new i; i < MAX_PLAYERS; i++)
{
    if(!IsPlayerConnected(i)) continue;
    rand = random(sizeof(MissionSpawns));

    SetPlayerPos(i, MissionSpawns[rand][0], MissionSpawns[rand][1],MissionSpawns[rand][2]);
    SetPlayerFacingAngle(i, lmsSpawns[rand][3]);
}
Is that what you're looking for? I'm sorry I just can't offer any more advice if I don't know what context you're talking about.
Reply
#7

Quote:
Originally Posted by JaTochNietDan
Посмотреть сообщение
So you're using a loop to go through all players and generate a random number the size of the array for each of them and then set their position to that area in the array?

pawn Код:
new rand;

for(new i; i < MAX_PLAYERS; i++)
{
    if(!IsPlayerConnected(i)) continue;
    rand = random(sizeof(MissionSpawns));

    SetPlayerPos(i, MissionSpawns[rand][0], MissionSpawns[rand][1],MissionSpawns[rand][2]);
    SetPlayerFacingAngle(i, lmsSpawns[rand][3]);
}
Is that what you're looking for? I'm sorry I just can't offer any more advice if I don't know what context you're talking about.
I have the same code in my script. I have a mission script. When all players spawn in the mission they spawn only in 1 random position all. I need so all the players that will spawn have different positions from the list that i made.
Reply
#8

Are you sure the randomization is done in the loop and not outside of the loop?
Reply
#9

Quote:
Originally Posted by JaTochNietDan
Посмотреть сообщение
Are you sure the randomization is done in the loop and not outside of the loop?
everything is inside the loop exept this new rand = random(sizeof(lmsSpawns));
Reply
#10

Could you please post more code, everytime jatoch offers a solution you say its already in the code. If you post the full problem code maybe you'll get a fix faster.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)