SA-MP Forums Archive
Distance between Floats not working - 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 Floats not working (/showthread.php?tid=360756)



Distance between Floats not working - Jstylezzz - 18.07.2012

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?


Re: Distance between Floats not working - Vince - 18.07.2012

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));
}



Re: Distance between Floats not working - Jstylezzz - 18.07.2012

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)



Re: Distance between Floats not working - Vince - 18.07.2012

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


Re: Distance between Floats not working - Jstylezzz - 18.07.2012

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