SA-MP Forums Archive
Get nearest point - 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: Get nearest point (/showthread.php?tid=521625)



Get nearest point - cnoopers - 23.06.2014

yow i got few teleports and i wanna teleport player to closest of those. get player pos, compare it with that. how?


Re: Get nearest point - Konstantinos - 23.06.2014

https://sampwiki.blast.hk/wiki/GetPlayerDistanceFromPoint

The x, y, z in the function are the teleport's coordinates. The one returns the shortest distance is the closest one.


Re: Get nearest point - cnoopers - 24.06.2014

i still cant understand what i have to do
Код:
//OnPlayerSpawn
    if(Death[playerid] == 1)
    {
		new
		Float: Hospital1 = GetPlayerDistanceFromPoint(playerid, 2034.1149,-1414.9154,16.9922), //133.3335
		Float: Hospital2 = GetPlayerDistanceFromPoint(playerid, 1182.1077,-1324.0918,13.5815), //270.4434
		Float: Hospital3 = GetPlayerDistanceFromPoint(playerid, 1244.3423,331.9934,19.5547), //335.6859
		Float: Hospital4 = GetPlayerDistanceFromPoint(playerid, 1607.6090,1821.0934,10.8280), //0.7354
		Float: Hospital5 = GetPlayerDistanceFromPoint(playerid, -317.0090,1056.6217,19.7422), //358.9579
		Float: Hospital6 = GetPlayerDistanceFromPoint(playerid, -1514.7358,2527.0601,55.7455), //359.0611
		Float: Hospital7 = GetPlayerDistanceFromPoint(playerid, -2661.2441,633.7098,14.4531), //180.1544
		Float: Hospital8 = GetPlayerDistanceFromPoint(playerid, -2198.7803,-2306.5793,30.6250); //320.6338

    }
in comments is facing angles


Re: Get nearest point - Konstantinos - 24.06.2014

The value returned that you stored to variables is what we want. The lower that value is, the closest to the player. Using it as array will be easier:
pawn Код:
//OnPlayerSpawn
if(Death[playerid] == 1)
{
    new
        Float: HospitalDistance[8],
        closest = -1,
        Float: tmp_distance = -1.0;
   
    HospitalDistance[0] = GetPlayerDistanceFromPoint(playerid, 2034.1149,-1414.9154,16.9922);
    HospitalDistance[1] = GetPlayerDistanceFromPoint(playerid, 1182.1077,-1324.0918,13.5815);
    HospitalDistance[2] = GetPlayerDistanceFromPoint(playerid, 1244.3423,331.9934,19.5547);
    HospitalDistance[3] = GetPlayerDistanceFromPoint(playerid, 1607.6090,1821.0934,10.8280);
    HospitalDistance[4] = GetPlayerDistanceFromPoint(playerid, -317.0090,1056.6217,19.7422);
    HospitalDistance[5] = GetPlayerDistanceFromPoint(playerid, -1514.7358,2527.0601,55.7455);
    HospitalDistance[6] = GetPlayerDistanceFromPoint(playerid, -2661.2441,633.7098,14.4531);
    HospitalDistance[7] = GetPlayerDistanceFromPoint(playerid, -2198.7803,-2306.5793,30.6250);
   
    for (new i; i != sizeof (HospitalDistance); ++i)
    {
        if (HospitalDistance[i] > tmp_distance)
        {
            tmp_distance = HospitalDistance[i];
            closest = i;
        }
    }
   
    // set player's pos
    switch (closest)
    {
        case 0:
        {
            // 2034.1149,-1414.9154,16.9922
        }
        case 1:
        {
            // 1182.1077,-1324.0918,13.5815
        }
        case 2:
        {
            // 1244.3423,331.9934,19.5547
        }
        case 3:
        {
            // 1607.6090,1821.0934,10.8280
        }
        case 4:
        {
            // -317.0090,1056.6217,19.7422
        }
        case 5:
        {
            //-1514.7358,2527.0601,55.7455
        }
        case 6:
        {
            // -2661.2441,633.7098,14.4531
        }
        case 7:
        {
            // -2198.7803,-2306.5793,30.6250
        }
    }
}



