Spawn player problems.
#1

o/,

Here is a code I wrote which switches spawn locations every round:

The first round, players spawn randomly at LV Airport normally.
However, in the second round instead of spawning at WEST LV they all spawn at the default location (on LV Strip in the building in front of the Pyramid near the escalators which are the coordinates for my skin but 1 player spawns normally at WEST LV...
On the third round when the spawn location is set back to LV Airport all players spawn normally at LV Airport.
PHP код:
(under OnGamemodeInit)
    for (new 
i=0i<310i++)
    {
        if (
i>= 0)
        
AddPlayerClass(i1958.37831343.157215.3746269.1425000000);
     } 
PHP код:
new MapChange;
forward StartedNewRound();
forward NewMapTimer(playerid);
new 
Float:SpawnLVA[][]=
    {
        {
1651.17951543.308114.63340.0000},
        {
1623.37181536.687214.63340.0000},
        {
1635.28941581.709114.6334270.0000},
        {
1591.59161624.082714.6334180.0000},
        {
1701.49811673.077114.6334180.0000},
        {
1701.49811577.736614.633490.0000},
        {
1718.71241634.676114.63340.0000}
    };
    
new 
Float:SpawnWESTLV[][] =
    {
        {
1059.41841081.0885,10.1808 ,270.0000 },
        {
1092.52281107.5720,10.1808 ,180.0000 },
        {
1122.97881069.1709,10.1808 ,90.0000 },
        {
1085.90191040.0391,10.1808 ,0.0000 },
        {
1091.19861073.1435,10.8359 ,0.0000 },
        {
1122.97881100.9511,10.1808 ,180.0000 },
        {
1064.71511103.5995,10.1808 ,180.0000 }
    };
    
public 
OnPlayerSpawn(playerid)
{
GivePlayerWeapon(playerid,24,300); //DEAGLE
GivePlayerWeapon(playerid,25,300); //SHOTGUN
GivePlayerWeapon(playerid,34,300); //SNIPER
SetPlayerArmour(playerid100);
TextDrawShowForPlayer(playerid, FINAL);
            
   
switch (
MapChange)
    {                       
// you must have a case for the mapchange to get the list going
        
case 0:                                   // MapChange1 this is the part for MapChange = 0; Which basically starts of the first MapChangein the list
        
{
            new 
rand random(sizeof(SpawnLVA));
            
SetPlayerPos(playeridSpawnLVA[rand][0],SpawnLVA[rand][1],SpawnLVA[rand][2]);        // XYZ Co-rds of the first map
            
SetPlayerFacingAngle(playerid,SpawnLVA[rand][3]);   // Facing Angle of the first map
            
TogglePlayerControllable(playerid1);
        }
        case 
1:                                   // MapChange2 same settings on top
        
{
            new 
rand random(sizeof(SpawnWESTLV));
            
SetPlayerPos(playeridSpawnWESTLV[rand][0],SpawnWESTLV[rand][1],SpawnWESTLV[rand][2]);        // XYZ Co-rds of the first map
            
SetPlayerFacingAngle(playerid,SpawnWESTLV[rand][3]);
            
TogglePlayerControllable(playerid1);
            
            
MapChange =-1;
        }
    }
return 
1;
}
public 
NewMapTimer(playerid)                      // The function we forwarded on the beginning of the tutorial
{
    
MapChange++;                            // this makes it to go to the second MapChange++ part basically does it
    
roundstats[playerid][rKills]=0;
    
roundstats[playerid][rDeaths]=0;
    
GameTextForPlayer(playerid"~r~Switching maps, wait..."40006);
    
SetTimer("StartedNewRound",8000,false);       // Starts a new timer for the MapChangechange 4 seconds this basically starts the new MapChangeand always must be in false
    
return 1;
}
forward StartedNewRound();
public 
StartedNewRound()                          // The callback we forwarded in the beginning of this tutorial
{
    for(new 
0MAX_PLAYERSi++)
    {        
// this loops everyone in the server also you can use foreach include for this part
        
SpawnPlayer(i);                      // Re Spawns everyone in the server which then gets OnPlayerSpawn Callback called
    
}
    return 
1;

I've been trying to fix this but I can't work around it, if anyone could help I will be grateful.
Reply
#2

pawn Код:
#include <a_samp>

new MapChange;
forward StartedNewRound();
forward NewMapTimer(playerid);


new Float:SpawnLVA[][]=
{
        {1651.1795, 1543.3081, 14.6334, 0.0000},
        {1623.3718, 1536.6872, 14.6334, 0.0000},
        {1635.2894, 1581.7091, 14.6334, 270.0000},
        {1591.5916, 1624.0827, 14.6334, 180.0000},
        {1701.4981, 1673.0771, 14.6334, 180.0000},
        {1701.4981, 1577.7366, 14.6334, 90.0000},
        {1718.7124, 1634.6761, 14.6334, 0.0000}
};

new Float:SpawnWESTLV[][] =
{
        {1059.4184, 1081.0885,10.1808 ,270.0000 },
        {1092.5228, 1107.5720,10.1808 ,180.0000 },
        {1122.9788, 1069.1709,10.1808 ,90.0000 },
        {1085.9019, 1040.0391,10.1808 ,0.0000 },
        {1091.1986, 1073.1435,10.8359 ,0.0000 },
        {1122.9788, 1100.9511,10.1808 ,180.0000 },
        {1064.7151, 1103.5995,10.1808 ,180.0000 }
};

public OnPlayerSpawn(playerid)
{

    GivePlayerWeapon(playerid,24,300); //DEAGLE
    GivePlayerWeapon(playerid,25,300); //SHOTGUN
    GivePlayerWeapon(playerid,34,300); //SNIPER
    SetPlayerArmour(playerid, 100);
    TextDrawShowForPlayer(playerid, FINAL);
    SetPlayerToMap(playerid);
    return 1;
}




SetPlayerToMap(playerid)
{
    switch (MapChange)
    {                       // you must have a case for the mapchange to get the list going
            case 0:                                   // MapChange1 this is the part for MapChange = 0; Which basically starts of the first MapChangein the list
            {
                new rand = random(sizeof(SpawnLVA));
                SetPlayerPos(playerid, SpawnLVA[rand][0],SpawnLVA[rand][1],SpawnLVA[rand][2]);        // XYZ Co-rds of the first map
                SetPlayerFacingAngle(playerid,SpawnLVA[rand][3]);   // Facing Angle of the first map
                TogglePlayerControllable(playerid, 1);
            }
            case 1:                                   // MapChange2 same settings on top
            {
                new rand = random(sizeof(SpawnWESTLV));
                SetPlayerPos(playerid, SpawnWESTLV[rand][0],SpawnWESTLV[rand][1],SpawnWESTLV[rand][2]);        // XYZ Co-rds of the first map
                SetPlayerFacingAngle(playerid,SpawnWESTLV[rand][3]);
                TogglePlayerControllable(playerid, 1);

                MapChange =-1;
            }
            return 1;
    }
}




public NewMapTimer(playerid)                      // The function we forwarded on the beginning of the tutorial
{
    MapChange += 1;                            // this makes it to go to the second MapChange++ part basically does it
    roundstats[playerid][rKills] = 0;
    roundstats[playerid][rDeaths] = 0;


    GameTextForPlayer(playerid, "~r~Switching maps, wait...", 4000, 6);
    SetTimer("StartedNewRound",8000,false);       // Starts a new timer for the MapChangechange 4 seconds this basically starts the new MapChangeand always must be in false
    return 1;
}

forward StartedNewRound();
public StartedNewRound()                          // The callback we forwarded in the beginning of this tutorial
{
    for(new i = 0; i < MAX_PLAYERS; i++)
    {        // this loops everyone in the server also you can use foreach include for this part
        SpawnPlayer(i);                      // Re Spawns everyone in the server which then gets OnPlayerSpawn Callback called
    }
    return 1;
}
Try it.
Reply
#3

1. Skin id 74 doesn't exists so you must add if(i != 74)
2. Change MapChange =-1; to MapChange = 0; or MapChange -= 1;

=-1;
to
-= 1;
Reply
#4

Quote:
Originally Posted by Jefff
Посмотреть сообщение
1. Skin id 74 doesn't exists so you must add if(i != 74)
2. Change MapChange =-1; to MapChange = 0; or MapChange -= 1;

=-1;
to
-= 1;
when MapChange - =1, player id 0 goes to WEST LV but player id 1 respawns again in LV Airport instead of WEST LV (which is better than spawning near the escaltors ) but it is still not functionning properly.

I will be trying to find a fix now.

maybe there is something wrong with the loop?


UPDATE: when i use
PHP код:
forward StartedNewRound();
public 
StartedNewRound()                          // The callback we forwarded in the beginning of this tutorial
{
    for(new 
1MAX_PLAYERSi++)
    {        
// this loops everyone in the server also you can use foreach include for this part
        
SpawnPlayer(i);                      // Re Spawns everyone in the server which then gets OnPlayerSpawn Callback called
    
}
    return 
1;

instead of
PHP код:
forward StartedNewRound();
public 
StartedNewRound()                          // The callback we forwarded in the beginning of this tutorial
{
    for(new 
0MAX_PLAYERSi++)
    {        
// this loops everyone in the server also you can use foreach include for this part
        
SpawnPlayer(i);                      // Re Spawns everyone in the server which then gets OnPlayerSpawn Callback called
    
}
    return 
1;

only ID 1 changes map while ID 0 remains at LV Airport, any solutions?
Reply
#5

Hello!

Quote:

maybe there is something wrong with the loop?

You should use this version:
PHP код:
forward StartedNewRound();
public 
StartedNewRound()                          // The callback we forwarded in the beginning of this tutorial
{
    for(new 
0MAX_PLAYERSi++)
    {        
// this loops everyone in the server also you can use foreach include for this part
        
if(!IsPlayerConnected(i) || IsPlayerNPC(i))continue;
        
SpawnPlayer(i);                      // Re Spawns everyone in the server which then gets OnPlayerSpawn Callback called
    
}
    return 
1;

In your version you would spawn all players (npcs).
Reply
#6

Quote:
Originally Posted by Mencent
Посмотреть сообщение
Hello!



You should use this version:
PHP код:
forward StartedNewRound();
public 
StartedNewRound()                          // The callback we forwarded in the beginning of this tutorial
{
    for(new 
0MAX_PLAYERSi++)
    {        
// this loops everyone in the server also you can use foreach include for this part
        
if(!IsPlayerConnected(i) || IsPlayerNPC(i))continue;
        
SpawnPlayer(i);                      // Re Spawns everyone in the server which then gets OnPlayerSpawn Callback called
    
}
    return 
1;

In your version you would spawn all players (npcs).
Tested it with 2 players;
ID 0 goes to WEST LV but ID 1 respawns again at LV Airport ;/
Reply
#7

Can you send me your OnPlayerSpawn callback?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)