SA-MP Forums Archive
Distance between players - 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: Distance between players (/showthread.php?tid=616681)



Distance between players - StR_MaRy - 09.09.2016

Hey guys i have a find sistem and i have a textdraw everything works but i put this function under

Код HTML:
task OtherTimer[1000]()
{
    foreach(new i : Player)
	{
	    if(UseFind[i] == 1)
		{
		    new string[120];
		    new Float: distance;
		    distance = GetDistanceBetweenPlayers(i, targetfind[i]);
		    format(string, sizeof(string), "Distanta ramasa: %.0f metri", distance);
			PlayerTextDrawSetString(i, FindTimerTxT[i], string);
			PlayerTextDrawShow(i, FindTimerTxT[i]);
		}
		else
		{
		    PlayerTextDrawHide(i, FindTimerTxT[i]);
		}
	}
    return 1;
}
what is wrong why i get in textdraw "Distanta ramasa: 0 metri" , that is 0 metters from me and that player and he is in SF and i am on LS


Re: Distance between players - thefirestate - 09.09.2016

Can you show the function GetDistanceBetweenPlayers?


Re: Distance between players - StR_MaRy - 09.09.2016

Код HTML:
function Float:GetDistanceBetweenPlayers(playerid,targetplayerid)
{
    new Float:x1,Float:y1,Float:z1,Float:x2,Float:y2,Float:z2;
    if(!IsPlayerConnected(playerid) || !IsPlayerConnected(targetplayerid)) {
        return -1.00;
    }
    GetPlayerPos(playerid,x1,y1,z1);
    GetPlayerPos(targetplayerid,x2,y2,z2);
    return floatsqroot(floatpower(floatabs(floatsub(x2,x1)),2)+floatpower(floatabs(floatsub(y2,y1)),2)+floatpower(floatabs(floatsub(z2,z1)),2));
}
this is it


Re: Distance between players - thefirestate - 09.09.2016

Why don't you get the position of the targetplayerid with GetPlayerPos and then use GetPlayerDistanceFromPoint using the main playerid and the position of the targetplayerid then return the distance from the function?


Re: Distance between players - StR_MaRy - 09.09.2016

can you say if is something wrong with those functions ?

if is yes can you help me up ? with more details


Re: Distance between players - thefirestate - 09.09.2016

Код:
GetDistanceBetweenPlayers(playera, playerb)
{
    if(!IsPlayerConnected(playera) || !IsPlayerConnected(playerb))
    {
        return -1.00;
    }
    new Float:pPos[3], Float:pDistance;
    GetPlayerPos(playerb, pPos[0], pPos[1], pPos[2]);
    pDistance = GetPlayerDistanceFromPoint(playera, pPos[0], pPos[1], pPos[2]);
    return pDistance;
}
Can you try with this code?


Re: Distance between players - StR_MaRy - 09.09.2016

i get this error's

Код HTML:
C:\Users\StR\Desktop\Scripting\snake\gamemodes\server.pwn(36920) : warning 217: loose indentation
C:\Users\StR\Desktop\Scripting\snake\gamemodes\server.pwn(36922) : warning 213: tag mismatch
C:\Users\StR\Desktop\Scripting\snake\gamemodes\server.pwn(36923) : warning 213: tag mismatch
Код HTML:
line 36920: new Float:pPos[3], pDistance;
line 36922: pDistance = GetPlayerDistanceFromPoint(playera, pPos[0], pPos[1], pPos[2]);
line 36923: return pDistance;



Re: Distance between players - thefirestate - 09.09.2016

OOps, updated it. Sorry haven't tested it in a pawno compiler. It should work now.


Re: Distance between players - StR_MaRy - 09.09.2016

yea it worked , thx my friend +1 rep


Re: Distance between players - ISmokezU - 09.09.2016

Quote:
Originally Posted by thefirestate
Посмотреть сообщение
Код:
GetDistanceBetweenPlayers(playera, playerb)
{
    if(!IsPlayerConnected(playera) || !IsPlayerConnected(playerb))
    {
        return -1.00;
    }
    new Float:pPos[3], Float:pDistance;
    GetPlayerPos(playerb, pPos[0], pPos[1], pPos[2]);
    pDistance = GetPlayerDistanceFromPoint(playera, pPos[0], pPos[1], pPos[2]);
    return pDistance;
}
Can you try with this code?
Hey what would i've to do to set a textdraw string with this code and get the distance in either m / km "Distance 346 M" / "Distance 1.9 KM" Thanks..