Alternating Spawn Locations?
#1

When people connect to my server and spawn, I want them to spawn at their last position.
PHP код:
    if(PlayerInfo[playerid][pXPos] == 0.0 && PlayerInfo[playerid][pYPos] == 0.0 && PlayerInfo[playerid][pZPos] == 0.0)
    {
        
SetSpawnInfo(playeridNO_TEAMGetPlayerSkin(playerid),-1968.9745,137.8568,27.6875,88.8534000000);
    }
    else
    {
        if(
USE_EXISTING_POSITION == true)
        {
              
SetPlayerPos(playeridPlayerInfo[playerid][pXPos], PlayerInfo[playerid][pYPos], PlayerInfo[playerid][pZPos]);
            
SetPlayerFacingAngle(playeridPlayerInfo[playerid][pAPos]);
        }
        if(
USE_EXISTING_MONEY == true)
        {
               
ResetPlayerMoney(playerid);
            
GivePlayerMoney(playeridPlayerInfo[playerid][pCash]);
        }
    } 
This is under the callback OnPlayerSpawn.
However when a player dies, I want them to spawn at the nearest hospital.
PHP код:
    new Float:distance 99999.0,
    
Float:tmp_distance,
      
closest = -1;
    for(new 
0MAX_HOSPITALSi++)
    {
        
tmp_distance GetPlayerDistanceFromPoint(playeridhspawns[i][0], hspawns[i][1], hspawns[i][2]);
        if (
tmp_distance distance)
        {
            
distance tmp_distance;
            
closest i;
        }
    }
    
SetSpawnInfo(playeridNO_TEAMGetPlayerSkin(playerid), hspawns[closest][0],hspawns[closest][1],hspawns[closest][2],hspawns[closest][3], 000000); 
This code is under the callback OnPlayerDeath

Currently what happens is that when a player connects they spawn at their previous position, however once they die. They spawn at the position they spawned at.

How should I go about this?

So that when a player connects they spawn at their previous position. Once they die they then spawn to the nearest hospital.
Reply
#2

Could you show me the code in OnPlayerDisconnect?
Reply
#3

