public OnPlayerSpawn (playerid)
{
new selected_spawn = random (5);
switch (selected_spawn)
{
case 0: { SetPlayerPos (playerid, 0.0, 0.0, 0.0); SetPlayerFacingAngle (playerid, 0.0); }
case 1: { SetPlayerPos (playerid, 10.0, 10.0, 10.0); SetPlayerFacingAngle (playerid, 10.0); }
case 2: { SetPlayerPos (playerid, 20.0, 20.0, 20.0); SetPlayerFacingAngle (playerid, 20.0); }
case 3: { SetPlayerPos (playerid, 30.0, 30.0, 30.0); SetPlayerFacingAngle (playerid, 30.0); }
case 4: { SetPlayerPos (playerid, 40.0, 40.0, 40.0); SetPlayerFacingAngle (playerid, 40.0); }
}
return 1;
}
new selected_spawn = random (5);
switch (selected_spawn) { }
switch (selected_spawn)
{
case 0: { SetPlayerPos (playerid, 0.0, 0.0, 0.0); SetPlayerFacingAngle (playerid, 0.0); }
case 1: { SetPlayerPos (playerid, 10.0, 10.0, 10.0); SetPlayerFacingAngle (playerid, 10.0); }
case 2: { SetPlayerPos (playerid, 20.0, 20.0, 20.0); SetPlayerFacingAngle (playerid, 20.0); }
case 3: { SetPlayerPos (playerid, 30.0, 30.0, 30.0); SetPlayerFacingAngle (playerid, 30.0); }
case 4: { SetPlayerPos (playerid, 40.0, 40.0, 40.0); SetPlayerFacingAngle (playerid, 40.0); }
}
public OnPlayerSpawn (playerid)
{
SetRandomPosition (playerid); // You can use this multiple times in other parts of code too.
return 1;
}
stock SetRandomPosition (playerid)
{
new selected_spawn = random (5);
switch (selected_spawn)
{
case 0: { SetPlayerPos (playerid, 0.0, 0.0, 0.0); SetPlayerFacingAngle (playerid, 0.0); }
case 1: { SetPlayerPos (playerid, 10.0, 10.0, 10.0); SetPlayerFacingAngle (playerid, 10.0); }
case 2: { SetPlayerPos (playerid, 20.0, 20.0, 20.0); SetPlayerFacingAngle (playerid, 20.0); }
case 3: { SetPlayerPos (playerid, 30.0, 30.0, 30.0); SetPlayerFacingAngle (playerid, 30.0); }
case 4: { SetPlayerPos (playerid, 40.0, 40.0, 40.0); SetPlayerFacingAngle (playerid, 40.0); }
}
return 1;
}
|
Why not store the positions and looking angles in an array and set spawns based on the array index. It's easier to add positions because you don't need a switch/case, so you don't have to repeat the same code over and over to add more spawn positions.
|
There are alot of beginners who are unable to understand the concept of multi-dimensional arrays so in this tutorial i will show them how to make a random spawn system and similar stuff without using the arrays. Since the array method is explained in the wiki, i'll be explaining the second one.
|
Thanks for the response, this tutorial was for the beginners as i said in the above introduction (please read that).
Code:
There are alot of beginners who are unable to understand the concept of multi-dimensional arrays so in this tutorial i will show them how to make a random spawn system and similar stuff without using the arrays. Since the array method is explained in the wiki, i'll be explaining the second one. |