Re: Get nearest point - cnoopers - 24.06.2014

Now, if i die i spawned on ganton with skin change buttons.
Код:
	if(Death[playerid] == 1)
	{
	    new
	        Float: HospitalDistance[8],
	        closest = -1,
	        Float: tmp_distance = -1.0;

	    HospitalDistance[0] = GetPlayerDistanceFromPoint(playerid, 2034.1149,-1414.9154,16.9922);
	    HospitalDistance[1] = GetPlayerDistanceFromPoint(playerid, 1182.1077,-1324.0918,13.5815);
	    HospitalDistance[2] = GetPlayerDistanceFromPoint(playerid, 1244.3423,331.9934,19.5547);
	    HospitalDistance[3] = GetPlayerDistanceFromPoint(playerid, 1607.6090,1821.0934,10.8280);
	    HospitalDistance[4] = GetPlayerDistanceFromPoint(playerid, -317.0090,1056.6217,19.7422);
	    HospitalDistance[5] = GetPlayerDistanceFromPoint(playerid, -1514.7358,2527.0601,55.7455);
	    HospitalDistance[6] = GetPlayerDistanceFromPoint(playerid, -2661.2441,633.7098,14.4531);
	    HospitalDistance[7] = GetPlayerDistanceFromPoint(playerid, -2198.7803,-2306.5793,30.6250);

	    for (new i; i != sizeof (HospitalDistance); ++i)
	    {
	        if (HospitalDistance[i] > tmp_distance)
	        {
	            tmp_distance = HospitalDistance[i];
	            closest = i;
	        }
	    }

	    // set player's pos
	    switch (closest)
	    {
	        case 0:
	        {
	            // 2034.1149,-1414.9154,16.9922
	            SetPlayerPos(playerid, 2034.1149,-1414.9154,16.9922);
	            SetPlayerFacingAngle(playerid, 133.3335);
	        }
	        case 1:
	        {
	            // 1182.1077,-1324.0918,13.5815
	            SetPlayerPos(playerid, 1182.1077,-1324.0918,13.5815);
	            SetPlayerFacingAngle(playerid, 270.4434);
	        }
	        case 2:
	        {
	            // 1244.3423,331.9934,19.5547
	            SetPlayerPos(playerid, 1244.3423,331.9934,19.5547);
	            SetPlayerFacingAngle(playerid, 335.6859);
	        }
	        case 3:
	        {
	            // 1607.6090,1821.0934,10.8280
	            SetPlayerPos(playerid, 1607.6090,1821.0934,10.8280);
	            SetPlayerFacingAngle(playerid, 0.7354);
	        }
	        case 4:
	        {
	            // -317.0090,1056.6217,19.7422
	            SetPlayerPos(playerid, -317.0090,1056.6217,19.7422);
	            SetPlayerFacingAngle(playerid, 358.9579);
	        }
	        case 5:
	        {
	            //-1514.7358,2527.0601,55.7455
	            SetPlayerPos(playerid, -1514.7358,2527.0601,55.7455);
	            SetPlayerFacingAngle(playerid, 359.0611);
	        }
	        case 6:
	        {
	            // -2661.2441,633.7098,14.4531
	            SetPlayerPos(playerid, -2661.2441,633.7098,14.4531);
	            SetPlayerFacingAngle(playerid, 180.1544);
	        }
	        case 7:
	        {
	            // -2198.7803,-2306.5793,30.6250
	            SetPlayerPos(playerid, -2198.7803,-2306.5793,30.6250);
	            SetPlayerFacingAngle(playerid, 320.6338);
	        }
	    }
	}



Re: Get nearest point - cnoopers - 24.06.2014

refresh


Re: Get nearest point - cnoopers - 24.06.2014

bump!


Re: Get nearest point - Crayder - 24.06.2014

You are supposed to wait 24 hours between bumps,

Can you show us the rest of OnPlayerSpawn? Nothing there would send you to class selection...


Re: Get nearest point - cnoopers - 24.06.2014

