Random Spawn
#1

Hey,

I'd like to create random spawns when you join the server or get killed etc...
I DID SEARCH BEFORE POSTING. The answers werent clear to me though.

Bai
Reply
#2

https://sampwiki.blast.hk/wiki/Random

Seems like you hadn't searched hard enough, it was right in the wiki.

If you don't understand:

pawn Код:
new Float:RandomSpawn[][4] = //This is a variable that holds the information of the random spawns, save as much positions as you want.

/*The first square brackets stands for the amount of random spawns, it's optional, the second brackets however are not optional and must be filled, they hold how much information pieces each one of the variables hold. 4 In this specific case, x(1),y(2),z(3) and facing angle(4).*/
{
    // Positions, (X, Y, Z and Facing Angle)
    {-2796.9854, 1224.8180, 20.5429, 192.0335},
    {-2454.2170, 503.8759, 30.0790, 267.2932},
    {-2669.7322, -6.0874, 6.1328, 89.8853}
};
pawn Код:
public OnPlayerSpawn(playerid)
{
    new rand = random(sizeof(RandomSpawn)); // it randomizes between the three lines of positions we've inserted above.
   
   
    SetPlayerPos(playerid, RandomSpawn[rand][0], RandomSpawn[rand][1],RandomSpawn[rand][2]);
    /*This is sending the player to the randomized position, [rand] is a random we've declared above, it's randomized between the 3 lines of positions we have.
    0 means the first piece of information from the line we've just randomized, the first one as you remember, is the X position,so on for 1 and 2.
 */


     SetPlayerFacingAngle(playerid, RandomSpawn[rand][3]); //As we've explained, now the fourth piece of information from the randomized line, which is the facing angle.
     
    return 1;
}
Reply
#3

Well. I have 5 differnet spawns.

What variables should I use then?
Thanks
Reply
#4

i did this and it wont work
Reply
#5

: error 017: undefined symbol "RandomSpawn"
: error 029: invalid expression, assumed zero
: warning 215: expression has no effect
: error 017: undefined symbol "RandomSpawn"
: warning 215: expression has no effect
: error 001: expected token: ";", but found "]"
: error 029: invalid expression, assumed zero
: fatal error 107: too many error messages on one line
Reply
#6

It's in my script with NO errors, but my players still spawn at the AddPlayerSpawn Location, how to solve that ?

Bai
Reply
#7

Anyone ?
Reply
#8

AddPlayerSpawn? custom function or you mean something else?
like AddPlayerClass...
Reply
#9

I added all random spawns, but the player still spawns at:
AddPlayerClass(266, 1948.236450, -2239.018066, 13.546875, 136.121856, 0, 0, 0, 0, 0, 0);

And it should be spawning @ the random spawns :/
Reply
#10

Hey, thats strange since i know AddPlayerClass the co-ords arent the spawning co-ords but the co-ords to select the class (switching skins)
Your sure nothing in a script has a SetPlayerPos on spawn?
Reply


Forum Jump:


Users browsing this thread: 7 Guest(s)