21.07.2016, 10:15
When people connect to my server and spawn, I want them to spawn at their last position.
This is under the callback OnPlayerSpawn.
However when a player dies, I want them to spawn at the nearest hospital.
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.
PHP код:
if(PlayerInfo[playerid][pXPos] == 0.0 && PlayerInfo[playerid][pYPos] == 0.0 && PlayerInfo[playerid][pZPos] == 0.0)
{
SetSpawnInfo(playerid, NO_TEAM, GetPlayerSkin(playerid),-1968.9745,137.8568,27.6875,88.8534, 0, 0, 0, 0, 0, 0);
}
else
{
if(USE_EXISTING_POSITION == true)
{
SetPlayerPos(playerid, PlayerInfo[playerid][pXPos], PlayerInfo[playerid][pYPos], PlayerInfo[playerid][pZPos]);
SetPlayerFacingAngle(playerid, PlayerInfo[playerid][pAPos]);
}
if(USE_EXISTING_MONEY == true)
{
ResetPlayerMoney(playerid);
GivePlayerMoney(playerid, PlayerInfo[playerid][pCash]);
}
}
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 i = 0; i < MAX_HOSPITALS; i++)
{
tmp_distance = GetPlayerDistanceFromPoint(playerid, hspawns[i][0], hspawns[i][1], hspawns[i][2]);
if (tmp_distance < distance)
{
distance = tmp_distance;
closest = i;
}
}
SetSpawnInfo(playerid, NO_TEAM, GetPlayerSkin(playerid), hspawns[closest][0],hspawns[closest][1],hspawns[closest][2],hspawns[closest][3], 0, 0, 0, 0, 0, 0);
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.