thats all, i have no char selection
Код:
public OnPlayerSpawn(playerid)
{

    new Random = random(sizeof(RandomMainSpawns));
    SetPlayerPos(playerid, RandomMainSpawns[Random][0], RandomMainSpawns[Random][1], RandomMainSpawns[Random][2]);
    SetPlayerFacingAngle(playerid, RandomMainSpawns[Random][3]);

    SetPlayerColor(playerid, 0xFFFFFF30);
	SetCameraBehindPlayer(playerid);
	TogglePlayerControllable(playerid, 1);
	TogglePlayerSpectating(playerid, 0);
	
	PlayerTextDrawShow(playerid, progresshud[playerid]);

	if(Death[playerid] == 1)
	{
	    ResetPlayerWeapons(playerid);
	    new
	        Float: HospitalDistance[8],
	        closest = -1,
	        Float: tmp_distance = -1.0;

	    HospitalDistance[0] = GetPlayerDistanceFromPoint(playerid, 2034.1149,-1414.9154,16.9922);
	    HospitalDistance[1] = GetPlayerDistanceFromPoint(playerid, 1182.1077,-1324.0918,13.5815);
	    HospitalDistance[2] = GetPlayerDistanceFromPoint(playerid, 1244.3423,331.9934,19.5547);
	    HospitalDistance[3] = GetPlayerDistanceFromPoint(playerid, 1607.6090,1821.0934,10.8280);
	    HospitalDistance[4] = GetPlayerDistanceFromPoint(playerid, -317.0090,1056.6217,19.7422);
	    HospitalDistance[5] = GetPlayerDistanceFromPoint(playerid, -1514.7358,2527.0601,55.7455);
	    HospitalDistance[6] = GetPlayerDistanceFromPoint(playerid, -2661.2441,633.7098,14.4531);
	    HospitalDistance[7] = GetPlayerDistanceFromPoint(playerid, -2198.7803,-2306.5793,30.6250);

	    for (new i; i != sizeof (HospitalDistance); ++i)
	    {
	        if (HospitalDistance[i] > tmp_distance)
	        {
	            tmp_distance = HospitalDistance[i];
	            closest = i;
	        }
	    }

	    // set player's pos
	    switch (closest)
	    {
	        case 0:
	        {
	            // 2034.1149,-1414.9154,16.9922
	            SetPlayerPos(playerid, 2034.1149,-1414.9154,16.9922);
	            SetPlayerFacingAngle(playerid, 133.3335);
	        }
	        case 1:
	        {
	            // 1182.1077,-1324.0918,13.5815
	            SetPlayerPos(playerid, 1182.1077,-1324.0918,13.5815);
	            SetPlayerFacingAngle(playerid, 270.4434);
	        }
	        case 2:
	        {
	            // 1244.3423,331.9934,19.5547
	            SetPlayerPos(playerid, 1244.3423,331.9934,19.5547);
	            SetPlayerFacingAngle(playerid, 335.6859);
	        }
	        case 3:
	        {
	            // 1607.6090,1821.0934,10.8280
	            SetPlayerPos(playerid, 1607.6090,1821.0934,10.8280);
	            SetPlayerFacingAngle(playerid, 0.7354);
	        }
	        case 4:
	        {
	            // -317.0090,1056.6217,19.7422
	            SetPlayerPos(playerid, -317.0090,1056.6217,19.7422);
	            SetPlayerFacingAngle(playerid, 358.9579);
	        }
	        case 5:
	        {
	            //-1514.7358,2527.0601,55.7455
	            SetPlayerPos(playerid, -1514.7358,2527.0601,55.7455);
	            SetPlayerFacingAngle(playerid, 359.0611);
	        }
	        case 6:
	        {
	            // -2661.2441,633.7098,14.4531
	            SetPlayerPos(playerid, -2661.2441,633.7098,14.4531);
	            SetPlayerFacingAngle(playerid, 180.1544);
	        }
	        case 7:
	        {
	            // -2198.7803,-2306.5793,30.6250
	            SetPlayerPos(playerid, -2198.7803,-2306.5793,30.6250);
	            SetPlayerFacingAngle(playerid, 320.6338);
	        }
	    }
	}
	
    return 1;
}



Re: Get nearest point - cnoopers - 25.06.2014

reff