Under onPlayerDisconnect I have a stock called SaveAccount that obviously saves accounts. here is my SaveAccount stock.
PHP код:
public SaveAccount(playerid)
{
    new 
FloatxFloatyFloat:zFloata;
    
GetPlayerPos(playeridx,y,z);
    
GetPlayerFacingAngle(playerida);
    
PlayerInfo[playerid][pXPos] = x;
    
PlayerInfo[playerid][pYPos] = y;
    
PlayerInfo[playerid][pZPos] = z;
    
PlayerInfo[playerid][pAPos] = a;
    new 
INI:File INI_Open(UserPath(playerid));
    
INI_SetTag(File"data");
    
INI_WriteInt(File"Cash"PlayerInfo[playerid][pCash]);
    
INI_WriteInt(File"Admin"PlayerInfo[playerid][pAdmin]);
    
INI_WriteInt(File"UCAdmin"PlayerInfo[playerid][pUCAdmin]);
    
INI_WriteInt(File"DriversLicense"PlayerInfo[playerid][pDriverLicense]);
    
INI_WriteInt(File"TotalTime"timeSpent);
    
INI_WriteInt(File"pInJail"PlayerInfo[playerid][pInJail]);
    
INI_WriteInt(File"pInJailTime"PlayerInfo[playerid][pInJailTime]);
    
INI_WriteFloat(File"PosX"PlayerInfo[playerid][pXPos]);
    
INI_WriteFloat(File"PosY"PlayerInfo[playerid][pYPos]);
    
INI_WriteFloat(File"PosZ"PlayerInfo[playerid][pZPos]);
    
INI_WriteFloat(File"PosA"PlayerInfo[playerid][pAPos]);
    
INI_WriteInt(File"Banned"PlayerInfo[playerid][pBanned]);
    
INI_WriteString(File"BannedBy"PlayerInfo[playerid][pBannedBy]);
    
INI_WriteString(File"Reason"PlayerInfo[playerid][pReason]);
    
INI_Close(File);
    return 
1;

Reply
#4

Thanks.

You don't save/load the player's health.
Reply
#5

So I need to save/load the player's health? How will that make a difference?
Reply
#6

pawn Код:
public SaveAccount(playerid)
{
    new Float: x, Float: y, Float:z, Float: a, Float: health;
    GetPlayerPos(playerid, x,y,z);
    GetPlayerFacingAngle(playerid, a);
    PlayerInfo[playerid][pXPos] = x;
    PlayerInfo[playerid][pYPos] = y;
    PlayerInfo[playerid][pZPos] = z;
    PlayerInfo[playerid][pAPos] = a;
    GetPlayerHealth(playerid, health);
    new INI:File = INI_Open(UserPath(playerid));
    INI_SetTag(File, "data");
    INI_WriteInt(File, "Cash", PlayerInfo[playerid][pCash]);
    INI_WriteInt(File, "Admin", PlayerInfo[playerid][pAdmin]);
    INI_WriteInt(File, "UCAdmin", PlayerInfo[playerid][pUCAdmin]);
    INI_WriteInt(File, "DriversLicense", PlayerInfo[playerid][pDriverLicense]);
    INI_WriteInt(File, "TotalTime", timeSpent);
    INI_WriteInt(File, "pInJail", PlayerInfo[playerid][pInJail]);
    INI_WriteInt(File, "pInJailTime", PlayerInfo[playerid][pInJailTime]);
    INI_WriteFloat(File, "PosX", PlayerInfo[playerid][pXPos]);
    INI_WriteFloat(File, "PosY", PlayerInfo[playerid][pYPos]);
    INI_WriteFloat(File, "PosZ", PlayerInfo[playerid][pZPos]);
    INI_WriteFloat(File, "PosA", PlayerInfo[playerid][pAPos]);
    INI_WriteFloat(File, "Health", health);
    INI_WriteInt(File, "Banned", PlayerInfo[playerid][pBanned]);
    INI_WriteString(File, "BannedBy", PlayerInfo[playerid][pBannedBy]);
    INI_WriteString(File, "Reason", PlayerInfo[playerid][pReason]);
    INI_Close(File);
    return 1;
}
In the load function of the account:

pawn Код:
new Float: health;
INI_ReadFloat(File, "Health", health); // or INI_GetFloat
SetPlayerHealth(playerid, health);
Reply
#7

I don't understand why saving health is going to fix my Spawning problem...
Reply
#8

Bump?
Reply
#9

I found this code in a different gamemode, however I don't understand it could someone tell me how I could manipulate this code to use within my gamemode?

PHP код:
    if (Logged[playerid] == 1) {
        if (!
dini_Isset(AddDirFile(dir_userfilesplayername), "firstspawn")) {
            
SetSpawnInfo(playeridNO_TEAMpdfs[playerid], dini_Float(AddDirFile(dir_userfilesplayername), "X"), dini_Float(AddDirFile(dir_userfilesplayername), "Y"), dini_Float(AddDirFile(dir_userfilesplayername), "Z"), dini_Float(AddDirFile(dir_userfilesplayername), "A"), -1, -1, -1, -1, -1, -1);
        }
        else {
            new 
rand MRandom(sizeof(rspawns));
            
SetSpawnInfo(playeridNO_TEAMpdfs[playerid], rspawns[rand][0], rspawns[rand][1], rspawns[rand][2], rspawns[rand][3], -1, -1, -1, -1, -1, -1);
        }
    }
    else if (
orcl[playerid][1] == 1) {
        
SetSpawnInfo(playeridNO_TEAMpdfs[playerid], hspawns[dspawn[playerid]][0], hspawns[dspawn[playerid]][1], hspawns[dspawn[playerid]][2], hspawns[dspawn[playerid]][3], -1, -1, -1, -1, -1, -1);
    } 
Reply
#10

I am wondering why there is a SetSpawnInfo in your OnPlayerSpawn, it will take effect after you spawned

If you use INI you need to use global variables to load the data, therefor you could remove SetSpawnInfo completely
PHP код:
// OnPlayerConnect
    
PlayerInfo[playerid][pXPos] = -1968.9745// default spawn for everyone who connects
    
PlayerInfo[playerid][pYPos] = 137.8568;
    
PlayerInfo[playerid][pZPos] = 27.6875;
    
PlayerInfo[playerid][pAPos] = 88.8534;
// OnPlayerSpawn
    
SetPlayerPos(playeridPlayerInfo[playerid][pXPos], PlayerInfo[playerid][pYPos], PlayerInfo[playerid][pZPos]);
    
SetPlayerFacingAngle(playeridPlayerInfo[playerid][pAPos]);
    if(
USE_EXISTING_MONEY == true)
    {
        
ResetPlayerMoney(playerid);
        
GivePlayerMoney(playeridPlayerInfo[playerid][pCash]);
    }
// OnPlayerDeath
    
new
        
Floatdistance GetPlayerDistanceFromPoint(playeridhspawns[0][0], hspawns[0][1], hspawns[0][2]),
        
Floattmp_distance,
        
closest 0;
    for(new 
1MAX_HOSPITALSi++)
    {
        
tmp_distance GetPlayerDistanceFromPoint(playeridhspawns[i][0], hspawns[i][1], hspawns[i][2]);
        if (
tmp_distance distance)
        {
            
distance tmp_distance;
            
closest i;
        }
    }
    
PlayerInfo[playerid][pXPos] = hspawns[closest][0];
    
PlayerInfo[playerid][pYPos] = hspawns[closest][1];
    
PlayerInfo[playerid][pZPos] = hspawns[closest][2];
    
PlayerInfo[playerid][pAPos] = hspawns[closest][3]; 
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)