SA-MP Forums Archive
Spawn at nearest hospital script not working. - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Spawn at nearest hospital script not working. (/showthread.php?tid=497615)



Spawn at nearest hospital script not working. - Aerotactics - 27.02.2014

I came to this subforum previously for a similar script, but I rewrote the script and it still isn't working like it should. It only spawns me at 1 of the 2 hospitals, even if I'm standing right at the other hospital. I plan on adding a third hospital, but can't do that if the first script doesn't work.

pawn Код:
new Float:hos[2];

stock SpawnToHospital(playerid)
{
    dead[playerid] = 0;
    hos[0] =GetPlayerDistanceFromPoint(playerid, 2034.1670,-1406.0623,17.2181);
    hos[1] =GetPlayerDistanceFromPoint(playerid, 1177.3391,-1324.2300,14.0658);
    //hos[2] = GetPlayerDistanceFromPoint(playerid, 1177.3391,-1324.2300,14.0658);
    if (hos[0] < hos[1])
    {
        SetPlayerPos(playerid, 2034.1670,-1406.0623,17.2181);
        SetPlayerFacingAngle(playerid, 125);
        SetCameraBehindPlayer(playerid);
        print("hos 0 is closer");
    }
    if (hos[0] > hos[1])
    {
        SetPlayerPos(playerid, 1177.3391,-1324.2300,14.0658);
        SetPlayerFacingAngle(playerid, 90);
        SetCameraBehindPlayer(playerid);
        print("hos 1 is closer");
    }
    return 1;
}



Re: Spawn at nearest hospital script not working. - Aerotactics - 27.02.2014

Bump Please Help.


Re: Spawn at nearest hospital script not working. - Miado_Hulk - 27.02.2014

pawn Код:
stock SpawnToHospital(playerid)
{
    dead[playerid] = 0;
    hos[0] =GetPlayerDistanceFromPoint(playerid, 2034.1670,-1406.0623,17.2181);
    hos[1] =GetPlayerDistanceFromPoint(playerid, 1177.3391,-1324.2300,14.0658);
    //hos[2] = GetPlayerDistanceFromPoint(playerid, 1177.3391,-1324.2300,14.0658);
    if (hos[0]<= hos[1])
    {
        SetPlayerPos(playerid, 2034.1670,-1406.0623,17.2181);
        SetPlayerFacingAngle(playerid, 125);
        SetCameraBehindPlayer(playerid);
        print("hos 0 is closer");
    }
    else
    {
        SetPlayerPos(playerid, 1177.3391,-1324.2300,14.0658);
        SetPlayerFacingAngle(playerid, 90);
        SetCameraBehindPlayer(playerid);
        print("hos 1 is closer");
    }
    return 1;
}



Re: Spawn at nearest hospital script not working. - Aerotactics - 27.02.2014

Quote:
Originally Posted by Miado_Hulk
Посмотреть сообщение
pawn Код:
stock SpawnToHospital(playerid)
{
    dead[playerid] = 0;
    hos[0] =GetPlayerDistanceFromPoint(playerid, 2034.1670,-1406.0623,17.2181);
    hos[1] =GetPlayerDistanceFromPoint(playerid, 1177.3391,-1324.2300,14.0658);
    //hos[2] = GetPlayerDistanceFromPoint(playerid, 1177.3391,-1324.2300,14.0658);
    if (hos[0]<= hos[1])
    {
        SetPlayerPos(playerid, 2034.1670,-1406.0623,17.2181);
        SetPlayerFacingAngle(playerid, 125);
        SetCameraBehindPlayer(playerid);
        print("hos 0 is closer");
    }
    else
    {
        SetPlayerPos(playerid, 1177.3391,-1324.2300,14.0658);
        SetPlayerFacingAngle(playerid, 90);
        SetCameraBehindPlayer(playerid);
        print("hos 1 is closer");
    }
    return 1;
}
Nope, but thanks for trying.


Re: Spawn at nearest hospital script not working. - Aerotactics - 28.02.2014

Bump


Re: Spawn at nearest hospital script not working. - FalconWingsX - 28.02.2014

Try this method.
pawn Код:
// TOP of the script
new RespawnLocation[MAX_PLAYERS];
Place this under OnPlayerSpawn
pawn Код:
if(RespawnLocation[playerid] == 1)
    {
        SetPlayerPos(playerid, 1177.3391,-1324.2300,14.0658);
        SetPlayerFacingAngle(playerid, 90);
        SetCameraBehindPlayer(playerid);
        print("hos 1 is closer");
    } else {
        SetPlayerPos(playerid, 2034.1670,-1406.0623,17.2181);
        SetPlayerFacingAngle(playerid, 125);
        SetCameraBehindPlayer(playerid);
        print("hos 0 is closer");
    }

pawn Код:
stock RespawnToHospital(playerid)
{
    new Float:hos[2];
    hos[0] = GetPlayerDistanceFromPoint(playerid, 2034.1670, -1406.0623, 17.2181);
    hos[1] = GetPlayerDistanceFromPoint(playerid, 1177.3391, -1324.2300, 14.0658);
    if (hos[0]<= hos[1])
    {
        RespawnLocation[playerid] = 0;
    }
    else
    {
        RespawnLocation[playerid] = 1;
    }
    return 1;
}
NOTE: since RespawnLocation isnt defined on OnPlayerConnect, the player will spawn in the second defined hospital, you might want to fix this.


Re: Spawn at nearest hospital script not working. - Aerotactics - 28.02.2014

Quote:
Originally Posted by FalconWingsX
Посмотреть сообщение
Try this method.

NOTE: since RespawnLocation isnt defined on OnPlayerConnect, the player will spawn in the second defined hospital, you might want to fix this.
I implemented your script and it works like a charm (after a minor bugfix on my end)! Thanks! +Rep


Re: Spawn at nearest hospital script not working. - AmazonSK - 27.03.2014

What if I want more than 2 hospitals?