not so random, random spawns :)
#1

hi, i have 4 basses in my fs and i need to know if there is a way to get a player to spawn at a random base not just a random position i have looked on the wiki and i made this.
Code:
new Float:randspawn[][4]=
{
  -1631.6195,-2238.2793,31.4766,96.3710,
  -1352.3009,-2403.2361,35.4450,81.5111,
  -1418.8741,-2597.6355,68.8439,348.0974,
  -1277.3259,-2064.2441,24.0359,178.2503
};
COMMAND:rspawn(playerid,params[])
{
  new rand = random(sizeof(randspawn));
  SetPlayerPos(playerid,randspawn[rand][0],randspawn[rand][1],randspawn[rand][2]);
  SetPlayerFacingAngle(playerid,randspawn[rand][3]);
  return 1;
}
Is there a way i can get it to pick one of the sets of co-ords at random and not just completly randomise the spawn. Im fairly new to scripting so sorry if my question annoys u
Thanks in advance.
Reply
#2

I don't understand what's wrong, just put
Code:
  new rand = random(sizeof(randspawn));
  SetPlayerPos(playerid,randspawn[rand][0],randspawn[rand][1],randspawn[rand][2]);
  SetPlayerFacingAngle(playerid,randspawn[rand][3]);
  return 1;
under OnPlayerSpawn
Reply
#3

yea like a normal lvdm ?
Reply
#4

Code:
new rand = random(sizeof(randspawn));
  SetPlayerPos(playerid,randspawn[rand][0],randspawn[rand][1],randspawn[rand][2]);
  SetPlayerFacingAngle(playerid,randspawn[rand][3]);
  return 1;
If im not mistaken that will pick a random x,y,z and angle.. Thats not what i want i want it to pick one of the sets of co-ords at random i hope u get me.


Edit: i dont want it in OnPlayerSpawn its a command spawn
Reply
#5

hmm, maybe so:

new Float:randspawn[][4]=
{
{-1631.6195,-2238.2793,31.4766,96.3710},
{-1352.3009,-2403.2361,35.4450,81.5111},
{-1418.8741,-2597.6355,68.8439,348.0974},
{-1277.3259,-2064.2441,24.0359,178.2503}
};

so, there is a maximum of 4 random spawns.
Reply
#6

pawn Code:
new Float:coords[][4] =
{
{X, Y, Z, A},
{X, Y, Z, A}.
{X, Y, Z, A},
{X, Y, Z, A}
};

new rand = random(sizeof(coords));
SetPlayerPos(playerid, coords[rand][0], coords[rand][1], coords[rand][2]);
SetPlayerFacingAngle(playerid, coods[rands][3]);
Random(sizeof(coords)); will get a random slot out of sizeof coords (which is empty, so the compiler will calculate automaticly)
So if random picks 1 (out of 4) it will then store that into rand.

Then you're setting pos via coords[rand][0], so if random picks 1 and stores that into rand, rand is 1, so it's basicly saying:
coords[1][0], remember you're calling it once, not calling it when you use coords[rand][0].

Simpler:

Random picks a number out of how many sets there are, stores the number into rand, then you're using rand (which is a number).
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)