SA-MP Forums Archive
Make Player Spawns more Perfect - 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: Make Player Spawns more Perfect (/showthread.php?tid=627305)



Make Player Spawns more Perfect - DerickClark - 26.01.2017

How to give out better randon spawns? they should not spawn at the same spawn
Код:
enum SpawnLocation
{
    Spawnname[256],
	Float:SpawnX,
	Float:SpawnY,
	Float:SpawnZ,
	Float:SpawnAngle
}


new const TruckerSpawn[][SpawnLocation] =
{
    // Positions, (Spawnname, X, Y, Z and Facing Angle)
    //{"Tierra Robada",-1278.0699,2709.5935,50.2663,299.5070},
    //{"Shady Creeks",-1561.4307,-2733.6567,48.7435,236.4525},
    {"UNKOWN Spawn_Name", 2269.3945,-2343.9868,13.5469,314.4856}
};
OnPlayerSpawn
Код:
        //regular code
        new rand = random(sizeof(TruckerSpawn));
        SetPlayerPos(playerid, TruckerSpawn[rand][SpawnX], TruckerSpawn[rand][SpawnY], TruckerSpawn[rand][SpawnZ]);
        SetPlayerFacingAngle(playerid, TruckerSpawn[rand][SpawnAngle]);
        SetCameraBehindPlayer(playerid);
        
        // code added
        static last,current;
        while( last == current)
        {
            current = random(sizeof(TruckerSpawn));
        }
        SendClientMessageToAll(-1, TruckerSpawn[current]);
        last = current;
How to apply this?

http://forum.sa-mp.com/showpost.php?...3&postcount=13


Re: Make Player Spawns more Perfect - SyS - 26.01.2017

Like this
PHP код:
 
static last,current;
while( 
last == current)
{
  
current random(sizeof(TruckerSpawn));
}
SetPlayerPos(playeridTruckerSpawn[current][SpawnX], TruckerSpawn[current][SpawnY], TruckerSpawn[current][SpawnZ]);
SetPlayerFacingAngle(playeridTruckerSpawn[current][SpawnAngle]);
SetCameraBehindPlayer(playerid);
last current
All we is doing ,in both cases, is randomising indices of array with reference to last spawned place.

NOTE: It might not work for a per player purpose for that you need to make a per player array of current and last.So its better to do like this

PHP код:
 
static last[MAX_PLAYERS],current[MAX_PLAYERS];
while( 
last[playerid] == current[playerid])
{
  
current[playerid] = random(sizeof(TruckerSpawn));
}
SetPlayerPos(playeridTruckerSpawn[current[playerid]][SpawnX], TruckerSpawn[current[playerid]][SpawnY], TruckerSpawn[current[playerid]][SpawnZ]);
SetPlayerFacingAngle(playeridTruckerSpawn[current[playerid]][SpawnAngle]);
SetCameraBehindPlayer(playerid);
last[playerid] = current[playerid]; 
Choice is yours....


Re: Make Player Spawns more Perfect - DerickClark - 26.01.2017

Quote:
Originally Posted by Sreyas
Посмотреть сообщение
Like this
PHP код:
 
static last,current;
while( 
last == current)
{
  
current random(sizeof(TruckerSpawn));
}
SetPlayerPos(playeridTruckerSpawn[current][SpawnX], TruckerSpawn[current][SpawnY], TruckerSpawn[current][SpawnZ]);
SetPlayerFacingAngle(playeridTruckerSpawn[current][SpawnAngle]);
SetCameraBehindPlayer(playerid);
last current
All we is doing ,in both cases, is randomising indices of array with reference to last spawned place.
NOTE:Iit might not work for a per player purpose for that you need to make a per player array of current and last.
It don't work. the server stop respondin when spawn


Re: Make Player Spawns more Perfect - SyS - 26.01.2017

Quote:
Originally Posted by DerickClark
Посмотреть сообщение
It don't work. the server stop respondin when spawn
What about second one?(Also i dont have any problem with first one)


Re: Make Player Spawns more Perfect - DerickClark - 26.01.2017

Quote:
Originally Posted by Sreyas
Посмотреть сообщение
What about second one?(Also i dont have any problem with first one)
They both login to the server then spawn then the server stop working. and the spawn won't show



Код:
new rand = random(sizeof(TruckerSpawn));
static last[MAX_PLAYERS],current[MAX_PLAYERS]; 
while( last[playerid] == current[playerid]) 
{ 
  current[playerid] = random(sizeof(TruckerSpawn)); 
} 
SetPlayerPos(playerid, TruckerSpawn[current[playerid]][SpawnX], TruckerSpawn[current[playerid]][SpawnY], TruckerSpawn[current[playerid]][SpawnZ]); 
SetPlayerFacingAngle(playerid, TruckerSpawn[current[playerid]][SpawnAngle]); 
SetCameraBehindPlayer(playerid); 
last[playerid] = current[playerid];



