Random Spawns
#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


Messages In This Thread
Random Spawns - by Scropion - 20.08.2015, 16:40
Re: Random Spawns - by Crystallize - 20.08.2015, 17:37
Re: Random Spawns - by Scropion - 20.08.2015, 19:05
Re: Random Spawns - by Karolukas123 - 20.08.2015, 19:38
Re: Random Spawns - by LetsOWN[PL] - 20.08.2015, 20:31
Re: Random Spawns - by Scropion - 20.08.2015, 21:24
Re: Random Spawns - by Scropion - 21.08.2015, 22:00

Forum Jump:


Users browsing this thread: 2 Guest(s)