Advertisement
Guest User

Untitled

a guest
Sep 21st, 2011
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 38.19 KB | None | 0 0
  1. /*
  2. Release:
  3. » Race System Filterscript
  4.  
  5. Author:
  6. » » RyDeR «
  7.  
  8. Last Update:
  9. » 26/04/2010
  10.  
  11. ChangeLog:
  12. » v0.1a:
  13. - Initial release
  14.  
  15. » v0.2a:
  16. - Major Bugs fixed!
  17. - Racing in other worlds added (enable/disbable with uncomment/comment-ing the define)
  18. - New Commands added:
  19. - /startautorace: You can enable that the script starts automaticly a race after the previous one is done.
  20. - /stopautorace: You can disable the command above.
  21. - /exitrace: To exit the race safely
  22. - Best Race Times added (Top 5 best time laps; You will see a message when the record is broken).
  23. - Crash while creating a race is fixed.
  24. - Etc..
  25.  
  26. Bugs:
  27. » No bugs
  28.  
  29. Version:
  30. » v0.2a
  31.  
  32. Functions:
  33. » IsPlayerInRace(playerid); >> UseFull in stunt servers to disable speedhack, nitro etc. while racing.
  34.  
  35. Credits:
  36. » Joker: He knows why ;)
  37. » Joe Torran C, ModrLicC: For testing.
  38. » DracoBlue: 'Dini' include.
  39. » Y_Less: 'IsOdd' function.
  40. » Seif_: 'function' function.
  41. » ZeeX: 'zcmd' include.
  42. » Switch: InRace Position function.
  43. */
  44.  
  45. #include <a_samp>
  46. #include <dini>
  47. #include <zcmd>
  48.  
  49. #pragma unused IsNumeric
  50. #pragma unused ret_memcpy
  51.  
  52.  
  53. #define ForEach(%0,%1) \
  54. for(new %0 = 0; %0 != %1; %0++) if(IsPlayerConnected(%0) && !IsPlayerNPC(%0))
  55.  
  56. #define Loop(%0,%1) \
  57. for(new %0 = 0; %0 != %1; %0++)
  58.  
  59. #define IsOdd(%1) \
  60. ((%1) & 1)
  61.  
  62. #define ConvertTime(%0,%1,%2,%3,%4) \
  63. new \
  64. Float: %0 = floatdiv(%1, 60000) \
  65. ;\
  66. %2 = floatround(%0, floatround_tozero); \
  67. %3 = floatround(floatmul(%0 - %2, 60), floatround_tozero); \
  68. %4 = floatround(floatmul(floatmul(%0 - %2, 60) - %3, 1000), floatround_tozero)
  69.  
  70. #define function%0(%1) \
  71. forward%0(%1); public%0(%1)
  72.  
  73. #define MAX_RACE_CHECKPOINTS_EACH_RACE \
  74. 120
  75.  
  76. #define MAX_RACES \
  77. 100
  78.  
  79. #define COUNT_DOWN_TILL_RACE_START \
  80. 30 // seconds
  81.  
  82. #define MAX_RACE_TIME \
  83. 300 // seconds
  84.  
  85. #define RACE_CHECKPOINT_SIZE \
  86. 12.0
  87.  
  88. #define DEBUG_RACE \
  89. 1
  90.  
  91. //#define RACE_IN_OTHER_WORLD // Uncomment to enable
  92.  
  93. #define GREY \
  94. 0xAFAFAFAA
  95.  
  96. #define GREEN \
  97. 0x9FFF00FF
  98.  
  99. #define RED \
  100. 0xE60000FF
  101.  
  102. #define YELLOW \
  103. 0xFFFF00AA
  104.  
  105. #define WHITE \
  106. 0xFFFFFFAA
  107.  
  108. new
  109. vNames[212][] =
  110. {
  111. {"Landstalker"},
  112. {"Bravura"},
  113. {"Buffalo"},
  114. {"Linerunner"},
  115. {"Perrenial"},
  116. {"Sentinel"},
  117. {"Dumper"},
  118. {"Firetruck"},
  119. {"Trashmaster"},
  120. {"Stretch"},
  121. {"Manana"},
  122. {"Infernus"},
  123. {"Voodoo"},
  124. {"Pony"},
  125. {"Mule"},
  126. {"Cheetah"},
  127. {"Ambulance"},
  128. {"Leviathan"},
  129. {"Moonbeam"},
  130. {"Esperanto"},
  131. {"Taxi"},
  132. {"Washington"},
  133. {"Bobcat"},
  134. {"Mr Whoopee"},
  135. {"BF Injection"},
  136. {"Hunter"},
  137. {"Premier"},
  138. {"Enforcer"},
  139. {"Securicar"},
  140. {"Banshee"},
  141. {"Predator"},
  142. {"Bus"},
  143. {"Rhino"},
  144. {"Barracks"},
  145. {"Hotknife"},
  146. {"Trailer 1"},
  147. {"Previon"},
  148. {"Coach"},
  149. {"Cabbie"},
  150. {"Stallion"},
  151. {"Rumpo"},
  152. {"RC Bandit"},
  153. {"Romero"},
  154. {"Packer"},
  155. {"Monster"},
  156. {"Admiral"},
  157. {"Squalo"},
  158. {"Seasparrow"},
  159. {"Pizzaboy"},
  160. {"Tram"},
  161. {"Trailer 2"},
  162. {"Turismo"},
  163. {"Speeder"},
  164. {"Reefer"},
  165. {"Tropic"},
  166. {"Flatbed"},
  167. {"Yankee"},
  168. {"Caddy"},
  169. {"Solair"},
  170. {"Berkley's RC Van"},
  171. {"Skimmer"},
  172. {"PCJ-600"},
  173. {"Faggio"},
  174. {"Freeway"},
  175. {"RC Baron"},
  176. {"RC Raider"},
  177. {"Glendale"},
  178. {"Oceanic"},
  179. {"Sanchez"},
  180. {"Sparrow"},
  181. {"Patriot"},
  182. {"Quad"},
  183. {"Coastguard"},
  184. {"Dinghy"},
  185. {"Hermes"},
  186. {"Sabre"},
  187. {"Rustler"},
  188. {"ZR-350"},
  189. {"Walton"},
  190. {"Regina"},
  191. {"Comet"},
  192. {"BMX"},
  193. {"Burrito"},
  194. {"Camper"},
  195. {"Marquis"},
  196. {"Baggage"},
  197. {"Dozer"},
  198. {"Maverick"},
  199. {"News Chopper"},
  200. {"Rancher"},
  201. {"FBI Rancher"},
  202. {"Virgo"},
  203. {"Greenwood"},
  204. {"Jetmax"},
  205. {"Hotring"},
  206. {"Sandking"},
  207. {"Blista Compact"},
  208. {"Police Maverick"},
  209. {"Boxville"},
  210. {"Benson"},
  211. {"Mesa"},
  212. {"RC Goblin"},
  213. {"Hotring Racer A"},
  214. {"Hotring Racer B"},
  215. {"Bloodring Banger"},
  216. {"Rancher"},
  217. {"Super GT"},
  218. {"Elegant"},
  219. {"Journey"},
  220. {"Bike"},
  221. {"Mountain Bike"},
  222. {"Beagle"},
  223. {"Cropdust"},
  224. {"Stunt"},
  225. {"Tanker"},
  226. {"Roadtrain"},
  227. {"Nebula"},
  228. {"Majestic"},
  229. {"Buccaneer"},
  230. {"Shamal"},
  231. {"Hydra"},
  232. {"FCR-900"},
  233. {"NRG-500"},
  234. {"HPV1000"},
  235. {"Cement Truck"},
  236. {"Tow Truck"},
  237. {"Fortune"},
  238. {"Cadrona"},
  239. {"FBI Truck"},
  240. {"Willard"},
  241. {"Forklift"},
  242. {"Tractor"},
  243. {"Combine"},
  244. {"Feltzer"},
  245. {"Remington"},
  246. {"Slamvan"},
  247. {"Blade"},
  248. {"Freight"},
  249. {"Streak"},
  250. {"Vortex"},
  251. {"Vincent"},
  252. {"Bullet"},
  253. {"Clover"},
  254. {"Sadler"},
  255. {"Firetruck LA"},
  256. {"Hustler"},
  257. {"Intruder"},
  258. {"Primo"},
  259. {"Cargobob"},
  260. {"Tampa"},
  261. {"Sunrise"},
  262. {"Merit"},
  263. {"Utility"},
  264. {"Nevada"},
  265. {"Yosemite"},
  266. {"Windsor"},
  267. {"Monster A"},
  268. {"Monster B"},
  269. {"Uranus"},
  270. {"Jester"},
  271. {"Sultan"},
  272. {"Stratum"},
  273. {"Elegy"},
  274. {"Raindance"},
  275. {"RC Tiger"},
  276. {"Flash"},
  277. {"Tahoma"},
  278. {"Savanna"},
  279. {"Bandito"},
  280. {"Freight Flat"},
  281. {"Streak Carriage"},
  282. {"Kart"},
  283. {"Mower"},
  284. {"Duneride"},
  285. {"Sweeper"},
  286. {"Broadway"},
  287. {"Tornado"},
  288. {"AT-400"},
  289. {"DFT-30"},
  290. {"Huntley"},
  291. {"Stafford"},
  292. {"BF-400"},
  293. {"Newsvan"},
  294. {"Tug"},
  295. {"Trailer 3"},
  296. {"Emperor"},
  297. {"Wayfarer"},
  298. {"Euros"},
  299. {"Hotdog"},
  300. {"Club"},
  301. {"Freight Carriage"},
  302. {"Trailer 3"},
  303. {"Andromada"},
  304. {"Dodo"},
  305. {"RC Cam"},
  306. {"Launch"},
  307. {"Police Car (LSPD)"},
  308. {"Police Car (SFPD)"},
  309. {"Police Car (LVPD)"},
  310. {"Police Ranger"},
  311. {"Picador"},
  312. {"S.W.A.T. Van"},
  313. {"Alpha"},
  314. {"Phoenix"},
  315. {"Glendale"},
  316. {"Sadler"},
  317. {"Luggage Trailer A"},
  318. {"Luggage Trailer B"},
  319. {"Stair Trailer"},
  320. {"Boxville"},
  321. {"Farm Plow"},
  322. {"Utility Trailer"}
  323. },
  324. BuildRace,
  325. BuildRaceType,
  326. BuildVehicle,
  327. BuildCreatedVehicle,
  328. BuildModeVID,
  329. BuildName[30],
  330. bool: BuildTakeVehPos,
  331. BuildVehPosCount,
  332. bool: BuildTakeCheckpoints,
  333. BuildCheckPointCount,
  334. RaceBusy = 0x00,
  335. RaceName[30],
  336. RaceVehicle,
  337. RaceType,
  338. TotalCP,
  339. Float: RaceVehCoords[2][4],
  340. Float: CPCoords[MAX_RACE_CHECKPOINTS_EACH_RACE][4],
  341. CreatedRaceVeh[MAX_PLAYERS],
  342. Index,
  343. PlayersCount[2],
  344. CountTimer,
  345. CountAmount,
  346. bool: Joined[MAX_PLAYERS],
  347. RaceTick,
  348. RaceStarted,
  349. CPProgess[MAX_PLAYERS],
  350. Position,
  351. FinishCount,
  352. JoinCount,
  353. rCounter,
  354. RaceTime,
  355. Text: RaceInfo[MAX_PLAYERS],
  356. InfoTimer[MAX_PLAYERS],
  357. RacePosition[MAX_PLAYERS],
  358. RaceNames[MAX_RACES][128],
  359. TotalRaces,
  360. bool: AutomaticRace,
  361. TimeProgress
  362.  
  363. ;
  364.  
  365. public OnFilterScriptExit()
  366. {
  367. BuildCreatedVehicle = (BuildCreatedVehicle == 0x01) ? (DestroyVehicle(BuildVehicle), BuildCreatedVehicle = 0x00) : (DestroyVehicle(BuildVehicle), BuildCreatedVehicle = 0x00);
  368. KillTimer(rCounter);
  369. KillTimer(CountTimer);
  370. Loop(i, MAX_PLAYERS)
  371. {
  372. DisablePlayerRaceCheckpoint(i);
  373. TextDrawDestroy(RaceInfo[i]);
  374. DestroyVehicle(CreatedRaceVeh[i]);
  375. Joined[i] = false;
  376. KillTimer(InfoTimer[i]);
  377. }
  378. JoinCount = 0;
  379. FinishCount = 0;
  380. TimeProgress = 0;
  381. AutomaticRace = false;
  382. return 1;
  383. }
  384.  
  385. CMD:buildrace(playerid, params[])
  386. {
  387. if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, RED, "<!> You are not an administrator!");
  388. if(BuildRace != 0) return SendClientMessage(playerid, RED, "<!> There's already someone building a race!");
  389. if(RaceBusy == 0x01) return SendClientMessage(playerid, RED, "<!> Wait first till race ends!");
  390. if(IsPlayerInAnyVehicle(playerid)) return SendClientMessage(playerid, RED, "<!> Please leave your vehicle first!");
  391. BuildRace = playerid+1;
  392. ShowDialog(playerid, 599);
  393. return 1;
  394. }
  395. CMD:startrace(playerid, params[])
  396. {
  397. if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, RED, "<!> You are not an administrator!");
  398. if(AutomaticRace == true) return SendClientMessage(playerid, RED, "<!> Not possible. Automatic race is enabled!");
  399. if(BuildRace != 0) return SendClientMessage(playerid, RED, "<!> There's someone building a race!");
  400. if(RaceBusy == 0x01 || RaceStarted == 1) return SendClientMessage(playerid, RED, "<!> There's a race currently. Wait first till race ends!");
  401. if(isnull(params)) return SendClientMessage(playerid, RED, "<!> /startrace [racename]");
  402. LoadRace(playerid, params);
  403. return 1;
  404. }
  405. CMD:stoprace(playerid, params[])
  406. {
  407. if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, RED, "<!> You are not an administrator!");
  408. if(RaceBusy == 0x00 || RaceStarted == 0) return SendClientMessage(playerid, RED, "<!> There's no race to stop!");
  409. SendClientMessageToAll(RED, ">> An admin stopped the current race!");
  410. return StopRace();
  411. }
  412. CMD:joinrace(playerid, params[])
  413. {
  414. if(RaceStarted == 1) return SendClientMessage(playerid, RED, "<!> Race already started! Wait first till race ends!");
  415. if(RaceBusy == 0x00) return SendClientMessage(playerid, RED, "<!> There's no race to join!");
  416. if(Joined[playerid] == true) return SendClientMessage(playerid, RED, "<!> You already joined a race!");
  417. if(IsPlayerInAnyVehicle(playerid)) return SetTimerEx("SetupRaceForPlayer", 2500, 0, "e", playerid), RemovePlayerFromVehicle(playerid), Joined[playerid] = true;
  418. SetupRaceForPlayer(playerid);
  419. Joined[playerid] = true;
  420. return 1;
  421. }
  422. CMD:startautorace(playerid, params[])
  423. {
  424. if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, RED, "<!> You are not an administrator!");
  425. if(RaceBusy == 0x01 || RaceStarted == 1) return SendClientMessage(playerid, RED, "<!> There's a race currently. Wait first till race ends!");
  426. if(AutomaticRace == true) return SendClientMessage(playerid, RED, "<!> It's already enabled!");
  427. LoadRaceNames();
  428. LoadAutoRace(RaceNames[random(TotalRaces)]);
  429. AutomaticRace = true;
  430. SendClientMessage(playerid, GREEN, ">> You stared auto race. The filterscript will start a random race everytime the previous race is over!");
  431. return 1;
  432. }
  433. CMD:stopautorace(playerid, params[])
  434. {
  435. if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, RED, "<!> You are not an administrator!");
  436. if(AutomaticRace == false) return SendClientMessage(playerid, RED, "<!> It's already disabled!");
  437. AutomaticRace = false;
  438. return 1;
  439. }
  440. CMD:exitrace(playerid, params[])
  441. {
  442. if(Joined[playerid] == true)
  443. {
  444. JoinCount--;
  445. Joined[playerid] = false;
  446. DestroyVehicle(CreatedRaceVeh[playerid]);
  447. DisablePlayerRaceCheckpoint(playerid);
  448. TextDrawHideForPlayer(playerid, RaceInfo[playerid]);
  449. CPProgess[playerid] = 0;
  450. KillTimer(InfoTimer[playerid]);
  451. TogglePlayerControllable(playerid, true);
  452. SetCameraBehindPlayer(playerid);
  453. #if defined RACE_IN_OTHER_WORLD
  454. SetPlayerVirtualWorld(playerid, 0);
  455. #endif
  456. } else return SendClientMessage(playerid, RED, "<!> You are not in a race!");
  457. return 1;
  458. }
  459.  
  460. public OnPlayerEnterRaceCheckpoint(playerid)
  461. {
  462. if(CPProgess[playerid] == TotalCP -1)
  463. {
  464. new
  465. TimeStamp,
  466. TotalRaceTime,
  467. string[256],
  468. rFile[256],
  469. pName[MAX_PLAYER_NAME],
  470. rTime[3],
  471. Prize[2],
  472. TempTotalTime,
  473. TempTime[3]
  474. ;
  475. Position++;
  476. GetPlayerName(playerid, pName, sizeof(pName));
  477. TimeStamp = GetTickCount();
  478. TotalRaceTime = TimeStamp - RaceTick;
  479. ConvertTime(var, TotalRaceTime, rTime[0], rTime[1], rTime[2]);
  480. switch(Position)
  481. {
  482. case 1: Prize[0] = (random(random(5000)) + 10000), Prize[1] = 10;
  483. case 2: Prize[0] = (random(random(4500)) + 9000), Prize[1] = 9;
  484. case 3: Prize[0] = (random(random(4000)) + 8000), Prize[1] = 8;
  485. case 4: Prize[0] = (random(random(3500)) + 7000), Prize[1] = 7;
  486. case 5: Prize[0] = (random(random(3000)) + 6000), Prize[1] = 6;
  487. case 6: Prize[0] = (random(random(2500)) + 5000), Prize[1] = 5;
  488. case 7: Prize[0] = (random(random(2000)) + 4000), Prize[1] = 4;
  489. case 8: Prize[0] = (random(random(1500)) + 3000), Prize[1] = 3;
  490. case 9: Prize[0] = (random(random(1000)) + 2000), Prize[1] = 2;
  491. default: Prize[0] = random(random(1000)), Prize[1] = 1;
  492. }
  493. format(string, sizeof(string), ">> \"%s\" has finished the race in position \"%d\".", pName, Position);
  494. SendClientMessageToAll(WHITE, string);
  495. format(string, sizeof(string), " - Time: \"%d:%d.%d\".", rTime[0], rTime[1], rTime[2]);
  496. SendClientMessageToAll(WHITE, string);
  497. format(string, sizeof(string), " - Prize: \"$%d and +%d Score\".", Prize[0], Prize[1]);
  498. SendClientMessageToAll(WHITE, string);
  499.  
  500. if(FinishCount <= 5)
  501. {
  502. format(rFile, sizeof(rFile), "/rRaceSystem/%s.RRACE", RaceName);
  503. format(string, sizeof(string), "BestRacerTime_%d", TimeProgress);
  504. TempTotalTime = dini_Int(rFile, string);
  505. ConvertTime(var1, TempTotalTime, TempTime[0], TempTime[1], TempTime[2]);
  506. if(TotalRaceTime <= dini_Int(rFile, string) || TempTotalTime == 0)
  507. {
  508. dini_IntSet(rFile, string, TotalRaceTime);
  509. format(string, sizeof(string), "BestRacer_%d", TimeProgress);
  510. if(TempTotalTime != 0) format(string, sizeof(string), ">> \"%s\" has broken the record of \"%s\" with \"%d\" seconds faster on the \"%d\"'st/th place!", pName, dini_Get(rFile, string), -(rTime[1] - TempTime[1]), TimeProgress+1);
  511. else format(string, sizeof(string), ">> \"%s\" has broken a new record of on the \"%d\"'st/th place!", pName, TimeProgress+1);
  512. SendClientMessageToAll(GREEN, " ");
  513. SendClientMessageToAll(GREEN, string);
  514. SendClientMessageToAll(GREEN, " ");
  515. format(string, sizeof(string), "BestRacer_%d", TimeProgress);
  516. dini_Set(rFile, string, pName);
  517. TimeProgress++;
  518. }
  519. }
  520. FinishCount++;
  521. GivePlayerMoney(playerid, Prize[0]);
  522. SetPlayerScore(playerid, GetPlayerScore(playerid) + Prize[1]);
  523. DisablePlayerRaceCheckpoint(playerid);
  524. CPProgess[playerid]++;
  525. if(FinishCount >= JoinCount) return StopRace();
  526. }
  527. else
  528. {
  529. CPProgess[playerid]++;
  530. CPCoords[CPProgess[playerid]][3]++;
  531. RacePosition[playerid] = floatround(CPCoords[CPProgess[playerid]][3], floatround_floor);
  532. SetCP(playerid, CPProgess[playerid], CPProgess[playerid]+1, TotalCP, RaceType);
  533. PlayerPlaySound(playerid, 1137, 0.0, 0.0, 0.0);
  534. }
  535. return 1;
  536. }
  537.  
  538. public OnPlayerDisconnect(playerid)
  539. {
  540. if(Joined[playerid] == true)
  541. {
  542. JoinCount--;
  543. Joined[playerid] = false;
  544. DestroyVehicle(CreatedRaceVeh[playerid]);
  545. DisablePlayerRaceCheckpoint(playerid);
  546. TextDrawHideForPlayer(playerid, RaceInfo[playerid]);
  547. CPProgess[playerid] = 0;
  548. KillTimer(InfoTimer[playerid]);
  549. #if defined RACE_IN_OTHER_WORLD
  550. SetPlayerVirtualWorld(playerid, 0);
  551. #endif
  552. }
  553. TextDrawDestroy(RaceInfo[playerid]);
  554. if(BuildRace == playerid+1) BuildRace = 0;
  555. return 1;
  556. }
  557.  
  558. public OnPlayerConnect(playerid)
  559. {
  560. RaceInfo[playerid] = TextDrawCreate(633.000000, 348.000000, " ");
  561. TextDrawAlignment(RaceInfo[playerid], 3);
  562. TextDrawBackgroundColor(RaceInfo[playerid], 255);
  563. TextDrawFont(RaceInfo[playerid], 1);
  564. TextDrawLetterSize(RaceInfo[playerid], 0.240000, 1.100000);
  565. TextDrawColor(RaceInfo[playerid], -687931137);
  566. TextDrawSetOutline(RaceInfo[playerid], 0);
  567. TextDrawSetProportional(RaceInfo[playerid], 1);
  568. TextDrawSetShadow(RaceInfo[playerid], 1);
  569. return 1;
  570. }
  571.  
  572. public OnPlayerDeath(playerid)
  573. {
  574. if(Joined[playerid] == true)
  575. {
  576. JoinCount--;
  577. Joined[playerid] = false;
  578. DestroyVehicle(CreatedRaceVeh[playerid]);
  579. DisablePlayerRaceCheckpoint(playerid);
  580. TextDrawHideForPlayer(playerid, RaceInfo[playerid]);
  581. CPProgess[playerid] = 0;
  582. KillTimer(InfoTimer[playerid]);
  583. #if defined RACE_IN_OTHER_WORLD
  584. SetPlayerVirtualWorld(playerid, 0);
  585. #endif
  586. }
  587. if(BuildRace == playerid+1) BuildRace = 0;
  588. return 1;
  589. }
  590.  
  591. public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
  592. {
  593. switch(dialogid)
  594. {
  595. case 599:
  596. {
  597. if(!response) return BuildRace = 0;
  598. switch(listitem)
  599. {
  600. case 0: BuildRaceType = 0;
  601. case 1: BuildRaceType = 3;
  602. }
  603. ShowDialog(playerid, 600);
  604. }
  605. case 600..601:
  606. {
  607. if(!response) return ShowDialog(playerid, 599);
  608. if(!strlen(inputtext)) return ShowDialog(playerid, 601);
  609. if(strlen(inputtext) < 1 || strlen(inputtext) > 20) return ShowDialog(playerid, 601);
  610. strmid(BuildName, inputtext, 0, strlen(inputtext), sizeof(BuildName));
  611. ShowDialog(playerid, 602);
  612. }
  613. case 602..603:
  614. {
  615. if(!response) return ShowDialog(playerid, 600);
  616. if(!strlen(inputtext)) return ShowDialog(playerid, 603);
  617. if(IsNumeric(inputtext))
  618. {
  619.  
  620. if(!IsValidVehicle(strval(inputtext))) return ShowDialog(playerid, 603);
  621. new
  622. Float: pPos[4]
  623. ;
  624. GetPlayerPos(playerid, pPos[0], pPos[1], pPos[2]);
  625. GetPlayerFacingAngle(playerid, pPos[3]);
  626. BuildModeVID = strval(inputtext);
  627. BuildCreatedVehicle = (BuildCreatedVehicle == 0x01) ? (DestroyVehicle(BuildVehicle), BuildCreatedVehicle = 0x00) : (DestroyVehicle(BuildVehicle), BuildCreatedVehicle = 0x00);
  628. BuildVehicle = CreateVehicle(strval(inputtext), pPos[0], pPos[1], pPos[2], pPos[3], random(126), random(126), (60 * 60));
  629. PutPlayerInVehicle(playerid, BuildVehicle, 0);
  630. BuildCreatedVehicle = 0x01;
  631. ShowDialog(playerid, 604);
  632. }
  633. else
  634. {
  635. if(!IsValidVehicle(ReturnVehicleID(inputtext))) return ShowDialog(playerid, 603);
  636. new
  637. Float: pPos[4]
  638. ;
  639. GetPlayerPos(playerid, pPos[0], pPos[1], pPos[2]);
  640. GetPlayerFacingAngle(playerid, pPos[3]);
  641. BuildModeVID = ReturnVehicleID(inputtext);
  642. BuildCreatedVehicle = (BuildCreatedVehicle == 0x01) ? (DestroyVehicle(BuildVehicle), BuildCreatedVehicle = 0x00) : (DestroyVehicle(BuildVehicle), BuildCreatedVehicle = 0x00);
  643. BuildVehicle = CreateVehicle(ReturnVehicleID(inputtext), pPos[0], pPos[1], pPos[2], pPos[3], random(126), random(126), (60 * 60));
  644. PutPlayerInVehicle(playerid, BuildVehicle, 0);
  645. BuildCreatedVehicle = 0x01;
  646. ShowDialog(playerid, 604);
  647. }
  648. }
  649. case 604:
  650. {
  651. if(!response) return ShowDialog(playerid, 602);
  652. SendClientMessage(playerid, GREEN, ">> Go to the start line on the left road and press 'KEY_FIRE' and do the same with the right road block.");
  653. SendClientMessage(playerid, GREEN, " - When this is done, you will see a dialog to continue.");
  654. BuildVehPosCount = 0;
  655. BuildTakeVehPos = true;
  656. }
  657. case 605:
  658. {
  659. if(!response) return ShowDialog(playerid, 604);
  660. SendClientMessage(playerid, GREEN, ">> Start taking checkpoints now by clicking 'KEY_FIRE'.");
  661. SendClientMessage(playerid, GREEN, " - IMPORTANT: Press 'ENTER' when you're done with the checkpoints! If it doesn't react press again and again.");
  662. BuildCheckPointCount = 0;
  663. BuildTakeCheckpoints = true;
  664. }
  665. case 606:
  666. {
  667. if(!response) return ShowDialog(playerid, 606);
  668. BuildRace = 0;
  669. BuildCheckPointCount = 0;
  670. BuildVehPosCount = 0;
  671. BuildTakeCheckpoints = false;
  672. BuildTakeVehPos = false;
  673. BuildCreatedVehicle = (BuildCreatedVehicle == 0x01) ? (DestroyVehicle(BuildVehicle), BuildCreatedVehicle = 0x00) : (DestroyVehicle(BuildVehicle), BuildCreatedVehicle = 0x00);
  674. }
  675. }
  676. return 1;
  677. }
  678.  
  679. public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
  680. {
  681. new
  682. string[256],
  683. rNameFile[256],
  684. rFile[256],
  685. Float: vPos[4]
  686. ;
  687. if(newkeys & KEY_FIRE)
  688. {
  689. if(BuildRace == playerid+1)
  690. {
  691. if(BuildTakeVehPos == true)
  692. {
  693. if(!IsPlayerInAnyVehicle(playerid)) return SendClientMessage(playerid, RED, ">> You need to be in a vehicle");
  694. format(rFile, sizeof(rFile), "/rRaceSystem/%s.RRACE", BuildName);
  695. GetVehiclePos(GetPlayerVehicleID(playerid), vPos[0], vPos[1], vPos[2]);
  696. GetVehicleZAngle(GetPlayerVehicleID(playerid), vPos[3]);
  697. dini_Create(rFile);
  698. dini_IntSet(rFile, "vModel", BuildModeVID);
  699. dini_IntSet(rFile, "rType", BuildRaceType);
  700. format(string, sizeof(string), "vPosX_%d", BuildVehPosCount), dini_FloatSet(rFile, string, vPos[0]);
  701. format(string, sizeof(string), "vPosY_%d", BuildVehPosCount), dini_FloatSet(rFile, string, vPos[1]);
  702. format(string, sizeof(string), "vPosZ_%d", BuildVehPosCount), dini_FloatSet(rFile, string, vPos[2]);
  703. format(string, sizeof(string), "vAngle_%d", BuildVehPosCount), dini_FloatSet(rFile, string, vPos[3]);
  704. format(string, sizeof(string), ">> Vehicle Pos '%d' has been taken.", BuildVehPosCount+1);
  705. SendClientMessage(playerid, YELLOW, string);
  706. BuildVehPosCount++;
  707. }
  708. if(BuildVehPosCount >= 2)
  709. {
  710. BuildVehPosCount = 0;
  711. BuildTakeVehPos = false;
  712. ShowDialog(playerid, 605);
  713. }
  714. if(BuildTakeCheckpoints == true)
  715. {
  716. if(BuildCheckPointCount > MAX_RACE_CHECKPOINTS_EACH_RACE) return SendClientMessage(playerid, RED, ">> You reached the maximum amount of checkpoints!");
  717. if(!IsPlayerInAnyVehicle(playerid)) return SendClientMessage(playerid, RED, ">> You need to be in a vehicle");
  718. format(rFile, sizeof(rFile), "/rRaceSystem/%s.RRACE", BuildName);
  719. GetVehiclePos(GetPlayerVehicleID(playerid), vPos[0], vPos[1], vPos[2]);
  720. format(string, sizeof(string), "CP_%d_PosX", BuildCheckPointCount), dini_FloatSet(rFile, string, vPos[0]);
  721. format(string, sizeof(string), "CP_%d_PosY", BuildCheckPointCount), dini_FloatSet(rFile, string, vPos[1]);
  722. format(string, sizeof(string), "CP_%d_PosZ", BuildCheckPointCount), dini_FloatSet(rFile, string, vPos[2]);
  723. format(string, sizeof(string), ">> Checkpoint '%d' has been setted!", BuildCheckPointCount+1);
  724. SendClientMessage(playerid, YELLOW, string);
  725. BuildCheckPointCount++;
  726. }
  727. }
  728. }
  729. if(newkeys & KEY_SECONDARY_ATTACK)
  730. {
  731. if(BuildTakeCheckpoints == true)
  732. {
  733. ShowDialog(playerid, 606);
  734. format(rNameFile, sizeof(rNameFile), "/rRaceSystem/RaceNames/RaceNames.txt");
  735. TotalRaces = dini_Int(rNameFile, "TotalRaces");
  736. TotalRaces++;
  737. dini_IntSet(rNameFile, "TotalRaces", TotalRaces);
  738. format(string, sizeof(string), "Race_%d", TotalRaces-1);
  739. format(rFile, sizeof(rFile), "/rRaceSystem/%s.RRACE", BuildName);
  740. dini_Set(rNameFile, string, BuildName);
  741. dini_IntSet(rFile, "TotalCP", BuildCheckPointCount);
  742. Loop(x, 5)
  743. {
  744. format(string, sizeof(string), "BestRacerTime_%d", x);
  745. dini_Set(rFile, string, "0");
  746. format(string, sizeof(string), "BestRacer_%d", x);
  747. dini_Set(rFile, string, "noone");
  748. }
  749. }
  750. }
  751. return 1;
  752. }
  753.  
  754. function LoadRaceNames()
  755. {
  756. new
  757. rNameFile[64],
  758. string[64]
  759. ;
  760. format(rNameFile, sizeof(rNameFile), "/rRaceSystem/RaceNames/RaceNames.txt");
  761. TotalRaces = dini_Int(rNameFile, "TotalRaces");
  762. Loop(x, TotalRaces)
  763. {
  764. format(string, sizeof(string), "Race_%d", x), strmid(RaceNames[x], dini_Get(rNameFile, string), 0, 20, sizeof(RaceNames));
  765. printf(">> Loaded Races: %s", RaceNames[x]);
  766. }
  767. return 1;
  768. }
  769.  
  770. function LoadAutoRace(rName[])
  771. {
  772. new
  773. rFile[256],
  774. string[256]
  775. ;
  776. format(rFile, sizeof(rFile), "/rRaceSystem/%s.RRACE", rName);
  777. if(!dini_Exists(rFile)) return printf("Race \"%s\" doesn't exist!", rName);
  778. strmid(RaceName, rName, 0, strlen(rName), sizeof(RaceName));
  779. RaceVehicle = dini_Int(rFile, "vModel");
  780. RaceType = dini_Int(rFile, "rType");
  781. TotalCP = dini_Int(rFile, "TotalCP");
  782.  
  783. #if DEBUG_RACE == 1
  784. printf("VehicleModel: %d", RaceVehicle);
  785. printf("RaceType: %d", RaceType);
  786. printf("TotalCheckpoints: %d", TotalCP);
  787. #endif
  788.  
  789. Loop(x, 2)
  790. {
  791. format(string, sizeof(string), "vPosX_%d", x), RaceVehCoords[x][0] = dini_Float(rFile, string);
  792. format(string, sizeof(string), "vPosY_%d", x), RaceVehCoords[x][1] = dini_Float(rFile, string);
  793. format(string, sizeof(string), "vPosZ_%d", x), RaceVehCoords[x][2] = dini_Float(rFile, string);
  794. format(string, sizeof(string), "vAngle_%d", x), RaceVehCoords[x][3] = dini_Float(rFile, string);
  795. #if DEBUG_RACE == 1
  796. printf("VehiclePos %d: %f, %f, %f, %f", x, RaceVehCoords[x][0], RaceVehCoords[x][1], RaceVehCoords[x][2], RaceVehCoords[x][3]);
  797. #endif
  798. }
  799. Loop(x, TotalCP)
  800. {
  801. format(string, sizeof(string), "CP_%d_PosX", x), CPCoords[x][0] = dini_Float(rFile, string);
  802. format(string, sizeof(string), "CP_%d_PosY", x), CPCoords[x][1] = dini_Float(rFile, string);
  803. format(string, sizeof(string), "CP_%d_PosZ", x), CPCoords[x][2] = dini_Float(rFile, string);
  804. #if DEBUG_RACE == 1
  805. printf("RaceCheckPoint %d: %f, %f, %f", x, CPCoords[x][0], CPCoords[x][1], CPCoords[x][2]);
  806. #endif
  807. }
  808. Position = 0;
  809. FinishCount = 0;
  810. JoinCount = 0;
  811. Loop(x, 2) PlayersCount[x] = 0;
  812. CountAmount = COUNT_DOWN_TILL_RACE_START;
  813. RaceTime = MAX_RACE_TIME;
  814. RaceBusy = 0x01;
  815. CountTimer = SetTimer("CountTillRace", 999, 1);
  816. TimeProgress = 0;
  817. return 1;
  818. }
  819.  
  820. function LoadRace(playerid, rName[])
  821. {
  822. new
  823. rFile[256],
  824. string[256]
  825. ;
  826. format(rFile, sizeof(rFile), "/rRaceSystem/%s.RRACE", rName);
  827. if(!dini_Exists(rFile)) return SendClientMessage(playerid, RED, "<!> Race doesn't exist!"), printf("Race \"%s\" doesn't exist!", rName);
  828. strmid(RaceName, rName, 0, strlen(rName), sizeof(RaceName));
  829. RaceVehicle = dini_Int(rFile, "vModel");
  830. RaceType = dini_Int(rFile, "rType");
  831. TotalCP = dini_Int(rFile, "TotalCP");
  832.  
  833. #if DEBUG_RACE == 1
  834. printf("VehicleModel: %d", RaceVehicle);
  835. printf("RaceType: %d", RaceType);
  836. printf("TotalCheckpoints: %d", TotalCP);
  837. #endif
  838.  
  839. Loop(x, 2)
  840. {
  841. format(string, sizeof(string), "vPosX_%d", x), RaceVehCoords[x][0] = dini_Float(rFile, string);
  842. format(string, sizeof(string), "vPosY_%d", x), RaceVehCoords[x][1] = dini_Float(rFile, string);
  843. format(string, sizeof(string), "vPosZ_%d", x), RaceVehCoords[x][2] = dini_Float(rFile, string);
  844. format(string, sizeof(string), "vAngle_%d", x), RaceVehCoords[x][3] = dini_Float(rFile, string);
  845. #if DEBUG_RACE == 1
  846. printf("VehiclePos %d: %f, %f, %f, %f", x, RaceVehCoords[x][0], RaceVehCoords[x][1], RaceVehCoords[x][2], RaceVehCoords[x][3]);
  847. #endif
  848. }
  849. Loop(x, TotalCP)
  850. {
  851. format(string, sizeof(string), "CP_%d_PosX", x), CPCoords[x][0] = dini_Float(rFile, string);
  852. format(string, sizeof(string), "CP_%d_PosY", x), CPCoords[x][1] = dini_Float(rFile, string);
  853. format(string, sizeof(string), "CP_%d_PosZ", x), CPCoords[x][2] = dini_Float(rFile, string);
  854. #if DEBUG_RACE == 1
  855. printf("RaceCheckPoint %d: %f, %f, %f", x, CPCoords[x][0], CPCoords[x][1], CPCoords[x][2]);
  856. #endif
  857. }
  858. Position = 0;
  859. FinishCount = 0;
  860. JoinCount = 0;
  861. Loop(x, 2) PlayersCount[x] = 0;
  862. Joined[playerid] = true;
  863. CountAmount = COUNT_DOWN_TILL_RACE_START;
  864. RaceTime = MAX_RACE_TIME;
  865. RaceBusy = 0x01;
  866. TimeProgress = 0;
  867. SetupRaceForPlayer(playerid);
  868. CountTimer = SetTimer("CountTillRace", 999, 1);
  869. return 1;
  870. }
  871.  
  872. function SetCP(playerid, PrevCP, NextCP, MaxCP, Type)
  873. {
  874. if(Type == 0)
  875. {
  876. if(NextCP == MaxCP) SetPlayerRaceCheckpoint(playerid, 1, CPCoords[PrevCP][0], CPCoords[PrevCP][1], CPCoords[PrevCP][2], CPCoords[NextCP][0], CPCoords[NextCP][1], CPCoords[NextCP][2], RACE_CHECKPOINT_SIZE);
  877. else SetPlayerRaceCheckpoint(playerid, 0, CPCoords[PrevCP][0], CPCoords[PrevCP][1], CPCoords[PrevCP][2], CPCoords[NextCP][0], CPCoords[NextCP][1], CPCoords[NextCP][2], RACE_CHECKPOINT_SIZE);
  878. }
  879. else if(Type == 3)
  880. {
  881. if(NextCP == MaxCP) SetPlayerRaceCheckpoint(playerid, 4, CPCoords[PrevCP][0], CPCoords[PrevCP][1], CPCoords[PrevCP][2], CPCoords[NextCP][0], CPCoords[NextCP][1], CPCoords[NextCP][2], RACE_CHECKPOINT_SIZE);
  882. else SetPlayerRaceCheckpoint(playerid, 3, CPCoords[PrevCP][0], CPCoords[PrevCP][1], CPCoords[PrevCP][2], CPCoords[NextCP][0], CPCoords[NextCP][1], CPCoords[NextCP][2], RACE_CHECKPOINT_SIZE);
  883. }
  884. return 1;
  885. }
  886.  
  887. function SetupRaceForPlayer(playerid)
  888. {
  889. CPProgess[playerid] = 0;
  890. TogglePlayerControllable(playerid, false);
  891. CPCoords[playerid][3] = 0;
  892. SetCP(playerid, CPProgess[playerid], CPProgess[playerid]+1, TotalCP, RaceType);
  893. if(IsOdd(playerid)) Index = 1;
  894. else Index = 0;
  895.  
  896. switch(Index)
  897. {
  898. case 0:
  899. {
  900. if(PlayersCount[0] == 1)
  901. {
  902. RaceVehCoords[0][0] -= (6 * floatsin(-RaceVehCoords[0][3], degrees));
  903. RaceVehCoords[0][1] -= (6 * floatcos(-RaceVehCoords[0][3], degrees));
  904. CreatedRaceVeh[playerid] = CreateVehicle(RaceVehicle, RaceVehCoords[0][0], RaceVehCoords[0][1], RaceVehCoords[0][2]+2, RaceVehCoords[0][3], random(126), random(126), (60 * 60));
  905. SetPlayerPos(playerid, RaceVehCoords[0][0], RaceVehCoords[0][1], RaceVehCoords[0][2]+2);
  906. SetPlayerFacingAngle(playerid, RaceVehCoords[0][3]);
  907. PutPlayerInVehicle(playerid, CreatedRaceVeh[playerid], 0);
  908. Camera(playerid, RaceVehCoords[0][0], RaceVehCoords[0][1], RaceVehCoords[0][2], RaceVehCoords[0][3], 20);
  909. }
  910. }
  911. case 1:
  912. {
  913. if(PlayersCount[1] == 1)
  914. {
  915. RaceVehCoords[1][0] -= (6 * floatsin(-RaceVehCoords[1][3], degrees));
  916. RaceVehCoords[1][1] -= (6 * floatcos(-RaceVehCoords[1][3], degrees));
  917. CreatedRaceVeh[playerid] = CreateVehicle(RaceVehicle, RaceVehCoords[1][0], RaceVehCoords[1][1], RaceVehCoords[1][2]+2, RaceVehCoords[1][3], random(126), random(126), (60 * 60));
  918. SetPlayerPos(playerid, RaceVehCoords[1][0], RaceVehCoords[1][1], RaceVehCoords[1][2]+2);
  919. SetPlayerFacingAngle(playerid, RaceVehCoords[1][3]);
  920. PutPlayerInVehicle(playerid, CreatedRaceVeh[playerid], 0);
  921. Camera(playerid, RaceVehCoords[1][0], RaceVehCoords[1][1], RaceVehCoords[1][2], RaceVehCoords[1][3], 20);
  922. }
  923. }
  924. }
  925. switch(Index)
  926. {
  927. case 0:
  928. {
  929. if(PlayersCount[0] != 1)
  930. {
  931. CreatedRaceVeh[playerid] = CreateVehicle(RaceVehicle, RaceVehCoords[0][0], RaceVehCoords[0][1], RaceVehCoords[0][2]+2, RaceVehCoords[0][3], random(126), random(126), (60 * 60));
  932. SetPlayerPos(playerid, RaceVehCoords[0][0], RaceVehCoords[0][1], RaceVehCoords[0][2]+2);
  933. SetPlayerFacingAngle(playerid, RaceVehCoords[0][3]);
  934. PutPlayerInVehicle(playerid, CreatedRaceVeh[playerid], 0);
  935. Camera(playerid, RaceVehCoords[0][0], RaceVehCoords[0][1], RaceVehCoords[0][2], RaceVehCoords[0][3], 20);
  936. PlayersCount[0] = 1;
  937. }
  938. }
  939. case 1:
  940. {
  941. if(PlayersCount[1] != 1)
  942. {
  943. CreatedRaceVeh[playerid] = CreateVehicle(RaceVehicle, RaceVehCoords[1][0], RaceVehCoords[1][1], RaceVehCoords[1][2]+2, RaceVehCoords[1][3], random(126), random(126), (60 * 60));
  944. SetPlayerPos(playerid, RaceVehCoords[1][0], RaceVehCoords[1][1], RaceVehCoords[1][2]+2);
  945. SetPlayerFacingAngle(playerid, RaceVehCoords[1][3]);
  946. PutPlayerInVehicle(playerid, CreatedRaceVeh[playerid], 0);
  947. Camera(playerid, RaceVehCoords[1][0], RaceVehCoords[1][1], RaceVehCoords[1][2], RaceVehCoords[1][3], 20);
  948. PlayersCount[1] = 1;
  949. }
  950. }
  951. }
  952. new
  953. string[128]
  954. ;
  955. #if defined RACE_IN_OTHER_WORLD
  956. SetPlayerVirtualWorld(playerid, 10);
  957. #endif
  958. InfoTimer[playerid] = SetTimerEx("TextInfo", 500, 1, "e", playerid);
  959. if(JoinCount == 1) format(string, sizeof(string), "RaceName: ~w~%s~n~~p~~h~Checkpoint: ~w~%d/%d~n~~b~~h~RaceTime: ~w~%s~n~~y~RacePosition: ~w~1/1~n~ ", RaceName, CPProgess[playerid], TotalCP, TimeConvert(RaceTime));
  960. else format(string, sizeof(string), "RaceName: ~w~%s~n~~p~~h~Checkpoint: ~w~%d/%d~n~~b~~h~RaceTime: ~w~%s~n~~y~RacePosition: ~w~%d/%d~n~ ", RaceName, CPProgess[playerid], TotalCP, TimeConvert(RaceTime), RacePosition[playerid], JoinCount);
  961. TextDrawSetString(RaceInfo[playerid], string);
  962. TextDrawShowForPlayer(playerid, RaceInfo[playerid]);
  963. JoinCount++;
  964. return 1;
  965. }
  966.  
  967. function CountTillRace()
  968. {
  969. switch(CountAmount)
  970. {
  971. case 0:
  972. {
  973. ForEach(i, MAX_PLAYERS)
  974. {
  975. if(Joined[i] == false)
  976. {
  977. new
  978. string[128]
  979. ;
  980. format(string, sizeof(string), ">> You can't join to \"%s\" named race anymore. Join time is over!", RaceName);
  981. SendClientMessage(i, RED, string);
  982. }
  983. }
  984. StartRace();
  985. }
  986. case 1..5:
  987. {
  988. new
  989. string[10]
  990. ;
  991. format(string, sizeof(string), "~b~%d", CountAmount);
  992. ForEach(i, MAX_PLAYERS)
  993. {
  994. if(Joined[i] == true)
  995. {
  996. GameTextForPlayer(i, string, 999, 5);
  997. PlayerPlaySound(i, 1056, 0.0, 0.0, 0.0);
  998. }
  999. }
  1000. }
  1001. case 60, 50, 40, 30, 20, 10:
  1002. {
  1003. new
  1004. string[128]
  1005. ;
  1006. format(string, sizeof(string), ">> \"%d\" seconds till \"%s\" named race starts! Type \"/joinrace\" to join the race.", CountAmount, RaceName);
  1007. SendClientMessageToAll(GREEN, string);
  1008. }
  1009. }
  1010. return CountAmount--;
  1011. }
  1012.  
  1013. function StartRace()
  1014. {
  1015. ForEach(i, MAX_PLAYERS)
  1016. {
  1017. if(Joined[i] == true)
  1018. {
  1019. TogglePlayerControllable(i, true);
  1020. PlayerPlaySound(i, 1057, 0.0, 0.0, 0.0);
  1021. GameTextForPlayer(i, "~g~GO GO GO", 2000, 5);
  1022. SetCameraBehindPlayer(i);
  1023. }
  1024. }
  1025. rCounter = SetTimer("RaceCounter", 900, 1);
  1026. RaceTick = GetTickCount();
  1027. RaceStarted = 1;
  1028. KillTimer(CountTimer);
  1029. return 1;
  1030. }
  1031.  
  1032. function StopRace()
  1033. {
  1034. KillTimer(rCounter);
  1035. RaceStarted = 0;
  1036. RaceTick = 0;
  1037. RaceBusy = 0x00;
  1038. JoinCount = 0;
  1039. FinishCount = 0;
  1040. TimeProgress = 0;
  1041.  
  1042. ForEach(i, MAX_PLAYERS)
  1043. {
  1044. if(Joined[i] == true)
  1045. {
  1046. DisablePlayerRaceCheckpoint(i);
  1047. DestroyVehicle(CreatedRaceVeh[i]);
  1048. Joined[i] = false;
  1049. TextDrawHideForPlayer(i, RaceInfo[i]);
  1050. CPProgess[i] = 0;
  1051. KillTimer(InfoTimer[i]);
  1052. }
  1053. }
  1054. SendClientMessageToAll(YELLOW, ">> Race time is over!");
  1055. if(AutomaticRace == true) LoadRaceNames(), LoadAutoRace(RaceNames[random(TotalRaces)]);
  1056. return 1;
  1057. }
  1058.  
  1059. function RaceCounter()
  1060. {
  1061. if(RaceStarted == 1)
  1062. {
  1063. RaceTime--;
  1064. if(JoinCount <= 0)
  1065. {
  1066. StopRace();
  1067. SendClientMessageToAll(RED, ">> Race ended.. No one left in the race!");
  1068. }
  1069. }
  1070. if(RaceTime <= 0)
  1071. {
  1072. StopRace();
  1073. }
  1074. return 1;
  1075. }
  1076.  
  1077. function TextInfo(playerid)
  1078. {
  1079. new
  1080. string[128]
  1081. ;
  1082. if(JoinCount == 1) format(string, sizeof(string), "RaceName: ~w~%s~n~~p~~h~Checkpoint: ~w~%d/%d~n~~b~~h~RaceTime: ~w~%s~n~~y~RacePosition: ~w~1/1~n~", RaceName, CPProgess[playerid], TotalCP, TimeConvert(RaceTime));
  1083. else format(string, sizeof(string), "RaceName: ~w~%s~n~~p~~h~Checkpoint: ~w~%d/%d~n~~b~~h~RaceTime: ~w~%s~n~~y~RacePosition: ~w~%d/%d~n~", RaceName, CPProgess[playerid], TotalCP, TimeConvert(RaceTime), RacePosition[playerid], JoinCount);
  1084. TextDrawSetString(RaceInfo[playerid], string);
  1085. TextDrawShowForPlayer(playerid, RaceInfo[playerid]);
  1086. }
  1087.  
  1088. function Camera(playerid, Float:X, Float:Y, Float:Z, Float:A, Mul)
  1089. {
  1090. SetPlayerCameraLookAt(playerid, X, Y, Z);
  1091. SetPlayerCameraPos(playerid, X + (Mul * floatsin(-A, degrees)), Y + (Mul * floatcos(-A, degrees)), Z+6);
  1092. }
  1093.  
  1094. function IsPlayerInRace(playerid)
  1095. {
  1096. if(Joined[playerid] == true) return true;
  1097. else return false;
  1098. }
  1099.  
  1100. function ShowDialog(playerid, dialogid)
  1101. {
  1102. switch(dialogid)
  1103. {
  1104. case 599: ShowPlayerDialog(playerid, dialogid, DIALOG_STYLE_LIST, CreateCaption("Build New Race"), "\
  1105. Normal Race\n\
  1106. Air Race", "Next", "Exit");
  1107.  
  1108. case 600: ShowPlayerDialog(playerid, dialogid, DIALOG_STYLE_INPUT, CreateCaption("Build New Race (Step 1/4)"), "\
  1109. Step 1:\n\
  1110. ********\n\
  1111. Welcome to wizard 'Build New Race'.\n\
  1112. Before getting started, I need to know the name (e.g. SFRace) of the to save it under.\n\n\
  1113. >> Give the NAME below and press 'Next' to continue.", "Next", "Back");
  1114.  
  1115. case 601: ShowPlayerDialog(playerid, dialogid, DIALOG_STYLE_INPUT, CreateCaption("Build New Race (Step 1/4)"), "\
  1116. ERROR: Name too short or too long! (min. 1 - max. 20)\n\n\n\
  1117. Step 1:\n\
  1118. ********\n\
  1119. Welcome to wizard 'Build New Race'.\n\
  1120. Before getting started, I need to know the name (e.g. SFRace) of the to save it under.\n\n\
  1121. >> Give the NAME below and press 'Next' to continue.", "Next", "Back");
  1122.  
  1123. case 602: ShowPlayerDialog(playerid, dialogid, DIALOG_STYLE_INPUT, CreateCaption("Build New Race (Step 2/4)"), "\
  1124. Step 2:\n\
  1125. ********\n\
  1126. Please give the ID or NAME of the vehicle that's going to be used in the race you are creating now.\n\n\
  1127. >> Give the ID or NAME of the vehicle below and press 'Next' to continue. 'Back' to change something.", "Next", "Back");
  1128.  
  1129. case 603: ShowPlayerDialog(playerid, dialogid, DIALOG_STYLE_INPUT, CreateCaption("Build New Race (Step 2/4)"), "\
  1130. ERROR: Invalid Vehilce ID/Name\n\n\n\
  1131. Step 2:\n\
  1132. ********\n\
  1133. Please give the ID or NAME of the vehicle that's going to be used in the race you are creating now.\n\n\
  1134. >> Give the ID or NAME of the vehicle below and press 'Next' to continue. 'Back' to change something.", "Next", "Back");
  1135.  
  1136. case 604: ShowPlayerDialog(playerid, dialogid, DIALOG_STYLE_MSGBOX, CreateCaption("Build New Race (Step 3/4)"),
  1137. "\
  1138. Step 3:\n\
  1139. ********\n\
  1140. We are almost done! Now go to the start line where the first and second car should stand.\n\
  1141. Note: When you click 'OK' you will be free. Use 'KEY_FIRE' to set the first position and second position.\n\
  1142. Note: After you got these positions you will automaticly see a dialog to continue the wizard.\n\n\
  1143. >> Press 'OK' to do the things above. 'Back' to change something.", "OK", "Back");
  1144.  
  1145. case 605: ShowPlayerDialog(playerid, dialogid, DIALOG_STYLE_MSGBOX, CreateCaption("Build New Race (Step 4/4)"),
  1146. "\
  1147. Step 4:\n\
  1148. ********\n\
  1149. Welcome to the last stap. In this stap you have to set the checkpoints; so if you click 'OK' you can set the checkpoints.\n\
  1150. You can set the checkpoints with 'KEY_FIRE'. Each checkpoint you set will save.\n\
  1151. You have to press 'ENTER' button when you're done with everything. You race is aviable then!\n\n\
  1152. >> Press 'OK' to do the things above. 'Back' to change something.", "OK", "Back");
  1153.  
  1154. case 606: ShowPlayerDialog(playerid, dialogid, DIALOG_STYLE_MSGBOX, CreateCaption("Build New Race (Done)"),
  1155. "\
  1156. You have created your race and it's ready to use now.\n\n\
  1157. >> Press 'Finish' to finish. 'Exit' - Has no effect.", "Finish", "Exit");
  1158. }
  1159. return 1;
  1160. }
  1161.  
  1162. CreateCaption(arguments[])
  1163. {
  1164. new
  1165. string[128 char]
  1166. ;
  1167. format(string, sizeof(string), "RyDeR's Race System - %s", arguments);
  1168. return string;
  1169. }
  1170.  
  1171. stock IsValidVehicle(vehicleid)
  1172. {
  1173. if(vehicleid < 400 || vehicleid > 611) return false;
  1174. else return true;
  1175. }
  1176.  
  1177. ReturnVehicleID(vName[])
  1178. {
  1179. Loop(x, 211)
  1180. {
  1181. if(strfind(vNames[x], vName, true) != -1)
  1182. return x + 400;
  1183. }
  1184. return -1;
  1185. }
  1186.  
  1187. TimeConvert(seconds)
  1188. {
  1189. new tmp[16];
  1190. new minutes = floatround(seconds/60);
  1191. seconds -= minutes*60;
  1192. format(tmp, sizeof(tmp), "%d:%02d", minutes, seconds);
  1193. return tmp;
  1194. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement