[Help] Hospital System
#6

Oh sorry, i misread your post then.
Create a new variable again then:
pawn Code:
new ClosestHospital[MAX_PLAYERS];
Then create a switch to check what has been put in the variable, under OnPlayerSpawn:
pawn Code:
public OnPlayerSpawn(playerid)
{
    switch(ClosestHospital[playerid])
    {
        case 0: SetPlayerPos(playerid, /* Insert coordinates of hospital 0*/);
        case 1: SetPlayerPos(playerid, /* Insert coordinates of hospital 1*/);
        case 2: SetPlayerPos(playerid, /* Insert coordinates of hospital 2*/);
    }
    return 1;
}
Then we need to check which is the closest of these 3 hospitals, and then store 0, 1 or 2 in the variable.
We can do that with this stock:
pawn Code:
stock RespawnToHospital(playerid)
{
    new Float:Hospital[3]; // Creates 3 floats, which we then use underneath to check the distance the player has from those points
    Hospital[0] = GetPlayerDistanceFromPoint(playerid,/* Insert coordinates of hospital 0 here */);
    Hospital[1] = GetPlayerDistanceFromPoint(playerid, /* Insert coordinates of hospital 1 here */);
    Hospital[2] = GetPlayerDistanceFromPoint(playerid, /* Insert coordinates of hospital 2 here */);
    if(Hospital[0] <= Hospital[1] && Hospital[0] <= Hospital[3]) // We use this to detect if hospital 0 is closer than both other
    {
        ClosestHospital[playerid] = 0; // We store "0" in the variable if hospital 0 is closest
    }
    else if(Hospital[1] <= Hospital[0] && Hospital[1] <= Hospital[3]) // If hospital 0 isn't closest, we check hospital 1, if that's closer than both the other
    {
        ClosestHospital[playerid] = 1; // We store "1" in the variable if hospital 0 is closest
    }
    else if(Hospital[2] <= Hospital[0] && Hospital[2] <= Hospital[1]) // If none of those are closest, we check if hospital 2 is closest.
    {
        ClosestHospital[playerid] = 2; // We store "2" in the variable if hospital 0 is closest
    }
    return 1;
}
And then we call this stock by putting this under OnPlayerDeath:
pawn Code:
RespawnToHospital(playerid);
Reply


Messages In This Thread
[Help] Hospital System - by Arxalan - 11.01.2015, 04:59
Re: [Help] Hospital System - by Michael B - 11.01.2015, 05:42
Re: [Help] Hospital System - by Arxalan - 11.01.2015, 06:22
Re: [Help] Hospital System - by CalvinC - 11.01.2015, 08:19
Re: [Help] Hospital System - by Arxalan - 11.01.2015, 08:28
Re: [Help] Hospital System - by CalvinC - 11.01.2015, 08:56
Re: [Help] Hospital System - by Arxalan - 11.01.2015, 12:53
Re: [Help] Hospital System - by CalvinC - 11.01.2015, 15:16

Forum Jump:


Users browsing this thread: 2 Guest(s)