PDA

View Full Version : Race Progress

GSFBart
25/06/2017, 09:11 PM
How do I calculate the percentage of player progress in a race? I tried with TotalCP - 1, but it does not work properly ._.

forward Float:GetCPPercentage(playerid);
public Float:GetCPPercentage(playerid)
{
if(CPProgress[playerid] != 0)
{
new Float:Dist;

Dist = ((GetPlayerDistanceFromPoint(playerid, CPCoords[TotalCP - 1][0], CPCoords[TotalCP - 1][1], CPCoords[TotalCP - 1][2]) * 100.0) / DistAllCP);

CPPercentage[playerid] = 100.0 - Dist;
}
return CPPercentage[playerid];
}

for(new i = 0; i != TotalCP; i++)
{
if(i != TotalCP - 1) DistAllCP = DistAllCP + GetDistance(CPCoords[i][0], CPCoords[i][1], CPCoords[i][2], CPCoords[i + 1][0], CPCoords[i + 1][1], CPCoords[i + 1][2]);
}

#define GetDistance(%1,%2,%3,%4,%5,%6) floatsqroot((%1-%4)*(%1-%4) + (%2-%5)*(%2-%5) + (%3-%6)*(%3-%6))

GSFBart
26/06/2017, 04:38 PM
UP .-.

Jefff
27/06/2017, 12:36 AM
Something like this, basic code

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

GSFBart
01/07/2017, 02:26 PM
Thanks :)