SA-MP Forums Archive
random spawn help - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: random spawn help (/showthread.php?tid=258753)



random spawn help - Tom1412 - 01.06.2011

Im working on a trucking gamemode and the spawn only goes to the cords for the skin. i know thats it ispossible but whats the code for random spawn?? so i put a set of cords down for spawn places and it randomly spawns people to them?


Re: random spawn help - Jay. - 01.06.2011

under onplayerspawn:

pawn Код:
new rand = random(3); // 3 = number of spawns you want
{
    if(rand == 0)
    {
         //setplayerpos here

    }
    if(rand == 1)
    {
         //another here

    }

}
thats one way(i think)
There are alot more, i hope you understand


Re: random spawn help - Tom1412 - 01.06.2011

thanx thats work perfectly


Re: random spawn help - Jay. - 01.06.2011

Quote:
Originally Posted by Tom1412
Посмотреть сообщение
thanx thats work perfectly
No problem Glad I helped, please feel free to post back here if you have any problems/questions, or pm me


Re: random spawn help - Ash. - 01.06.2011

I know you have already found a way to do it, but you can use an array and reduce the effort it takes to complete such a task:

Example:
pawn Код:
enum S_Info{Float:x, Float:y, Float:z, Float:rot}
new Spawn[][S_Info] ={
{x here, y here, z here, rotation here}, //1st Spawn
{x here, y here, z here, rotation here}  // 2nd Spawn etc etc
};

public OnPlayerSpawn(playerid)
{
     new rand = random(sizeof(Spawn));
     SetPlayerPos(playerid, Spawn[rand][x], Spawn[rand][y], Spawn[rand][z]);
     SetPlayerFacingAngle(playerid, Spawn[rand][rot]);
     return 1;
}
It reduces the need for if, else if, else code blocks and makes it easier to edit and add positions.


Re: random spawn help - Raimis_R - 01.06.2011

Why you creating enum?

pawn Код:
new const
    Float:PlayerSpawn[][] = {
    {...}, // 1Spawn
    {...}, // 2Spawn
    {...}  // Last spawn
};

new Rand = random(sizeof(PlayerSpawn));
SetPlayerPos(playerid, PlayerSpawn[Rand][0],PlayerSpawn[Rand][1],PlayerSpawn[Rand][2]);



Re: random spawn help - Jay. - 01.06.2011

Quote:
Originally Posted by funky1234
Посмотреть сообщение
I know you have already found a way to do it, but you can use an array and reduce the effort it takes to complete such a task:

Example:
pawn Код:
enum S_Info{Float:x, Float:y, Float:z, Float:rot}
new Spawn[][S_Info] ={
{x here, y here, z here, rotation here}, //1st Spawn
{x here, y here, z here, rotation here}  // 2nd Spawn etc etc
};

public OnPlayerSpawn(playerid)
{
     new rand = random(sizeof(Spawn));
     SetPlayerPos(playerid, Spawn[rand][x], Spawn[rand][y], Spawn[rand][z]);
     SetPlayerFacingAngle(playerid, Spawn[rand][rot]);
     return 1;
}
It reduces the need for if, else if, else code blocks and makes it easier to edit and add positions.
I find my code easier for editing, but thats me lol


Re: random spawn help - Ash. - 01.06.2011

Quote:
Originally Posted by Raimis_R
Посмотреть сообщение
Why you creating enum?

pawn Код:
new const
    Float:PlayerSpawn[][] = {
    {...}, // 1Spawn
    {...}, // 2Spawn
    {...}  // Last spawn
};

new Rand = random(sizeof(PlayerSpawn));
SetPlayerPos(playerid, PlayerSpawn[Rand][0],PlayerSpawn[Rand][1],PlayerSpawn[Rand][2]);
I don't normally use an enum for such a task, I just used it here so it would be easy to understand for the topic starter. I try and make everything I do as easy to understand as possible for the original poster.