Re: Make Player Spawns more Perfect - SyS - 26.01.2017

All i can think of is a infinite loop (but its working perfect for me) try to debug the code like this and show me what is printing on console.


Код:
new rand = random(sizeof(TruckerSpawn));
static last[MAX_PLAYERS],current[MAX_PLAYERS]; 
new i;
while( last[playerid] == current[playerid]) 
{ 
  printf("iteration = %d ",i++);
  current[playerid] = random(sizeof(TruckerSpawn)); 
  printf("current = %d ",current[playerid]);
} 
SetPlayerPos(playerid, TruckerSpawn[current[playerid]][SpawnX], TruckerSpawn[current[playerid]][SpawnY], TruckerSpawn[current[playerid]][SpawnZ]); 
SetPlayerFacingAngle(playerid, TruckerSpawn[current[playerid]][SpawnAngle]); 
SetCameraBehindPlayer(playerid); 
last[playerid] = current[playerid];



Re: Make Player Spawns more Perfect - SyS - 27.01.2017

you may not have initialized the array is this part on your code?you probably forgot it.That is the only probability of giving random() always zero.
Код:
enum SpawnLocation
{
    Spawnname[256],
	Float:SpawnX,
	Float:SpawnY,
	Float:SpawnZ,
	Float:SpawnAngle
}


static const TruckerSpawn[][SpawnLocation] =
{
    // Positions, (Spawnname, X, Y, Z and Facing Angle)
    //{"Tierra Robada",-1278.0699,2709.5935,50.2663,299.5070},
    //{"Shady Creeks",-1561.4307,-2733.6567,48.7435,236.4525},
    {"UNKOWN Spawn_Name", 2269.3945,-2343.9868,13.5469,314.4856}
};



Re: Make Player Spawns more Perfect - DerickClark - 27.01.2017

Quote:
Originally Posted by Sreyas
Посмотреть сообщение
you may not have initialized the array is this part on your code?you probably forgot it.That is the only probability of giving random() always zero.
Код:
enum SpawnLocation
{
    Spawnname[256],
	Float:SpawnX,
	Float:SpawnY,
	Float:SpawnZ,
	Float:SpawnAngle
}


static const TruckerSpawn[][SpawnLocation] =
{
    // Positions, (Spawnname, X, Y, Z and Facing Angle)
    //{"Tierra Robada",-1278.0699,2709.5935,50.2663,299.5070},
    //{"Shady Creeks",-1561.4307,-2733.6567,48.7435,236.4525},
    {"UNKOWN Spawn_Name", 2269.3945,-2343.9868,13.5469,314.4856}
};
added that same problem


Re: Make Player Spawns more Perfect - SyS - 27.01.2017

Crap i didn't notice you put a comment line (//) on each element making only 1 element that made size 1 and random(1) is always zero.(thats why php tags better than code)

PHP код:
static const TruckerSpawn[][SpawnLocation] =
{
    
// Positions, (Spawnname, X, Y, Z and Facing Angle)
    
{"Tierra Robada",-1278.0699,2709.5935,50.2663,299.5070},
    {
"Shady Creeks",-1561.4307,-2733.6567,48.7435,236.4525},
    {
"UNKOWN Spawn_Name"2269.3945,-2343.9868,13.5469,314.4856}
}; 
^^It will work


Re: Make Player Spawns more Perfect - DerickClark - 27.01.2017

Quote:
Originally Posted by Sreyas
Посмотреть сообщение
Crap i didn't notice you put a comment line (//) on each element making only 1 element that made size 1 and random(1) is always zero.(thats why php tags better than code)

PHP код:
static const TruckerSpawn[][SpawnLocation] =
{
    
// Positions, (Spawnname, X, Y, Z and Facing Angle)
    
{"Tierra Robada",-1278.0699,2709.5935,50.2663,299.5070},
    {
"Shady Creeks",-1561.4307,-2733.6567,48.7435,236.4525},
    {
"UNKOWN Spawn_Name"2269.3945,-2343.9868,13.5469,314.4856}
}; 
^^It will work
It stop spamming / it's now showing the spawn but.

This first spawn debug, current?
Код:
[21:22:35] iteration = 0 
[21:22:35] current = 0 
[21:22:35] iteration = 1 
[21:22:35] current = 1
2nd Spawn, spawn at the same as First Spawn