Random Spawns
#1

Hello all...
I Have A New Problem About How To Make Random Spawns For Prison Cells...
I Know How To Make Random Spawns
But How To Make That If Someone Already In A Cell And Another Player Spawn But It Don't Repeat And Spawn Him In Same Cell
I Have Like 50 Cells...
Please Help Me I Didn't Found Like This Before
And Give Me Easy Code That I Can UnderStand With Explanations
Thank You
Reply
#2

Quote:
Originally Posted by Scropion
Посмотреть сообщение
Hello all...
I Have A New Problem About How To Make Random Spawns For Prison Cells...
I Know How To Make Random Spawns
But How To Make That If Someone Already In A Cell And Another Player Spawn But It Don't Repeat And Spawn Him In Same Cell
I Have Like 50 Cells...
Please Help Me I Didn't Found Like This Before
And Give Me Easy Code That I Can UnderStand With Explanations
Thank You
Get the positions of all cells then check if a player is in cell 1 if yes continue to cell 2 and so on but careful it can go to an infinite loop (as far as I know)
Reply
#3

Yeah... And the code ?
Reply
#4

Код:
new Float:RandSpawn [ 7 ] [ 6 ] =
{
	{CORD},
	{CORD},
	{CORD},
	{CORD},
	{CORD},
	{CORD},
	{CORD}
};

SetPlayerPos(playerid, RandSpawn [ pos ] [ 0 ] , RandSpawn [ pos ] [ 1 ] , RandSpawn [ pos ] [ 2 ] );
Reply
#5

Quote:
Originally Posted by Scropion
Посмотреть сообщение
Hello all...
I Have A New Problem About How To Make Random Spawns For Prison Cells...
I Know How To Make Random Spawns
But How To Make That If Someone Already In A Cell And Another Player Spawn But It Don't Repeat And Spawn Him In Same Cell
I Have Like 50 Cells...
Please Help Me I Didn't Found Like This Before
And Give Me Easy Code That I Can UnderStand With Explanations
Thank You
It's better NOT TO try put player in cell RANDOMLY, because, let's say, You've Your 50 cells out there, which 49 of them are busy. Imagine, how much time it could take for the server to finally generate random number equal to 50. So, it is better to find next free cell in queue and put player there.
pawn Код:
#define CELL_LIMIT 50 // How many cells?
enum CellInfo {
    bool:is_busy,
    Float:pos_x, Float:pos_y, Float:pos_z
} new Cell[ CELL_LIMIT ][ CellInfo ], OccupiedCells = 0;
// .........
public OnGameModeInit() {
    for( new CellId = 0; CellId < CELL_LIMIT; CellId++ )
        Cell[ CellId ][ is_busy ] = false;
}
// .........
stock PutPlayerInCell( playerid ) { // return TRUE on success, FALSE otherwise
    if( OccupiedCells == CELL_LIMIT )
        return false; // Cannot put player in cell (all cells are busy)

    // Find next free cell
    new CellId = 0;
    while( Cell[ CellId ][ is_busy ] )
        CellId++;  

    // Mark cell as busy
    Cell[ CellId ][ is_busy ] = true;
    // Put player in that cell
    SetPlayerPos( playerid, Cell[ CellId ][ pos_x ], Cell[ CellId ][ pos_y ], Cell[ CellId ][ pos_z ]);
    return true;
}
I have NOT tested it, but it should work though, there's no much rocket science about it.
Yes, those are just basic thing, and they have lack of some security stuff, but You've to figure out some protection to it at Your own (for example figure out how to determine if player is in cell or not, ect)

Have fun with it, happy scripting.
Greetings.
Reply
#6

Thanks To All For Helping
Reply
#7

Ahhh Just Where I Put The X, Y, Z Positions Of The Cells
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)