Random Spawns - 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)
+--- Thread: Random Spawns (
/showthread.php?tid=586247)
Random Spawns -
Scropion - 20.08.2015
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
Re: Random Spawns -
Crystallize - 20.08.2015
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)
Re: Random Spawns -
Scropion - 20.08.2015
Yeah... And the code ?
Re: Random Spawns -
Karolukas123 - 20.08.2015
Код:
new Float:RandSpawn [ 7 ] [ 6 ] =
{
{CORD},
{CORD},
{CORD},
{CORD},
{CORD},
{CORD},
{CORD}
};
SetPlayerPos(playerid, RandSpawn [ pos ] [ 0 ] , RandSpawn [ pos ] [ 1 ] , RandSpawn [ pos ] [ 2 ] );
Re: Random Spawns -
LetsOWN[PL] - 20.08.2015
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.
Re: Random Spawns -
Scropion - 20.08.2015
Thanks To All For Helping
Re: Random Spawns -
Scropion - 21.08.2015
Ahhh Just Where I Put The X, Y, Z Positions Of The Cells