Spawn nearest hospital
#1

I just made player spawn nearest hospital on death but doesn't work.

Full code:

pawn Код:
new bool:HospitalSpawn[MAX_PLAYERS];
Hospital coordinates:

pawn Код:
new Float:HospitalCoords[][4] =
{
    {2027.4375,-1421.0703,16.9922,137.2809}, // Los Santos Hospital
    {1177.9089,-1323.9611,14.0939,269.8222},  // Los Santos Hospital #2
    {1579.6106,1769.0625,10.8203,90.7178},  // Las Venturas Hospital
    {-321.8259,1056.7279,19.7422,316.0064}, // Fort Carson Hospital
    {-1514.8807,2527.8003,55.7315,358.6234},  // El Quebrados Hospital
    {-2662.0439,630.5056,14.4531,177.8114}, // San Fierro Hospital
    {-2199.2495,-2311.0444,30.6250,321.2772}, // Angel Pine Hospital
    {1244.1959,332.2817,19.5547,338.3063} // Montgomery Hospital
};
OnPlayerSpawn:

pawn Код:
if(HospitalSpawn[playerid])
    {
        HospitalSpawn[playerid] = false;
        new closest, Float:distance = 99999.9;
        for (new i, j = sizeof(HospitalCoords), Float:tmp_distance; i < j; i++)
        {
            tmp_distance = GetPlayerDistanceFromPoint(playerid, HospitalCoords[i][0], HospitalCoords[i][1], HospitalCoords[i][2]);
            if (tmp_distance < distance)
            {
                distance = tmp_distance;
                closest = i;
            }
        }
        SetSpawnInfo(playerid, GetPlayerTeam(playerid), GetPlayerSkin(playerid), HospitalCoords[closest][0], HospitalCoords[closest][1], HospitalCoords[closest][2], HospitalCoords[closest][3], 0, 0, 0, 0, 0, 0);
    }
    else
    {
        if(gTeam[playerid] == TEAM_CIV)
    {
        SetPlayerTeam(playerid,0);
        new rand = random(sizeof(RandomSpawnsLosSantos));
        SetPlayerPos(playerid, RandomSpawnsLosSantos[rand][0],RandomSpawnsLosSantos[rand][1],RandomSpawnsLosSantos[rand][2]);
    }
    }
OnPlayerDeath:

pawn Код:
HospitalSpawn[playerid] = true;
Instead of getting spawned at nearest hospital after death, i get spawned based on RandomSpawnsLosSantos coordinates.

What's wrong?
Reply
#2

Put this at the last line of OnPlayerSpawn (before })
PHP код:
    if(HospitalSpawn[playerid])
    {
        
HospitalSpawn[playerid] = false;
        new 
closestFloat:distance 99999.9;
        for (new 
isizeof(HospitalCoords), Float:tmp_distanceji++)
        {
            
tmp_distance GetPlayerDistanceFromPoint(playeridHospitalCoords[i][0], HospitalCoords[i][1], HospitalCoords[i][2]);
            if (
tmp_distance distance)
            {
                
distance tmp_distance;
                
closest i;
            }
        }
        
SetPlayerPos(playeridHospitalCoords[closest][0], HospitalCoords[closest][1], HospitalCoords[closest][2]);
        
SetPlayerFacingAngle(playerid,HospitalCoords[closest][3]);
        
SetCameraBehindPlayer(playerid);
        return 
1;
    }
    else
    {
        if(
gTeam[playerid] == TEAM_CIV)
        {
            
SetPlayerTeam(playerid,0);
            new 
rand random(sizeof(RandomSpawnsLosSantos));
            
SetPlayerPos(playeridRandomSpawnsLosSantos[rand][0],RandomSpawnsLosSantos[rand][1],RandomSpawnsLosSantos[rand][2]);
        }
    } 
Reply
#3

taktaz: Thanks but doesn't work...
Reply
#4

You are not calling the code. But you are toggling "True and False".

OnPlayerDeath:
Код:
gHospitalSpawn(playerid);
Код:
forward gHospitalSpawn(playerid);
public gHospitalSpawn(playerid)
{
    HospitalSpawn[playerid] = false;
    new closest, Float:distance = 99999.9;
    for (new i, j = sizeof(HospitalCoords), Float:tmp_distance; i < j; i++)
    {
        tmp_distance = GetPlayerDistanceFromPoint(playerid, HospitalCoords[i][0], HospitalCoords[i][1], HospitalCoords[i][2]);
        if (tmp_distance < distance)
        {
            distance = tmp_distance;
            closest = i;
        }
        }
        SetSpawnInfo(playerid, GetPlayerTeam(playerid), GetPlayerSkin(playerid), HospitalCoords[closest][0], HospitalCoords[closest][1], HospitalCoords[closest][2], HospitalCoords[closest][3], 0, 0, 0, 0, 0, 0);
    }
    else
    {
        if(gTeam[playerid] == TEAM_CIV)
	{
        SetPlayerTeam(playerid,0);
        new rand = random(sizeof(RandomSpawnsLosSantos));
		SetPlayerPos(playerid, RandomSpawnsLosSantos[rand][0],RandomSpawnsLosSantos[rand][1],RandomSpawnsLosSantos[rand][2]);
 	}
    }
    return 1;
}
Reply
#5

With that code the compiler crashes. Tried now.
Reply
#6

Quote:
Originally Posted by KinderClans
Посмотреть сообщение
taktaz: Thanks but doesn't work...
its because of some return 1; or errors that are upper than the code , that they dont let the script to be apply. you should check all lines in OnPlayerSpawn above this code or mb you can paste it at the first lines of OnPlayerSpawn
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)