SA-MP Forums Archive
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=652129)



random spawns - Lukasz56 - 03.04.2018

what's wrong with my code?

https://pastebin.com/ThYjj8K2


Re: random spawns - Jstylezzz - 03.04.2018

SetPlayerPos has only 4 arguments.
Code:
SetPlayerPos(playerid, Float:x, Float:y, Float:z);
You have more than those 4 arguments.


Re: random spawns - Jstylezzz - 03.04.2018

Quote:
Originally Posted by Lokii
View Post
PHP Code:
#include <a_samp>
new Float:RandomSpawn[6][4] =
{
    {-
480.6924,2189.9875,41.8672},  // Dam LV
    
{271.9112,-1867.8492,2.7009},  // Aqua Park LS
    
{379.7065,2537.1069,16.5391}, // Abandoned Airport
    
{2075.2749,-2535.3286,13.5469}, // Airport LS
    
{-2343.2390,-1636.1138,483.7031}, // Mount Chilliad
    
{-2619.8066,1396.3444,7.1016// Jizzy's SF
};
public 
OnPlayerConnect(playerid)
{
    
SetPlayerPos(playeridRandomSpawn[random(sizeof(RandomSpawn))][0], RandomSpawn[random(sizeof(RandomSpawn))][1], RandomSpawn[random(sizeof(RandomSpawn))][2]);

No, that won't work as intended. What you're doing here is sampling the X, Y and Z command all from a different index. This might spawn the player inside buildings or at least spawn the player on a weird, unintended position. If you're going to take random positions, save the random value before the SetPlayerPos function, and only then sample your coordinates from the array using the index saved beforehand.

EDIT: It won't magically fix itself if you delete your post and post the same thing again. Your approach will not work.
EDIT2: Now that should work. Nice.


Re: random spawns - Lokii - 03.04.2018

Quote:
Originally Posted by Jstylezzz
View Post
No, that won't work as intended. What you're doing here is sampling the X, Y and Z command all from a different index. This might spawn the player inside buildings or at least spawn the player on a weird, unintended position. If you're going to take random positions, save the random value before the SetPlayerPos function, and only then sample your coordinates from the array using the index saved beforehand.

EDIT: It won't magically fix itself if you delete your post and post the same thing again. Your approach will not work.
yea sorry my bad fixed

the player wont spawn in random place because you use this on player connect you

this on player spawn:

PHP Code:
#include <a_samp>
new Float:RandomSpawn[][6] =
{
    {-
480.6924,2189.9875,41.8672},  // Dam LV
    
{271.9112,-1867.8492,2.7009},  // Aqua Park LS
    
{379.7065,2537.1069,16.5391}, // Abandoned Airport
    
{2075.2749,-2535.3286,13.5469}, // Airport LS
    
{-2343.2390,-1636.1138,483.7031}, // Mount Chilliad
    
{-2619.8066,1396.3444,7.1016// Jizzy's SF
};
public 
OnPlayerSpawn(playerid)
{
    new 
rand random(sizeof(RandomSpawn));
    
SetPlayerPos(playeridRandomSpawn[rand][0], RandomSpawn[rand][1],RandomSpawn[rand][2]);
    return 
1;




Re: random spawns - Jstylezzz - 03.04.2018

Quote:
Originally Posted by Lokii
View Post
yea sorry my bad fixed

the player wont spawn in random place because you use this on player connect you

this on player spawn:

PHP Code:
#include <a_samp>
new Float:RandomSpawn[][4] =
{
    {-
480.6924,2189.9875,41.8672},  // Dam LV
    
{271.9112,-1867.8492,2.7009},  // Aqua Park LS
    
{379.7065,2537.1069,16.5391}, // Abandoned Airport
    
{2075.2749,-2535.3286,13.5469}, // Airport LS
    
{-2343.2390,-1636.1138,483.7031}, // Mount Chilliad
    
{-2619.8066,1396.3444,7.1016// Jizzy's SF
};
public 
OnPlayerSpawn(playerid)
{
    new 
rand random(sizeof(RandomSpawn));
    
SetPlayerPos(playeridRandomSpawn[rand][0], RandomSpawn[rand][1],RandomSpawn[rand][2]);
    return 
1;

You might want to look at the size of the random positions array. There are 6 entries, while you set the size to 4. This will make it exceed its declared size.

PHP Code:
#include <a_samp>
new Float:RandomSpawn[][6] =
{
    {-
480.6924,2189.9875,41.8672},  // Dam LV
    
{271.9112,-1867.8492,2.7009},  // Aqua Park LS
    
{379.7065,2537.1069,16.5391}, // Abandoned Airport
    
{2075.2749,-2535.3286,13.5469}, // Airport LS
    
{-2343.2390,-1636.1138,483.7031}, // Mount Chilliad
    
{-2619.8066,1396.3444,7.1016// Jizzy's SF
};
public 
OnPlayerSpawn(playerid)
{
    new 
rand random(sizeof(RandomSpawn));
    
SetPlayerPos(playeridRandomSpawn[rand][0], RandomSpawn[rand][1],RandomSpawn[rand][2]);
    return 
1;

This should work.


Re: random spawns - Lukasz56 - 03.04.2018

Thank you , what a stupid mistake i made . repped both of you


Re: random spawns - Jstylezzz - 03.04.2018

Quote:
Originally Posted by Lukasz56
View Post
Thank you , what a stupid mistake i made . repped both of you
It's not a stupid mistake at all, just an easy mistake to make


Re: random spawns - Lokii - 03.04.2018

Quote:
Originally Posted by Jstylezzz
View Post
You might want to look at the size of the random positions array. There are 6 entries, while you set the size to 4. This will make it exceed its declared size.

PHP Code:
#include <a_samp>
new Float:RandomSpawn[][6] =
{
    {-
480.6924,2189.9875,41.8672},  // Dam LV
    
{271.9112,-1867.8492,2.7009},  // Aqua Park LS
    
{379.7065,2537.1069,16.5391}, // Abandoned Airport
    
{2075.2749,-2535.3286,13.5469}, // Airport LS
    
{-2343.2390,-1636.1138,483.7031}, // Mount Chilliad
    
{-2619.8066,1396.3444,7.1016// Jizzy's SF
};
public 
OnPlayerSpawn(playerid)
{
    new 
rand random(sizeof(RandomSpawn));
    
SetPlayerPos(playeridRandomSpawn[rand][0], RandomSpawn[rand][1],RandomSpawn[rand][2]);
    return 
1;

This should work.
sorry thx for telling