Distance between players
#1

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
Reply
#2

Can you show the function GetDistanceBetweenPlayers?
Reply
#3

Код 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
Reply
#4

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?
Reply
#5

can you say if is something wrong with those functions ?

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

Код:
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?
Reply
#7

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;
Reply
#8

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

yea it worked , thx my friend +1 rep
Reply
#10

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..
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)