Race Progress
#1

How do I calculate the percentage of player progress in a race? I tried with TotalCP - 1, but it does not work properly ._.

PHP код:
forward Float:GetCPPercentage(playerid);
public 
Float:GetCPPercentage(playerid)
{
    if(
CPProgress[playerid] != 0)
    {
        new 
Float:Dist;
        
Dist = ((GetPlayerDistanceFromPoint(playeridCPCoords[TotalCP 1][0], CPCoords[TotalCP 1][1], CPCoords[TotalCP 1][2]) * 100.0) / DistAllCP);
        
CPPercentage[playerid] = 100.0 Dist;
    }
    return 
CPPercentage[playerid];

PHP код:
for(new 0!= TotalCPi++)
{    
    if(
!= TotalCP 1DistAllCP DistAllCP GetDistance(CPCoords[i][0], CPCoords[i][1], CPCoords[i][2], CPCoords[1][0], CPCoords[1][1], CPCoords[1][2]);

PHP код:
#define     GetDistance(%1,%2,%3,%4,%5,%6)     floatsqroot((%1-%4)*(%1-%4) + (%2-%5)*(%2-%5) + (%3-%6)*(%3-%6)) 
Reply
#2

UP .-.
Reply
#3

Something like this, basic code

pawn Код:
/// top
new Float:MaxDistance;
new Float:FullDistance[sizeof(CPCoords));

Float:GetDistanceBetweenPoints(Float:x1, Float:y1, Float:z1, Float:x2, Float:y2, Float:z2)
    return VectorSize(x1-x2, y1-y2, z1-z2);

// when race start
MaxDistance = 0.0;
for(new i = 0; i < TotalCP-1; i++)
{
    FullDistance[i+1] = GetDistanceBetweenPoints(CPCoords[i][0], CPCoords[i][1], CPCoords[i][2], CPCoords[i + 1][0], CPCoords[i + 1][1], CPCoords[i + 1][2]);
    MaxDistance += FullDistance[i+1];
}

// when player enter race checkpoint
CPPercentage[playerid] += FullDistance[ CPProgress[playerid] ]; // CPProgress must be checkpointid 0,1,2,...

// somewhere
forward Float:GetCPPercentage(playerid);
public Float:GetCPPercentage(playerid)
{
    new Float:CP_Percentage = 100.0 - ( MaxDistance - CPPercentage[playerid] );
    return CP_Percentage;
}
Reply
#4

Thanks
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)