SA-MP Forums Archive
Closet Distance! [REP] - 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: Closet Distance! [REP] (/showthread.php?tid=587954)



Closet Distance! [REP] - zeth98 - 04.09.2015

I have 5 coordonate and how I check who is closet from me?

I try this but I don't know how to make

Код HTML:
GetClosetcoordonate(playerid)
{
	new Float:distance,Float:distance2;
    distance = GetPlayerDistanceFromPoint(playerid, 1929.37,-1776.23,13.546);
	if(distance>nextdistance)
    distance = GetPlayerDistanceFromPoint(playerid,1833.11,-1842.56,13.578);
    distance = GetPlayerDistanceFromPoint(playerid,1833.11,-1842.56,13.578);
    distance = GetPlayerDistanceFromPoint(playerid,1533.11,-842.56,3.578);
    distance = GetPlayerDistanceFromPoint(playerid,-53.11,-12.56,6.578);
    return DistanceCloset;
}



Re: Closet Distance! [REP] - Battlezone - 04.09.2015

Not tested, you may try this, it will send you a message ingame with the closest spot coordinates (there are more optimized ways to this)
Код:
GetClosestCoordinate(playerid)
{
	new Float:dist, whichone;
	dist = GetPlayerDistanceFromPoint(playerid, 1929.37,-1776.23,13.546;
	whichone = 1;
	if(dist < GetPlayerDistanceFromPoint(playerid, 1833.11,-1842.56,13.578))
	{
		dist = GetPlayerDistanceFromPoint(playerid, 1833.11,-1842.56,13.578);
		whichone = 2;
	}
	if(dist < GetPlayerDistanceFromPoint(playerid,1833.11,-1842.56,13.578))
	{
		dist = GetPlayerDistanceFromPoint(playerid,1833.11,-1842.56,13.578);
		whichone = 3;
	}
	if(dist < GetPlayerDistanceFromPoint(playerid,1533.11,-842.56,3.578))
	{
		dist = GetPlayerDistanceFromPoint(playerid,1533.11,-842.56,3.578);
		whichone = 4;
	}
	if(dist < GetPlayerDistanceFromPoint(playerid,-53.11,-12.56,6.578)) whichone = 5;
	switch(whichone)
	{
		case 1: return SendClientMessage(playerid, -1, "Closest coords are : 1929.37,-1776.23,13.546;
		case 2: return SendClientMessage(playerid, -1, "Closest coords are : 1833.11,-1842.56,13.578;
		case 3: return SendClientMessage(playerid, -1, "Closest coords are : 1833.11,-1842.56,13.578;
		case 4: return SendClientMessage(playerid, -1, "Closest coords are : 1533.11,-842.56,3.578;
		case 5: return SendClientMessage(playerid, -1, "Closest coords are : -53.11,-12.56,6.578;
	}
}



Re: Closet Distance! [REP] - zeth98 - 04.09.2015

I want to setme a checkpint at closetcoordonate from that 5 , that function it's wrong.
in whichone 1 with who compare the distance?


Re: Closet Distance! [REP] - Battlezone - 04.09.2015

You did not talk about checkpoints at all in your topic, you should have explained from the beginning..
And the whichone = 1; means that the closest coords are the first ones by default, if there are closer coords they will be set instead of the first ones, anyway:
Код:
GetClosestCoordinate(playerid)
{
	new Float:dist, whichone;
	dist = GetPlayerDistanceFromPoint(playerid, 1929.37,-1776.23,13.546;
	whichone = 1;
	if(dist < GetPlayerDistanceFromPoint(playerid, 1833.11,-1842.56,13.578))
	{
		dist = GetPlayerDistanceFromPoint(playerid, 1833.11,-1842.56,13.578);
		whichone = 2;
	}
	if(dist < GetPlayerDistanceFromPoint(playerid,1833.11,-1842.56,13.578))
	{
		dist = GetPlayerDistanceFromPoint(playerid,1833.11,-1842.56,13.578);
		whichone = 3;
	}
	if(dist < GetPlayerDistanceFromPoint(playerid,1533.11,-842.56,3.578))
	{
		dist = GetPlayerDistanceFromPoint(playerid,1533.11,-842.56,3.578);
		whichone = 4;
	}
	if(dist < GetPlayerDistanceFromPoint(playerid,-53.11,-12.56,6.578)) whichone = 5;
	switch(whichone)
	{
		case 1: return SetPlayerCheckpoint(playerid, 1929.37,-1776.23,13.546, 2);
		case 2: return SetPlayerCheckpoint(playerid, 1833.11,-1842.56,13.578, 2);
		case 3: return SetPlayerCheckpoint(playerid, 1833.11,-1842.56,13.578, 2);
		case 4: return SetPlayerCheckpoint(playerid, 1533.11,-842.56,3.578, 2);
		case 5: return SetPlayerCheckpoint(playerid, -53.11,-12.56,6.578, 2);
	}
}
EDIT: I forgot to set the checkpoints size, edited the code


Re: Closet Distance! [REP] - Freezo - 04.09.2015

Quote:
Originally Posted by Battlezone
Посмотреть сообщение
You did not talk about checkpoints at all in your topic, you should have explained from the beginning..
And the whichone = 1; means that the closest coords are the first ones by default, if there are closer coords they will be set instead of the first ones, anyway:
Код:
GetClosestCoordinate(playerid)
{
	new Float:dist, whichone;
	dist = GetPlayerDistanceFromPoint(playerid, 1929.37,-1776.23,13.546;
	whichone = 1;
	if(dist < GetPlayerDistanceFromPoint(playerid, 1833.11,-1842.56,13.578))
	{
		dist = GetPlayerDistanceFromPoint(playerid, 1833.11,-1842.56,13.578);
		whichone = 2;
	}
	if(dist < GetPlayerDistanceFromPoint(playerid,1833.11,-1842.56,13.578))
	{
		dist = GetPlayerDistanceFromPoint(playerid,1833.11,-1842.56,13.578);
		whichone = 3;
	}
	if(dist < GetPlayerDistanceFromPoint(playerid,1533.11,-842.56,3.578))
	{
		dist = GetPlayerDistanceFromPoint(playerid,1533.11,-842.56,3.578);
		whichone = 4;
	}
	if(dist < GetPlayerDistanceFromPoint(playerid,-53.11,-12.56,6.578)) whichone = 5;
	switch(whichone)
	{
		case 1: return SetPlayerCheckpoint(playerid, 1929.37,-1776.23,13.546);
		case 2: return SetPlayerCheckpoint(playerid, 1833.11,-1842.56,13.578);
		case 3: return SetPlayerCheckpoint(playerid, 1833.11,-1842.56,13.578);
		case 4: return SetPlayerCheckpoint(playerid, 1533.11,-842.56,3.578);
		case 5: return SetPlayerCheckpoint(playerid, -53.11,-12.56,6.578);
	}
}
Код:
	if(dist < GetPlayerDistanceFromPoint(playerid, 1833.11,-1842.56,13.578))
	{
		dist = GetPlayerDistanceFromPoint(playerid, 1833.11,-1842.56,13.578);
		whichone = 2;
	}
	if(dist < GetPlayerDistanceFromPoint(playerid,1833.11,-1842.56,13.578))
	{
		dist = GetPlayerDistanceFromPoint(playerid,1833.11,-1842.56,13.578);
		whichone = 3;
	}
Same check, with different execution?


Re: Closet Distance! [REP] - Battlezone - 04.09.2015

Quote:
Originally Posted by Freezo
Посмотреть сообщение
Код:
	if(dist < GetPlayerDistanceFromPoint(playerid, 1833.11,-1842.56,13.578))
	{
		dist = GetPlayerDistanceFromPoint(playerid, 1833.11,-1842.56,13.578);
		whichone = 2;
	}
	if(dist < GetPlayerDistanceFromPoint(playerid,1833.11,-1842.56,13.578))
	{
		dist = GetPlayerDistanceFromPoint(playerid,1833.11,-1842.56,13.578);
		whichone = 3;
	}
Same check, with different execution?
I copy pasted the coordinates he gave me, check his post again


Re: Closet Distance! [REP] - Freezo - 04.09.2015

Even if he miss that, you should skip it.
lol, it make no sense.

Also the whichone variable is pointless. Take a look again, you can execute the function directly, without the switch.


Re: Closet Distance! [REP] - Battlezone - 04.09.2015

Quote:
Originally Posted by Freezo
Посмотреть сообщение
Even if he miss that, you should skip it.
lol, it make no since.

Also the whichone variable is pointless. Take a look again, you can execute the function directly, without the switch.
Well if you say so, reply with your code instead of pointing on useless things.
Also I won't remove that duplicate code as he asked for 5 coords and 2 of them were the same, it's not my problem


Re: Closet Distance! [REP] - Freezo - 04.09.2015

Quote:
Originally Posted by Battlezone
Посмотреть сообщение
Well if you say so, reply with your code instead of pointing on useless things.
Also I won't remove that duplicate code as he asked for 5 coords and 2 of them were the same, it's not my problem
Your code is just ... unreadable.



Re: Closet Distance! [REP] - Battlezone - 04.09.2015

Well you're right about one single thing, the fact that I forgot the checkpoint size float, +1 for that
otherwise go learn more basics and if you find a better way come back and suggest it here