SA-MP Forums Archive
M -->/Kms - 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: M -->/Kms (/showthread.php?tid=618161)



M -->/Kms - CannonBolt - 02.10.2016

Hey i got this code.

Код:
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;
}
Thing is now how do i convert it to KMs? if a player is 1000m from another player it will show as Distance: 1.2 KM


Re: M -->/Kms - DTV - 02.10.2016

If I'm not mistaken, if you want to convert it into km, just divide the result by 1000 as 1 km is 1000m.


Re: M -->/Kms - CannonBolt - 02.10.2016

Quote:
Originally Posted by DTV
Посмотреть сообщение
If I'm not mistaken, if you want to convert it into km, just divide the result by 1000 as 1 km is 1000m.
this is just a "/" right?

Also what about getting it as a decimal? 1.2 KM


Re: M -->/Kms - Threshold - 02.10.2016

"/" is divide. It doesn't matter how you use it, it's about how you format the string.


Re: M -->/Kms - CannonBolt - 02.10.2016

Could you explain a bit more.

1000m = 1Km
Код:
if(pDistance = 1-999)
TextDrawSetString(PlDis,Dis: %.0f%% M);

else if(pDistance = 1000 / 1000)
TextDrawSetString(PlDis,Dis: %.0f% KM);
This is right?

Output:
0 M
0.0 KM

I suck on conversions.


Re: M -->/Kms - ISmokezU - 02.10.2016

Quote:
Originally Posted by CannonBolt
Посмотреть сообщение
Could you explain a bit more.

1000m = 1Km
Код:
if(pDistance = 1-999)
TextDrawSetString(PlDis,Dis: %.0f%% M);

else if(pDistance = 1000 / 1000)
TextDrawSetString(PlDis,Dis: %.0f% KM);
This is right?

Output:
0 M
0.0 KM

I suck on conversions.
Yes you need a float value after converting the ms,also A 1000/1000 = 1.


Re: M -->/Kms - Shaheen - 02.10.2016

u need to use float function if u want to get in decimal


Re: M -->/Kms - CannonBolt - 02.10.2016

Above you,^^. what i want to know is how to convert it!


Re: M -->/Kms - DTV - 02.10.2016

You convert it like:

pawn Код:
new exampleint = 4,Float:floatvalue;
floatvalue = float(exampleint); //this is how you convert it



Re: M -->/Kms - CannonBolt - 02.10.2016

Quote:
Originally Posted by DTV
Посмотреть сообщение
You convert it like:

pawn Код:
new exampleint = 4,Float:floatvalue;
floatvalue = float(exampleint); //this is how you convert it
Its give an error.