Distance between Floats not working
#1

Hi everyone,

I made this function for my taxi system, but it isn't working..
Does anyone know why?
pawn Код:
forward FareUpdate(playerid);
public FareUpdate(playerid)
{

    new farestring[128];
    GetPlayerPos(playerid,NewX[playerid],NewY[playerid],NewZ[playerid]);
    new Float:XDifference[MAX_PLAYERS],Float:YDifference[MAX_PLAYERS], Float:ZDifference[MAX_PLAYERS];
    XDifference[playerid] = floatsub(OldX[playerid],NewX[playerid]);
    YDifference[playerid] = floatsub(OldY[playerid],NewY[playerid]);
    ZDifference[playerid] = floatsub(OldZ[playerid],NewZ[playerid]);
    if(XDifference[playerid] >= 100.0)
    {
    TotalFare[playerid]++;
    format(farestring,sizeof(farestring),"Total Fare: %d $",TotalFare[playerid]);
    TextDrawSetString(taxithisfare[playerid],farestring);
    GetOldPos(playerid);
    return 1;
    }
    else if(YDifference[playerid] >= 100.0)
    {
    TotalFare[playerid]++;
    format(farestring,sizeof(farestring),"Total Fare: %d $",TotalFare[playerid]);
    TextDrawSetString(taxithisfare[playerid],farestring);
    GetOldPos(playerid);
    return 1;
    }
    else if(ZDifference[playerid] >= 100.0)
    {
    TotalFare[playerid]++;
    format(farestring,sizeof(farestring),"Total Fare: %d $",TotalFare[playerid]);
    TextDrawSetString(taxithisfare[playerid],farestring);
    GetOldPos(playerid);
    return 1;
    }
   

   
   
    return 1;
   
}
forward GetOldPos(playerid);
public GetOldPos(playerid)
{
    GetPlayerPos(playerid,Float:OldX[playerid],Float:OldY[playerid],Float:OldZ[playerid]);
}
The FareUpdate is getting called every second..
The idea is, that if one of the float differences is 100 or more, it adds 1 to the TotalFare[playerid]
I used the return1; 's because i don't want to add 1 5 times

Does anyone know what i have to do here?
Reply
#2

Why don't you just use GetDistanceBetweenPoints instead of copying your code 3 times? Bad practice.

pawn Код:
stock Float:GetDistanceBetweenPoints(Float:x1, Float:y1, Float:z1, Float:x2, Float:y2, Float:z2)
{
    x1 -= x2;
    y1 -= y2;
    z1 -= z2;
    return floatsqroot((x1 * x1) + (y1 * y1) + (z1 * z1));
}
Reply
#3

Thanks Vince, I will remember this

!EDIT!:I get a tag mismatch while compiling,
Код:
warning 208: function with tag result used before definition, forcing reparse
it's this line:
pawn Код:
stock Float:GetDistanceBetweenPoints(Float:x1, Float:y1, Float:z1, Float:x2, Float:y2, Float:z2)
Reply
#4

pawn Код:
forward Float:GetDistanceBetweenPoints(Float:x1, Float:y1, Float:z1, Float:x2, Float:y2, Float:z2);
Add that.
Reply
#5

Quote:
Originally Posted by Vince
Посмотреть сообщение
pawn Код:
forward Float:GetDistanceBetweenPoints(Float:x1, Float:y1, Float:z1, Float:x2, Float:y2, Float:z2);
Add that.
Thanks alot man, it works
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)