Dravizz

Untitled

Oct 30th, 2020
866
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2.  
  3. enum e_RACE_CHECKPOINT_DATA
  4. {
  5.     PlayerId,
  6.     CheckpointCount,
  7.     CheckpointTime
  8. };
  9.  
  10. new RacePositionData[MAX_PLAYERS][e_RACE_CHECKPOINT_DATA] = {{-1, ...}, ...};
  11.  
  12.  
  13. hook OnPlayerEnterRaceCP(playerid)
  14. {
  15.     if(RaceParticipant[playerid]>=1)
  16.     {
  17.         if( if(RaceStart==1)
  18.         {
  19.             PlayerPlaySound(playerid, 1138,0.0,0.0,0.0);
  20.             SetNextCheckpoint(playerid);
  21.             UpdateRaceTable();
  22.         }
  23.     }
  24.     return 1;
  25. }
  26. function SetNextCheckpoint(playerid)
  27. {
  28.     CurrentCheckpoint[playerid]++;
  29.     RacePositionData[playerid][CheckpointCount]++;
  30.     RacePositionData[playerid][CheckpointTime] = GetTickCount();
  31.  
  32. BubbleSortRace(yourArraySize)
  33. {
  34.     for(new i = 0; i < yourArraySize - 1; i++)
  35.     {
  36.         new swapped = false;
  37.         for(new j = 0; j < yourArraySize - 1 - i; j++)
  38.         {
  39.             if(RacePositionData[j][CheckpointCount] > RacePositionData[j + 1][CheckpointCount])
  40.             {
  41.                 swapValues(RacePositionData[j][CheckpointCount], RacePositionData[j + 1][CheckpointCount]);
  42.                 swapValues(RacePositionData[j][CheckpointTime], RacePositionData[j + 1][CheckpointTime]);
  43.                 swapped = true;
  44.             }
  45.             else if (RacePositionData[j][CheckpointCount] == RacePositionData[j + 1][CheckpointCount] && RacePositionData[j][CheckpointTime] > RacePositionData[j + 1][CheckpointTime])
  46.             {
  47.                 swapValues(RacePositionData[j][CheckpointCount], RacePositionData[j + 1][CheckpointCount]);
  48.                 swapValues(RacePositionData[j][CheckpointTime], RacePositionData[j + 1][CheckpointTime]);
  49.                 swapValues(RacePositionData[j][PlayerId], RacePositionData[j + 1][PlayerId]);
  50.                 swapped = true;
  51.             }
  52.         }
  53.         if (!swapped) break;
  54.     }
  55. }
  56.  
  57.  
  58. stock UpdateRaceTable()
  59. {
  60.     new string[128];
  61.     foreach(new i : Player)
  62.     {
  63.         if(RaceParticipant[i] > 0)
  64.         {
  65.             RacePositionData[i][PlayerId] = i;
  66.         }
  67.     }
  68.     new racers = CountRacers();
  69.     BubbleSortRace(MAX_PLAYERS);
  70.     foreach(new i : Player)
  71.     {
  72.         if(RacePositionData[i][PlayerId] == -1) break;
  73.         format(string, sizeof(string), "%d/~g~~H~~h~%d", i+1, racers); // gali but, kad +1 nereik
  74.         PlayerTextDrawSetString(RacePositionData[i][PlayerId], RaceTD[RacePositionData[i][PlayerId]][1], string);
  75.        
  76.         format(string, sizeof(string), "LAP: %d/~g~~H~~H~%d", CurrentLap[i], Racelaps);
  77.         PlayerTextDrawSetString(RacePositionData[i][PlayerId], RaceTD[RacePositionData[i][PlayerId]][3], string);
  78.  
  79.         format(string, sizeof(string), "CP: %d/~g~~H~~H~%d", CurrentCheckpoint[i], LCurrentCheckpoint);
  80.         PlayerTextDrawSetString(RacePositionData[i][PlayerId], RaceTD[RacePositionData[i][PlayerId]][4], string);
  81.     }
  82. }
RAW Paste Data