M -->/Kms
#1

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

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

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

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

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

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

u need to use float function if u want to get in decimal
Reply
#8

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

You convert it like:

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

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


Forum Jump:


Users browsing this thread: 1 Guest(s)