random spawn help
#1

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?
Reply
#2

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
Reply
#3

thanx thats work perfectly
Reply
#4

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
Reply
#5

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.
Reply
#6

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]);
Reply
#7

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
Reply
#8

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.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)