20.08.2015, 20:31
Quote:
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 |
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;
}
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.