Advertisement
Guest User

Untitled

a guest
Jun 25th, 2017
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.53 KB | None | 0 0
  1. // If i use /loadrace manually, a race will load. However, race rotation wont do anything.
  2.  
  3. // gamemodeinit SetTimer("RaceRotation",RRotationDelay,1);
  4.  
  5. public RaceRotation()
  6. {
  7. if(!fexist("yrace.rr"))
  8. {
  9. printf("ERROR in YRACE's Race Rotation (yrace.rr): yrace.rr doesn't exist!");
  10. return -1;
  11. }
  12.  
  13. if(RRotation == -1)
  14. {
  15. KillTimer(RotationTimer);
  16. return -1; // RRotation has been disabled
  17. }
  18. if(Participants > 0) return 1; // A race is still active.
  19.  
  20. new File:f, templine[32], rotfile[]="yrace.rr", rraces=-1, rracenames[32][32], idx, fback;
  21. f = fopen(rotfile, io_read);
  22. while(fread(f,templine,sizeof(templine),false))
  23. {
  24. idx = 0;
  25. rraces++;
  26. rracenames[rraces]=strtok(templine,idx);
  27. }
  28. fclose(f);
  29. RRotation++;
  30. if(RRotation > rraces) RRotation = 0;
  31. fback = LoadRace(rracenames[RRotation]);
  32. if(fback == -1) printf("ERROR in YRACE's Race Rotation (yrace.rr): Race \'%s\' doesn't exist!",rracenames[RRotation]);
  33. else if (fback == -2) printf("ERROR in YRACE's Race Rotation (yrace.rr): Race \'%s\' is created with a newer version of YRACE",rracenames[RRotation]);
  34. else startrace();
  35. return 1;
  36. }
  37.  
  38. public LoadRace(tmp[])
  39. {
  40. new race_name[32],templine[172];
  41. format(CRaceName,sizeof(CRaceName), "%s",tmp);
  42. format(race_name,sizeof(race_name), "%s.yr",tmp);
  43. if(!fexist(race_name)) return -1; // File doesn't exist
  44. CFile=race_name;
  45. LCurrentCheckpoint=-1; RLenght=0; RLenght=0;
  46. new File:f, i;
  47. f = fopen(race_name, io_read);
  48. fread(f,templine,sizeof(templine));
  49. if(templine[0] == 'Y') //Checking if the racefile is v0.2+
  50. {
  51. new fileversion;
  52. strtok(templine,i); // read off YRACE
  53. fileversion = strval(strtok(templine,i)); // read off the file version
  54. if(fileversion > RACEFILE_VERSION) return -2; // Check if the race is made with a newer version of the racefile format
  55. CBuilder=strtok(templine,i); // read off RACEBUILDER
  56. ORacemode = strval(strtok(templine,i)); // read off racemode
  57. ORacelaps = strval(strtok(templine,i)); // read off amount of laps
  58. if(fileversion > 1)
  59. {
  60. Airrace = strval(strtok(templine,i)); // read off airrace
  61. CPsize = floatstr(strtok(templine,i)); // read off CP size
  62. }
  63. else // v1 file format, set to default
  64. {
  65. Airrace = 0;
  66. CPsize = 8.0;
  67. }
  68. OAirrace = Airrace;
  69. OCPsize = CPsize;
  70. Racemode=ORacemode; Racelaps=ORacelaps; //Allows changing the modes, but disables highscores if they've been changed.
  71. fread(f,templine,sizeof(templine)); // read off best race times
  72. i=0;
  73. for(new j=0;j<5;j++)
  74. {
  75. TopRacers[j]=strtok(templine,i);
  76. TopRacerTimes[j]=strval(strtok(templine,i));
  77. }
  78. fread(f,templine,sizeof(templine)); // read off best lap times
  79. i=0;
  80. for(new j=0;j<5;j++)
  81. {
  82. TopLappers[j]=strtok(templine,i);
  83. TopLapTimes[j]=strval(strtok(templine,i));
  84. }
  85. }
  86. else //Otherwise add the lines as checkpoints, the file is made with v0.1 (or older) version of the script.
  87. {
  88. LCurrentCheckpoint++;
  89. RaceCheckpoints[LCurrentCheckpoint][0] = floatstr(strtok(templine,i));
  90. RaceCheckpoints[LCurrentCheckpoint][1] = floatstr(strtok(templine,i));
  91. RaceCheckpoints[LCurrentCheckpoint][2] = floatstr(strtok(templine,i));
  92. Racemode=0; ORacemode=0; Racelaps=0; ORacelaps=0; //Enables converting old files to new versions
  93. CPsize = 8.0; Airrace = 0; // v2 additions
  94. OCPsize = CPsize; OAirrace = Airrace; // v2 additions
  95. CBuilder="UNKNOWN";
  96. for(new j;j<5;j++)
  97. {
  98. TopLappers[j]="A"; TopLapTimes[j]=0; TopRacers[j]="A"; TopRacerTimes[j]=0;
  99. }
  100. }
  101. while(fread(f,templine,sizeof(templine),false))
  102. {
  103. LCurrentCheckpoint++;
  104. i=0;
  105. RaceCheckpoints[LCurrentCheckpoint][0] = floatstr(strtok(templine,i));
  106. RaceCheckpoints[LCurrentCheckpoint][1] = floatstr(strtok(templine,i));
  107. RaceCheckpoints[LCurrentCheckpoint][2] = floatstr(strtok(templine,i));
  108. if(LCurrentCheckpoint >= 1)
  109. {
  110. RLenght+=Distance(RaceCheckpoints[LCurrentCheckpoint][0],RaceCheckpoints[LCurrentCheckpoint][1],
  111. RaceCheckpoints[LCurrentCheckpoint][2],RaceCheckpoints[LCurrentCheckpoint-1][0],
  112. RaceCheckpoints[LCurrentCheckpoint-1][1],RaceCheckpoints[LCurrentCheckpoint-1][2]);
  113. }
  114. }
  115. LLenght = RLenght + Distance(RaceCheckpoints[LCurrentCheckpoint][0],RaceCheckpoints[LCurrentCheckpoint][1],
  116. RaceCheckpoints[LCurrentCheckpoint][2],RaceCheckpoints[0][0],RaceCheckpoints[0][1],
  117. RaceCheckpoints[0][2]);
  118. fclose(f);
  119. return 1;
  120. }
  121.  
  122.  
  123. public startrace()
  124. {
  125. format(ystring,100,"** Race %s is about to start, type /join to join!",CRaceName);
  126. SendClientMessageToAll(COLOR_AMSG,ystring);
  127. format(ystring,100,"~g~Race ~y~%s ~g~is about to start, type ~h~/join ~g~to join!",CRaceName);
  128. TextDrawSetString(Textdrawrace,ystring);
  129. TextDrawShowForAll(Textdrawrace);
  130. format(ystring,100,"Race %s is about to start, type /join to join!",CRaceName);
  131. PlaySoundForAll(1057);
  132. GameTextForAll("~g~Its Race Time!",2500,3);
  133. SetTimer("CloseRaceTextdraw",5000,0);
  134. SendClientMessageToAll(COLOR_AMSG,ystring);
  135. if(TopRacerTimes[0] != 0)
  136. {
  137. format(ystring,100,"** Total Laps: %d - Best Race By: %s (%d Seconds)",ORacelaps,TopRacers[0],BeHuman(TopRacerTimes[0]));
  138. SendClientMessageToAll(COLOR_AMSG,ystring);
  139. }
  140. else
  141. {
  142. format(ystring,100,"** Total Laps: %d",ORacelaps);
  143. SendClientMessageToAll(COLOR_AMSG,ystring);
  144. }
  145. format(ystring,sizeof ystring," 0,3Race %s Starting Soon. [Laps: %d] (Created by %s)",CRaceName,ORacelaps,CBuilder);
  146. IrcSay(ystring);
  147. RaceStart=0;
  148. RaceActive=1;
  149. ScoreChange=0;
  150. Ranking=1;
  151. PrizeMP=3;
  152. SetTimer("RaceStartTimer",RaceStartTime*1000,false);
  153. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement