Nearest Hospital Respawn
#1

Hello There Im Trying To Make A Script Upon Death That they will respawn to the nearest hosipital...
But Want It As A New Variable How Would I Go About Doing This.. So It Calculates Player Position To The Nearest Hosipital
Reply
#2

Simple way is to set ranges.Like check under OnPlayerDeath,check if player position if bla bla,setplayerpos.and use if statements.
Reply
#3

Soo far I got this code but I want to be able to check the nearest hosipital

public OnPlayerDeath(playerid, killerid, reason)
{
new Float, Float:y, Float:z;
GetPlayerPos(playerid, x, y, z);
Reply
#4

Thanks To Talha XIV He gave Me A Code For OnPlayerDeath And What It Does It Just Sends Me To That Location When I Die But Doesn't Respawn Me To There ,,, So I Tweaked The Code A Little And Got This Code Below ,, But Now When I Die I Only Respawn To El Quebrados Medical Centre .. I Want This Code To Check if PlayerIsInRange Of The Nearest Hospital And Then Respawn Me To The Nearest Hospital , Can Anybody Help Me Please...
Quote:

new dead[MAX_PLAYERS]; Top Of Script
public OnPlayerConnect(playerid)
{
dead[playerid] = 0;
///Player Map Icons///
//Police Stations //
SetPlayerMapIcon(playerid, 1, 1555.5007, -1675.7805, 16.1953, 30, 0, MAPICON_LOCAL);//Los Santos PD HQ
SetPlayerMapIcon(playerid, 2, -2161.3547, -2384.7849, 30.8939, 30, 0, MAPICON_LOCAL);//AngelPine Sheriff PD HQ
SetPlayerMapIcon(playerid, 3, 2290.1460, 2432.0879, 10.8203, 30, 0, MAPICON_LOCAL);//Las Venturas PD HQ 3LVLS PARKING LOT
SetPlayerMapIcon(playerid, 4, -1388.7845, 2638.2061, 55.9844, 30, 0, MAPICON_LOCAL);//El Quedbrados Sheriff PD HQ
SetPlayerMapIcon(playerid, 5, -217.8340, 979.1722, 19.5040, 30, 0, MAPICON_LOCAL);//Fort Carson Sheriff PD HQ
SetPlayerMapIcon(playerid, 6, -1605.7604, 710.2723, 13.8672, 30, 0, MAPICON_LOCAL);//San Fierro Downtown PD HQ
SetPlayerMapIcon(playerid, 7, 626.9676, -571.4230, 17.9207, 30, 0, MAPICON_LOCAL);//Dillimore PD HQ
// Fire Stations //
SetPlayerMapIcon(playerid, 8, -2026.9122, 67.5129, 28.6916, 20, 0, MAPICON_LOCAL);//San Fierro Fire Department
SetPlayerMapIcon(playerid, 9, 1761.6390, 2081.5706, 10.8203, 20, 0, MAPICON_LOCAL);//Las Venturas Fire Department
// Hospitals //
SetPlayerMapIcon(playerid, 10, 1604.6643, 1815.2538, 10.8203, 22, 0, MAPICON_LOCAL);//Las Venturas Hospital
SetPlayerMapIcon(playerid, 11, -1513.4323, 2518.9666, 56.0703, 22, 0, MAPICON_LOCAL);//El Quebrados Medical Centre
SetPlayerMapIcon(playerid, 12, 2034.3083, -1401.6720, 17.2961, 22, 0, MAPICON_LOCAL);//County General Los Santos Hospital
SetPlayerMapIcon(playerid, 13, 1172.0804, -1325.2925, 15.4073, 22, 0, MAPICON_LOCAL);//All Saints General Hospital
SetPlayerMapIcon(playerid, 14, -319.7292, 1048.2355, 20.3403, 22, 0, MAPICON_LOCAL);//Fort Carson Medical Center
SetPlayerMapIcon(playerid, 15, -2655.0598, 640.1436, 14.4545, 22, 0, MAPICON_LOCAL);//San Fierro Medical Centrum
SetPlayerMapIcon(playerid, 16, -2203.9302, -2309.3950, 31.3750, 22, 0,MAPICON_LOCAL);//Angel Pine Medical Center
return true;
}
public OnPlayerSpawn(playerid)
{
if(dead[playerid] == 1)
{
IsPlayerInRangeOfPoint(playerid,20000.0,1604.6643, 1815.2538,10.8203);
SetPlayerPos(playerid,1604.6643,1815.2538,10.8203) ; //Las Venturas Hospital
IsPlayerInRangeOfPoint(playerid,20000.0,-1513.4323,2518.9666,56.0703);
SetPlayerPos(playerid,-1513.4323,2518.9666,56.0703);//El Quebrados Medical Centre

}
else
{
SetPlayerPos(playerid,1958.3783, 1343.1572, 15.3746); //Spawn1
return 1;
}
return 1;
}
public OnPlayerDeath(playerid, killerid, reason)
{
dead[playerid] = 1;
return 1;
}

Reply
#5

The Best option is adding random spawns on the hospital.
Reply
#6

Try increasing the range like 20000 to the value to need.
Reply
#7

I'd use sth like this:

PHP код:
enum hospital_
{
    
Float:h_X,
    
Float:h_Y,
    
Float:h_Z
};
new 
Hospitals[][hospital_] =
{
    {
0.00.00.0}, // list of hospital coords
    
{123.0456.0789.0},
    {
500.0500.0500.0}
};
stock Float:PlayerDistanceToPoint(playeridFloat:_xFloat:_yFloat:_z)
{
    new 
Float:Coo[3];
    
GetPlayerPos(playerid,Coo[0],Coo[1],Coo[2]);
    return 
floatsqroot(((Coo[0] - _x) * (Coo[0] - _x)) + ((Coo[1] - _y) * (Coo[1] - _y)) + ((Coo[2] - _z) * (Coo[2] - _z)));        
}
stock ClosestHospital(playerid)
{
    new 
hospitalidFloat:closest PlayerDistanceToPoint(playeridHospitals[0][h_X], Hospitals[0][h_Y], Hospitals[0][h_Z];
    for(new 
i=1i<sizeof(Hospitals); i++)
    {
        if(
PlayerDistanceToPoint(playeridHospitals[i][h_X], Hospitals[i][h_Y], Hospitals[i][h_Z]) < closest)
        {
            
closest PlayerDistanceToPoint(playeridHospitals[i][h_X], Hospitals[i][h_Y], Hospitals[i][h_Z]);
            
hospitalid i;
        }
    }
    return 
hospitalid;
}
public 
OnPlayerDeath(playeridkilleridreason)
{
    
SetPVarInt(playerid"Dead"1);
    
SetPVarInt(playerid"Hospital"ClosestHospital(playerid));
}
public 
OnPlayerSpawn(playerid)
{
    if(
GetPVarInt(playerid"Dead"))
    {
        new 
hid GetPVarInt(playerid"Hospital");
        
SetPlayerInterior(playerid0);
        
SetPlayerVirtualWorld(playerid0);
        
SetPlayerPos(playeridHospitals[hid][h_X], Hospitals[hid][h_Y], Hospitals[hid][h_Z]);
        
SetPVarInt(playerid"Dead"0);
    }

Not sure if it works..
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)