Jump to content

Recrutăm designeri audio și video. Aplicați aici

Recrutăm designeri grafici. Aplicați aici


Sign in to follow this  

[Pawn] Creating Random Spawn

Recommended Posts

Creating random spawn


Step 1: Getting the coordinates
To create random spawns we of course need to get coordinates which we will use for our random spawns, This is the easy way to get these:
Go in-game.

Go to the location where you want one of the spawns to be.
Type "/save" (without the " ")

Repeat the above steps until you have all your spawns.

Note: It is important that your character is facing the way you want them to spawn. It is pretty annoying when your character spawns facing a wall!
Note2: I advise you to add a word behind the "/save" so that you will easily know which ones are for the random spawns.
(Example: /save randomspawn)

Step 2: Finding the coordinates
In step 1 we have saved our spawns and now it is time to get them out of the default file where the "/save" command saves the positions.


Navigate too

...\My Documents\GTA San Andreas User Files\SAMP

Search the file



And open it.


Now search through the file until you find your positions which are marked with whatever word you added to your "/save" command (In the tutorial this will be randomspawn).

Step 3: Converting the coordinates
In step 2 we have located the positions, now we'll have to make them fit into our array.

IMPORTANT NOTE: This tool can convert the coordinates automatically!! Thanks to JaTochNietDan

Copy all your spawn point positions and paste them inside your game mode (or wherever you want the random spawns to be)


AddPlayerClass(101,1249.7258,-2047.9263,59.9209,90.2055,0,0,0,0,0,0); // Randomspawn
AddPlayerClass(101,1241.2084,-2057.6521,60.0190,94.9352,0,0,0,0,0,0); // Randomspawn
AddPlayerClass(101,1241.0105,-2052.6873,59.9975,2.8144,0,0,0,0,0,0); // Randomspawn
AddPlayerClass(101,718.4906,-1477.3024,5.4688,357.9947,0,0,0,0,0,0); // Randomspawn
AddPlayerClass(101,722.3772,-1477.2856,5.4688,272.3814,0,0,0,0,0,0); // Randomspawn


This is what we have, but we will need to convert this to an array. But first!

AddPlayerClass(skinid, x, y, z, angle, weapon1, weapon1_ammo, weapon2, weapon2_ammo, weapon3, weapon3_ammo)


Note: Check the wiki for further information: Click


For our random spawns, we will only need x, y, z coordinates, and the angle.


1249.7258, -2047.9263, 59.9209, 90.2055 // Randomspawn
1241.2084, -2057.6521, 60.0190, 94.9352 // Randomspawn
1241.0105, -2052.6873, 59.9975, 2.8144 // Randomspawn
718.4906, -1477.3024, 5.4688, 357.9947 // Randomspawn
722.3772, -1477.2856, 5.4688, 272.3814// Randomspawn


Now that we have extracted the x, y, z coordinates, and the angle out of the AddPlayerClass function we can easily convert that into an array!

new Float:RandomSpawns[][] = 
    {1249.7258, -2047.9263, 59.9209, 90.2055}, // Randomspawn
    {1241.2084, -2057.6521, 60.0190, 94.9352}, // Randomspawn
    {1241.0105, -2052.6873, 59.9975, 2.8144}, // Randomspawn
    {718.4906, -1477.3024, 5.4688, 357.9947}, // Randomspawn
    {722.3772, -1477.2856, 5.4688, 272.3814} // Randomspawn


Important: The array should be located outside any function!!
Wow, what is this?
Time to explain don't you think:

new Float:RandomSpawns[][] = 


  1. new is the default word to indicate the creation of a new variable, array, ....
  2. Float indicates that the data inside the array will be Floats.
  3. RandomSpawns is the name of the array (You may change this if you want but keep in mind to change it everywhere we will use it!)
  4. The first [] is left blank so that we don't have to change the number when we add more spawns, this basicly allows unlimited data.
  5. The second [] is left blank so that we don't have to change the number when we want to add more data to a spawn. (Example: x, y, z, angle, skin, weapon)
  6. The rest of the code should be pretty easy to understand.


{1249.7258, -2047.9263, 59.9209, 90.2055}, // Randomspawn
{    x   ,     y     ,   z    ,  angle  }, //Randomspawn


Note: The last line does not contain a "," at the end wich indicates that this is the last line in the array.

Step 4: Creating the spawn code
In the previous steps we have done everything containing coordinates, now it is time to use them!

The array has to be in the same script as where we will put this piece of code!



public OnPlayerSpawn(playerid)
    return 1;


Once you found this function it is time to create the actual random spawning.

public OnPlayerSpawn(playerid)
    new Random = random(sizeof(RandomSpawns));
    SetPlayerPos(playerid, RandomSpawns[Random][0], RandomSpawns[Random][1], RandomSpawns[Random][2]);
    SetPlayerFacingAngle(playerid, RandomSpawns[Random][3]);
    return 1;


  1. random(sizeof(RandomSpawns)) is a function which randomly picks a number out of a given amount. The sizeof(RandomPlayerSpawns) automatically outputs the amount of data inside the array, in this example, this is 5.
  2. SetPlayerPos: Click me
  3. RandomSpawns[Random][0] stands for the x coordinate that corresponds with the number that our variable "Random" contains.
  4. RandomSpawns[Random][1] stands for the y coordinate.
  5. RandomSpawns[Random][2] stands for the z coordinate.
  6. SetPlayerFacingAngle: Click me
  7. RandomSpawns[Random][3] stands for the angle.

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  


Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.