Advertisement
Guest User

Untitled

a guest
Jan 15th, 2014
968
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 22.25 KB | None | 0 0
  1.  
  2. /*==============================================================================
  3. Derby Script v1 by OutLawZ
  4. ==============================================================================*/
  5.  
  6. #include <a_samp>
  7. #include <sscanf2>
  8.  
  9. #define DERBY_INTERMISSION "90" // Time in seconds for the next derby to commence
  10. #define DERBY_COOLDOWN "30" // Time in seconds for the players to signup
  11. #define DERBY_COUNTDOWN "5" // Time in seconds for countdown
  12. #define MONEY_REWARD "500" // Money reward for the player that wins
  13. #define SCORE_REWARD "10" // Score reward for the player that wins
  14. #define ENABLE_CLIENT_MSG // Comment out if you don't want client messages to show
  15.  
  16. #define MIN_DERBY_PLAYERS (2)
  17. #define MAX_DERBY_PLAYERS (12)
  18. #define MAX_TD_FRAMES (8)
  19. #define MAX_CLIENT_STRING (128)
  20.  
  21. #define COLOR_ERROR (0xF11D22FF)
  22. #define COLOR_ORANGE (0xF4C70FFF)
  23. #define COLOR_GREEN (0x0B9311FF)
  24.  
  25. #define DERBY_LIST "Derbies\\Derby.min"
  26. #define DERBY_DATA "Derbies\\%s.deb"
  27.  
  28. #define isnull(%1) ((!(%1[0])) || (((%1[0]) == '\1') && (!(%1[1]))))
  29.  
  30. forward EndDerby();
  31. forward DerbyTextdraws();
  32. forward Commence_Derby();
  33. forward InitiatePlayers();
  34. forward DerbyRequirementCheck(playerid);
  35. forward FreezeVehicle(vehicleid,toggle);
  36. forward CountdownDerby();
  37. forward Start_Derby();
  38. forward KickPlayerFromDerby(playerid, reason[]);
  39. forward RetVehicle(vehfrz,Float:VX,Float:VY,Float:VZ,Float:VA);
  40. forward VehicleToPoint(playerid, Float:radi, Float:px, Float:py, Float:pz);
  41.  
  42. enum DERBY_SETTINGS
  43. {
  44. bool:Derby_Enabled,
  45. bool:Derby_Access,
  46. bool:Derby_Start,
  47. Derby_Countdown,
  48. DerbyMaxPlayers,
  49. Derby_Current,
  50. File:DerbyFile,
  51. Derby_Timer
  52. };
  53.  
  54. enum DERBY_PDATA
  55. {
  56. Derby_Name[32],
  57. Derby_Interior,
  58. Derby_World,
  59. Derby_VehModel,
  60. Float:Derby_Minheight,
  61. bool:Derby_ActiveCheck,
  62. bool:Derby_HightMeassure
  63. };
  64.  
  65. enum DERBY_INFO
  66. {
  67. Derby_Vehicle,
  68. Float:Derby_Position[4]
  69. };
  70.  
  71. enum DERBY_PLAYERS
  72. {
  73. bool:DerbySigned,
  74. Float:DerbyJoinP[4],
  75. Float:DerbyHealth,
  76. DerbyIW[2],
  77. DerbyWeapons[13],
  78. DerbyAmmo[13],
  79. DerbyInactive
  80. };
  81.  
  82. new
  83. DerbyWait [MAX_PLAYERS],
  84. DerbyString [MAX_CLIENT_STRING],
  85. Text:DerbyTextdraw [MAX_TD_FRAMES],
  86. fv [MAX_VEHICLES],
  87. DerbyPlayers [MAX_PLAYERS][DERBY_PLAYERS],
  88. DerbySettings [DERBY_SETTINGS],
  89. DerbyData [DERBY_PDATA],
  90. DerbyCoords [MAX_DERBY_PLAYERS][DERBY_INFO],
  91. Float:D_X, Float:D_Y, Float:D_Z
  92. ;
  93.  
  94. public OnFilterScriptInit()
  95. {
  96. print("\n--------------------------------------");
  97. print(" Derby Filterscript by OutLawZ Loaded ");
  98. print("--------------------------------------\n");
  99.  
  100. if(!fexist(DERBY_LIST))
  101. {
  102. printf("Error: You don't have derby file %s", DERBY_LIST);
  103. DerbySettings[DerbyFile] = fopen(DERBY_LIST, io_write);
  104. fclose(DerbySettings[DerbyFile]);
  105. }
  106. else
  107. {
  108. new bool:Empty = true;
  109. DerbySettings[DerbyFile] = fopen(DERBY_LIST, io_read);
  110.  
  111. while(fread(DerbySettings[DerbyFile], DerbyString))
  112. if(!isnull(DerbyString)) Empty = false;
  113.  
  114. if(Empty) printf("Error: Derby file %s is empty!", DERBY_LIST);
  115. }
  116.  
  117. DerbySettings[Derby_Current] = -1;
  118. DerbySettings[Derby_Enabled] = true;
  119.  
  120. DerbyTextdraw[0] = TextDrawCreate(619.000000, 125.000000, "_");
  121. TextDrawBackgroundColor(DerbyTextdraw[0], 255);
  122. TextDrawFont(DerbyTextdraw[0], 1);
  123. TextDrawLetterSize(DerbyTextdraw[0], 0.519999, 10.200002);
  124. TextDrawColor(DerbyTextdraw[0], -1);
  125. TextDrawSetOutline(DerbyTextdraw[0], 0);
  126. TextDrawSetProportional(DerbyTextdraw[0], 1);
  127. TextDrawSetShadow(DerbyTextdraw[0], 1);
  128. TextDrawUseBox(DerbyTextdraw[0], 1);
  129. TextDrawBoxColor(DerbyTextdraw[0], 140);
  130. TextDrawTextSize(DerbyTextdraw[0], 488.000000, -1.000000);
  131. TextDrawSetSelectable(DerbyTextdraw[0], 0);
  132.  
  133. DerbyTextdraw[1] = TextDrawCreate(614.000000, 131.000000, "_");
  134. TextDrawBackgroundColor(DerbyTextdraw[1], 255);
  135. TextDrawFont(DerbyTextdraw[1], 1);
  136. TextDrawLetterSize(DerbyTextdraw[1], 0.519999, 1.799999);
  137. TextDrawColor(DerbyTextdraw[1], -1);
  138. TextDrawSetOutline(DerbyTextdraw[1], 0);
  139. TextDrawSetProportional(DerbyTextdraw[1], 1);
  140. TextDrawSetShadow(DerbyTextdraw[1], 1);
  141. TextDrawUseBox(DerbyTextdraw[1], 1);
  142. TextDrawBoxColor(DerbyTextdraw[1], 150);
  143. TextDrawTextSize(DerbyTextdraw[1], 493.000000, -1.000000);
  144. TextDrawSetSelectable(DerbyTextdraw[1], 0);
  145.  
  146. DerbyTextdraw[2] = TextDrawCreate(614.000000, 158.000000, "_");
  147. TextDrawBackgroundColor(DerbyTextdraw[2], 255);
  148. TextDrawFont(DerbyTextdraw[2], 1);
  149. TextDrawLetterSize(DerbyTextdraw[2], 0.519999, 5.599998);
  150. TextDrawColor(DerbyTextdraw[2], -1);
  151. TextDrawSetOutline(DerbyTextdraw[2], 0);
  152. TextDrawSetProportional(DerbyTextdraw[2], 1);
  153. TextDrawSetShadow(DerbyTextdraw[2], 1);
  154. TextDrawUseBox(DerbyTextdraw[2], 1);
  155. TextDrawBoxColor(DerbyTextdraw[2], 150);
  156. TextDrawTextSize(DerbyTextdraw[2], 493.000000, -1.000000);
  157. TextDrawSetSelectable(DerbyTextdraw[2], 0);
  158.  
  159. DerbyTextdraw[3] = TextDrawCreate(552.000000, 133.000000, "Diesel Induction");
  160. TextDrawAlignment(DerbyTextdraw[3], 2);
  161. TextDrawBackgroundColor(DerbyTextdraw[3], 255);
  162. TextDrawFont(DerbyTextdraw[3], 2);
  163. TextDrawLetterSize(DerbyTextdraw[3], 0.169999, 1.000000);
  164. TextDrawColor(DerbyTextdraw[3], -1179010561);
  165. TextDrawSetOutline(DerbyTextdraw[3], 0);
  166. TextDrawSetProportional(DerbyTextdraw[3], 1);
  167. TextDrawSetShadow(DerbyTextdraw[3], 1);
  168. TextDrawSetSelectable(DerbyTextdraw[3], 0);
  169.  
  170. DerbyTextdraw[4] = TextDrawCreate(554.000000, 158.000000, "Derby is going to start~n~in 0 seconds!");
  171. TextDrawAlignment(DerbyTextdraw[4], 2);
  172. TextDrawBackgroundColor(DerbyTextdraw[4], 255);
  173. TextDrawFont(DerbyTextdraw[4], 2);
  174. TextDrawLetterSize(DerbyTextdraw[4], 0.199999, 0.899999);
  175. TextDrawColor(DerbyTextdraw[4], -1);
  176. TextDrawSetOutline(DerbyTextdraw[4], 0);
  177. TextDrawSetProportional(DerbyTextdraw[4], 1);
  178. TextDrawSetShadow(DerbyTextdraw[4], 1);
  179. TextDrawSetSelectable(DerbyTextdraw[4], 0);
  180.  
  181. DerbyTextdraw[5] = TextDrawCreate(614.000000, 187.000000, "_");
  182. TextDrawBackgroundColor(DerbyTextdraw[5], 255);
  183. TextDrawFont(DerbyTextdraw[5], 1);
  184. TextDrawLetterSize(DerbyTextdraw[5], 0.519999, 1.200000);
  185. TextDrawColor(DerbyTextdraw[5], -1);
  186. TextDrawSetOutline(DerbyTextdraw[5], 0);
  187. TextDrawSetProportional(DerbyTextdraw[5], 1);
  188. TextDrawSetShadow(DerbyTextdraw[5], 1);
  189. TextDrawUseBox(DerbyTextdraw[5], 1);
  190. TextDrawBoxColor(DerbyTextdraw[5], 255);
  191. TextDrawTextSize(DerbyTextdraw[5], 493.000000, -1.000000);
  192. TextDrawSetSelectable(DerbyTextdraw[5], 0);
  193.  
  194. DerbyTextdraw[6] = TextDrawCreate(554.000000, 197.000000, "Currently 0 Joined!");
  195. TextDrawAlignment(DerbyTextdraw[6], 2);
  196. TextDrawBackgroundColor(DerbyTextdraw[6], 255);
  197. TextDrawFont(DerbyTextdraw[6], 2);
  198. TextDrawLetterSize(DerbyTextdraw[6], 0.199999, 0.899999);
  199. TextDrawColor(DerbyTextdraw[6], 463129599);
  200. TextDrawSetOutline(DerbyTextdraw[6], 0);
  201. TextDrawSetProportional(DerbyTextdraw[6], 1);
  202. TextDrawSetShadow(DerbyTextdraw[6], 1);
  203. TextDrawSetSelectable(DerbyTextdraw[6], 0);
  204.  
  205. DerbyTextdraw[7] = TextDrawCreate(488.500, 121.000, "hud:radar_race");
  206. TextDrawFont(DerbyTextdraw[7], 4);
  207. TextDrawTextSize(DerbyTextdraw[7], 14.500, 13.000);
  208. TextDrawColor(DerbyTextdraw[7], -1);
  209.  
  210. Start_Derby();
  211. return 1;
  212. }
  213.  
  214. public OnFilterScriptExit()
  215. {
  216. for(new i; i < MAX_DERBY_PLAYERS; i++)
  217. {
  218. DestroyVehicle(DerbyCoords[i][Derby_Vehicle]);
  219. DerbyCoords[i][Derby_Vehicle] = INVALID_VEHICLE_ID;
  220. }
  221.  
  222. for(new i; i < MAX_TD_FRAMES; i++)
  223. {
  224. TextDrawHideForAll(DerbyTextdraw[i]);
  225. TextDrawDestroy(DerbyTextdraw[i]);
  226. }
  227. DerbySettings[Derby_Enabled] = false;
  228. return 1;
  229. }
  230.  
  231. stock LoadNextDerby()
  232. {
  233. DerbySettings[Derby_Current] ++;
  234. new Next = -1, D_Load[32];
  235. DerbySettings[DerbyFile] = fopen(DERBY_LIST, io_read);
  236.  
  237. while(fread(DerbySettings[DerbyFile], DerbyString))
  238. {
  239. Next++;
  240. StripNewLine(DerbyString);
  241.  
  242. if(!Next) format(D_Load, sizeof D_Load, "%s", DerbyString);
  243. if(Next == DerbySettings[Derby_Current])
  244. return LoadDerby(DerbyString);
  245. }
  246. DerbySettings[Derby_Current] = 0;
  247. return LoadDerby(D_Load);
  248. }
  249.  
  250. stock LoadDerby(derbyname[])
  251. {
  252. if(DerbySettings[DerbyFile]) fclose(DerbySettings[DerbyFile]);
  253. format(DerbyString, sizeof DerbyString, DERBY_DATA, derbyname);
  254. if(!fexist(DerbyString)) return printf("ERROR: Derby Data File (%s) doesn't exist!", DerbyString);
  255.  
  256. DerbySettings[DerbyFile] = fopen(DerbyString, io_read);
  257. new Next, iIndex, Float:DCoords[4];
  258. while(fread(DerbySettings[DerbyFile], DerbyString))
  259. {
  260. StripNewLine(DerbyString);
  261. Next++;
  262.  
  263. if(!sscanf(DerbyString, "p<,>ffff", DCoords[0], DCoords[1], DCoords[2], DCoords[3]))
  264. {
  265. if(0 <= iIndex < MAX_DERBY_PLAYERS)
  266. {
  267. DerbyCoords[iIndex][Derby_Position][0] = DCoords[0];
  268. DerbyCoords[iIndex][Derby_Position][1] = DCoords[1];
  269. DerbyCoords[iIndex][Derby_Position][2] = DCoords[2];
  270. DerbyCoords[iIndex][Derby_Position][3] = DCoords[3];
  271. }
  272. iIndex++;
  273. }
  274. else if(!sscanf(DerbyString, "p<|>s[32]iiifll", DerbyData[Derby_Name], DerbyData[Derby_Interior], DerbyData[Derby_World], DerbyData[Derby_VehModel], DerbyData[Derby_Minheight], DerbyData[Derby_ActiveCheck], DerbyData[Derby_HightMeassure]))
  275. {
  276. printf("Loaded \"%s\" Header", DerbyData[Derby_Name]);
  277. }
  278. else printf("Error: Derby (%s) has invalid data format @Line %i", DerbyString, Next);
  279. }
  280. fclose(DerbySettings[DerbyFile]);
  281.  
  282. if(iIndex != MAX_DERBY_PLAYERS) printf("Warning: Loaded Coords for %i derby players (Required: %i)", iIndex, MAX_DERBY_PLAYERS);
  283.  
  284. else printf("Loaded Coordinates for all players");
  285. return 1;
  286. }
  287.  
  288. stock StripNewLine(string[]) // DracoBlue
  289. {
  290. new len = strlen(string);
  291. if (string[0]==0) return;
  292. if ((string[len - 1] == '\n') || (string[len - 1] == '\r')) {
  293. string[len - 1] = 0;
  294. if (string[0]==0) return;
  295. if ((string[len - 2] == '\n') || (string[len - 2] == '\r')) string[len - 2] = 0;
  296. }
  297. }
  298.  
  299. public Commence_Derby()
  300. {
  301. DerbySettings[Derby_Access] = false;
  302.  
  303. if(DerbySettings[DerbyMaxPlayers] < 2)
  304. {
  305. for(new i; i < MAX_PLAYERS; i++)
  306. {
  307. TextDrawHideForPlayer(i, DerbyTextdraw[0]);
  308. TextDrawHideForPlayer(i, DerbyTextdraw[1]);
  309. TextDrawHideForPlayer(i, DerbyTextdraw[2]);
  310. TextDrawHideForPlayer(i, DerbyTextdraw[3]);
  311. TextDrawHideForPlayer(i, DerbyTextdraw[4]);
  312. TextDrawHideForPlayer(i, DerbyTextdraw[5]);
  313. TextDrawHideForPlayer(i, DerbyTextdraw[6]);
  314. TextDrawHideForPlayer(i, DerbyTextdraw[7]);
  315. DerbyPlayers[i][DerbySigned] = false;
  316. }
  317. SendClientMessageToAll(COLOR_GREEN, "Derby Event couldn't start because there were not enough players (Next derby in "#DERBY_INTERMISSION" seconds)");
  318. if(DerbySettings[Derby_Enabled]) SetTimer("Start_Derby", strval(DERBY_INTERMISSION) * 1000, false);
  319. DerbySettings[Derby_Start] = false;
  320. return 1;
  321. }
  322.  
  323. for(new i; i < DerbySettings[DerbyMaxPlayers]; i++)
  324. {
  325. for(new a; a < MAX_PLAYERS; a++) TextDrawHideForPlayer(i, DerbyTextdraw[a]);
  326. DerbyCoords[i][Derby_Vehicle] = CreateVehicle(DerbyData[Derby_VehModel], DerbyCoords[i][Derby_Position][0], DerbyCoords[i][Derby_Position][1], DerbyCoords[i][Derby_Position][2], DerbyCoords[i][Derby_Position][3], -1, -1, 999999);
  327. LinkVehicleToInterior(DerbyCoords[i][Derby_Vehicle], DerbyData[Derby_Interior]);
  328. SetVehicleVirtualWorld(DerbyCoords[i][Derby_Vehicle], DerbyData[Derby_World]);
  329. FreezeVehicle((DerbyCoords[i][Derby_Vehicle]), true);
  330. DerbyPlayers[i][DerbyInactive] = 0;
  331. }
  332. SetTimer("InitiatePlayers", 3000, 0);
  333. SendClientMessageToAll(COLOR_GREEN, "Derby Initializing...");
  334. return 1;
  335. }
  336.  
  337. public InitiatePlayers()
  338. {
  339. new iIndex;
  340. for(new i; i<MAX_PLAYERS; i++)
  341. {
  342. if(!DerbyPlayers[i][DerbySigned]) continue;
  343.  
  344. GetPlayerPos(i, DerbyPlayers[i][DerbyJoinP][0], DerbyPlayers[i][DerbyJoinP][1], DerbyPlayers[i][DerbyJoinP][2]);
  345. GetPlayerFacingAngle(i, DerbyPlayers[i][DerbyJoinP][3]);
  346. DerbyPlayers[i][DerbyIW][0] = GetPlayerInterior(i);
  347. DerbyPlayers[i][DerbyIW][1] = GetPlayerVirtualWorld(i);
  348. for(new w; w < 13; w++) GetPlayerWeaponData(i, w, DerbyPlayers[i][DerbyWeapons][w], DerbyPlayers[i][DerbyAmmo][w]);
  349.  
  350. RemovePlayerFromVehicle(i);
  351. ResetPlayerWeapons(i);
  352.  
  353. SetPlayerInterior(i, DerbyData[Derby_Interior]);
  354. SetPlayerVirtualWorld(i, DerbyData[Derby_World]);
  355. PutPlayerInVehicle(i, DerbyCoords[iIndex][Derby_Vehicle], 0);
  356. TogglePlayerControllable(i, false);
  357. iIndex++;
  358. }
  359. DerbySettings[Derby_Countdown] = strval(DERBY_COUNTDOWN) + 1;
  360. DerbySettings[Derby_Start] = true;
  361. CountdownDerby();
  362. return 1;
  363. }
  364.  
  365. public CountdownDerby()
  366. {
  367. new D_Small[5];
  368. DerbySettings[Derby_Countdown] --;
  369. if(DerbySettings[Derby_Countdown] >= 1)
  370. {
  371. format(D_Small, sizeof D_Small, "%i", DerbySettings[Derby_Countdown]);
  372. for(new i = 0; i < MAX_PLAYERS ;i++)
  373. {
  374. if(!DerbyPlayers[i][DerbySigned]) continue;
  375. GameTextForPlayer(i, D_Small, 1600, 5);
  376. }
  377. SetTimer("CountdownDerby", 2000, false);
  378. }
  379. else
  380. {
  381. for(new i; i < MAX_PLAYERS ;i++)
  382. {
  383. if(!DerbyPlayers[i][DerbySigned]) continue;
  384. GameTextForPlayer(i, "~g~GO", 999, 5);
  385. PlayerPlaySound(i, 1057, 0.0, 0.0, 10.0);
  386. TogglePlayerControllable(i, true);
  387. if(!IsPlayerInAnyVehicle(i)) KickPlayerFromDerby(i, "You lost the derby for exiting your vehicle.");
  388. FreezeVehicle(GetPlayerVehicleID(i), false);
  389. }
  390. DerbySettings[Derby_Timer] = SetTimer("DerbyRequirementCheck", 1000, false);
  391. format(DerbyString, sizeof DerbyString, "Derby \"%s\" has been started!", DerbyData[Derby_Name]);
  392. SendClientMessageToAll(COLOR_GREEN, DerbyString);
  393. }
  394. return 1;
  395. }
  396.  
  397.  
  398. public KickPlayerFromDerby(playerid, reason[])
  399. {
  400. DerbyPlayers[playerid][DerbySigned] = false;
  401. SendClientMessage(playerid, COLOR_ERROR, reason);
  402. if(DerbySettings[DerbyMaxPlayers] < 2) return EndDerby();
  403. SetPlayerPos(playerid, DerbyPlayers[playerid][DerbyJoinP][0], DerbyPlayers[playerid][DerbyJoinP][1], DerbyPlayers[playerid][DerbyJoinP][2]);
  404. SetPlayerFacingAngle(playerid, DerbyPlayers[playerid][DerbyJoinP][3]);
  405. SetPlayerInterior(playerid, DerbyPlayers[playerid][DerbyIW][0]);
  406. SetPlayerVirtualWorld(playerid, DerbyPlayers[playerid][DerbyIW][1]);
  407. ResetPlayerWeapons(playerid);
  408. for(new w; w < 13; w++) GivePlayerWeapon(playerid, DerbyPlayers[playerid][DerbyWeapons][w], DerbyPlayers[playerid][DerbyAmmo][w]);
  409. DerbySettings[DerbyMaxPlayers] --;
  410. return 1;
  411. }
  412.  
  413. public DerbyRequirementCheck(playerid)
  414. {
  415. if(DerbySettings[DerbyMaxPlayers] < MIN_DERBY_PLAYERS) return EndDerby();
  416.  
  417. static CheckLocalData;
  418. CheckLocalData++;
  419.  
  420. for(new i; i<MAX_PLAYERS; i++)
  421. {
  422. if(!DerbyPlayers[i][DerbySigned]) continue;
  423. if(DerbyData[Derby_HightMeassure])
  424. {
  425. GetPlayerPos(i, D_X, D_Y, D_Z);
  426. if (D_Z < DerbyData[Derby_Minheight]) KickPlayerFromDerby(i, "You lost the derby for falling out of range.");
  427. }
  428. if(!IsPlayerInAnyVehicle(i))
  429. {
  430. KickPlayerFromDerby(i, "You lost the derby for exiting your vehicle.");
  431. continue;
  432. }
  433. if(CheckLocalData >= 20)
  434. {
  435. if(DerbyData[Derby_ActiveCheck])
  436. {
  437. GetVehicleHealth(GetPlayerVehicleID(i), D_X);
  438. if(D_X == DerbyPlayers[i][DerbyHealth])
  439. {
  440. if(++DerbyPlayers[i][DerbyInactive] >= 20)
  441. {
  442. GetVehicleHealth(GetPlayerVehicleID(i), D_Y);
  443. SetVehicleHealth(GetPlayerVehicleID(i), D_Y - 150.00);
  444. SendClientMessage(i, 0xFF0000FF, "Your vehicle health is decreased by 150 for avoiding being hit.");
  445. }
  446. }
  447. else
  448. {
  449. DerbyPlayers[i][DerbyHealth] = D_X;
  450. DerbyPlayers[i][DerbyInactive] = 0;
  451. }
  452. }
  453. CheckLocalData = 0;
  454. }
  455. }
  456. if(DerbySettings[Derby_Start]) SetTimer("DerbyRequirementCheck", 1000, false);
  457. return 1;
  458. }
  459.  
  460. public EndDerby()
  461. {
  462. if(DerbySettings[DerbyMaxPlayers] >= 2) return 1;
  463. if(!DerbySettings[Derby_Start]) return 1;
  464.  
  465. DerbySettings[Derby_Start] = false;
  466. KillTimer(DerbySettings[Derby_Timer]);
  467.  
  468. #if defined ENABLE_CLIENT_MSG
  469. format(DerbyString, sizeof DerbyString, "Derby \"%s\" has ended, (Next derby in "#DERBY_INTERMISSION" seconds)", DerbyData[Derby_Name]);
  470. SendClientMessageToAll(COLOR_GREEN, DerbyString);
  471. #endif
  472.  
  473. for(new i; i < MAX_PLAYERS; i++)
  474. {
  475. if(!DerbyPlayers[i][DerbySigned]) continue;
  476. DerbyPlayers[i][DerbySigned] = false;
  477.  
  478. GetPlayerName(i, DerbyString, MAX_PLAYER_NAME);
  479. format(DerbyString, sizeof DerbyString, "%s won the derby with a reward of $"#MONEY_REWARD" and "#SCORE_REWARD" points", DerbyString);
  480. SendClientMessageToAll(COLOR_GREEN, DerbyString);
  481.  
  482. GivePlayerMoney(i, strval(MONEY_REWARD));
  483. SetPlayerScore(i, GetPlayerScore(i) + strval(SCORE_REWARD));
  484.  
  485. SetPlayerPos(i, DerbyPlayers[i][DerbyJoinP][0], DerbyPlayers[i][DerbyJoinP][1], DerbyPlayers[i][DerbyJoinP][2]);
  486. SetPlayerFacingAngle(i, DerbyPlayers[i][DerbyJoinP][3]);
  487. SetPlayerInterior(i, DerbyPlayers[i][DerbyIW][0]);
  488. SetPlayerVirtualWorld(i, DerbyPlayers[i][DerbyIW][1]);
  489. ResetPlayerWeapons(i);
  490. for(new w; w < 13; w++) GivePlayerWeapon(i, DerbyPlayers[i][DerbyWeapons][w], DerbyPlayers[i][DerbyAmmo][w]);
  491. }
  492.  
  493. for(new i; i < MAX_DERBY_PLAYERS; i++)
  494. {
  495. DestroyVehicle(DerbyCoords[i][Derby_Vehicle]);
  496. DerbyCoords[i][Derby_Vehicle] = INVALID_VEHICLE_ID;
  497. }
  498.  
  499. DerbySettings[DerbyMaxPlayers] = 0;
  500. DerbySettings[Derby_Countdown] = 0;
  501. DerbySettings[Derby_Access] = false;
  502.  
  503. if(DerbySettings[Derby_Enabled]) SetTimer("Start_Derby", strval(DERBY_INTERMISSION) * 1000, false);
  504. return 1;
  505. }
  506.  
  507. public Start_Derby()
  508. {
  509. LoadNextDerby();
  510.  
  511. #if defined ENABLE_CLIENT_MSG
  512. format(DerbyString, sizeof DerbyString,"%s is going to start in "#DERBY_COOLDOWN" seconds, /derby to sign up.", DerbyData[Derby_Name]);
  513. SendClientMessageToAll(COLOR_GREEN, DerbyString);
  514. #endif
  515.  
  516. DerbySettings[DerbyMaxPlayers] = 0;
  517. DerbySettings[Derby_Access] = true;
  518. DerbySettings[Derby_Countdown] = strval(DERBY_COOLDOWN);
  519.  
  520. for(new i; i < MAX_PLAYERS; i++)
  521. {
  522. for(new w; w < MAX_TD_FRAMES; w++) TextDrawShowForPlayer(i, DerbyTextdraw[w]);
  523. DerbyWait[i] = 0;
  524. }
  525. DerbyTextdraws();
  526. return 1;
  527. }
  528.  
  529. public DerbyTextdraws()
  530. {
  531. DerbySettings[Derby_Countdown] --;
  532. TextDrawSetString(DerbyTextdraw[3], DerbyData[Derby_Name]);
  533.  
  534. format(DerbyString, sizeof DerbyString, "Derby is going to start~n~in %i seconds!", DerbySettings[Derby_Countdown]);
  535. TextDrawSetString(DerbyTextdraw[4], DerbyString);
  536.  
  537. format(DerbyString, sizeof DerbyString, "Currently %i Joined!", DerbySettings[DerbyMaxPlayers]);
  538. TextDrawSetString(DerbyTextdraw[6], DerbyString);
  539.  
  540. if(DerbySettings[Derby_Countdown] <= 0)
  541. {
  542. for(new i = 0; i < MAX_PLAYERS;i++)
  543. {
  544. if(IsPlayerConnected(i) && DerbyPlayers[i][DerbySigned])
  545. {
  546. TextDrawHideForPlayer(i, DerbyTextdraw[4]);
  547. TextDrawHideForPlayer(i, DerbyTextdraw[6]);
  548. }
  549. }
  550. Commence_Derby();
  551. }
  552. else SetTimer("DerbyTextdraws", 1000, 0);
  553. }
  554.  
  555. public OnPlayerConnect(playerid)
  556. {
  557. DerbyWait[playerid] = gettime() + 45; // I added this to prevent textdraw bugs!
  558. return 1;
  559. }
  560.  
  561. public OnPlayerDisconnect(playerid, reason)
  562. {
  563. if(DerbyPlayers[playerid][DerbySigned])
  564. {
  565. DerbySettings[DerbyMaxPlayers] --;
  566. DerbyPlayers[playerid][DerbySigned] = false;
  567. }
  568. return 1;
  569. }
  570.  
  571. public OnPlayerDeath(playerid, killerid, reason)
  572. {
  573. if(DerbyPlayers[playerid][DerbySigned] && DerbySettings[Derby_Start])
  574. {
  575. DerbySettings[DerbyMaxPlayers] --;
  576. DerbyPlayers[playerid][DerbySigned] = false;
  577. if(DerbySettings[DerbyMaxPlayers] < 2) return EndDerby();
  578. GameTextForPlayer(playerid, "~r~You have been kicked out!", 4000, 0);
  579. }
  580. return 1;
  581. }
  582.  
  583. public OnPlayerExitVehicle(playerid, vehicleid)
  584. {
  585. if(DerbyPlayers[playerid][DerbySigned] && DerbySettings[Derby_Start])
  586. {
  587. KickPlayerFromDerby(playerid, "You lost the derby for exiting your vehicle.");
  588. }
  589. return 1;
  590. }
  591.  
  592. public FreezeVehicle(vehicleid, toggle) // Seif
  593. {
  594. new Float:fvX,Float:fvY,Float:fvZ,Float:fvA;
  595. new mp = GetMaxPlayers();
  596. for(new all = 0; all < mp; all++)
  597. {
  598. if (GetPlayerState(all) == 2)
  599. {
  600. if (GetPlayerVehicleID(all) == vehicleid)
  601. {
  602. TogglePlayerControllable(all,0);
  603. TogglePlayerControllable(all,1);
  604. }
  605. }
  606. }
  607. GetVehiclePos(vehicleid,fvX,fvY,fvZ);
  608. GetVehicleZAngle(vehicleid,fvA);
  609.  
  610. if (toggle == 1) fv[vehicleid] = SetTimerEx("RetVehicle", 200,1,"iffff",vehicleid,fvX,fvY,fvZ,fvA);
  611. else KillTimer(fv[vehicleid]);
  612. }
  613.  
  614. public RetVehicle(vehfrz,Float:VX,Float:VY,Float:VZ,Float:VA)
  615. {
  616. if (!VehicleToPoint(vehfrz,1.0,VX,VY,VZ))
  617. {
  618. SetVehiclePos(vehfrz,VX,VY,VZ);
  619. SetVehicleZAngle(vehfrz,VA);
  620. }
  621. }
  622.  
  623. public VehicleToPoint(playerid, Float:radi, Float:px, Float:py, Float:pz)
  624. {
  625. if(IsPlayerConnected(playerid))
  626. {
  627. new Float:x, Float:y, Float:z;
  628. new Float:ox, Float:oy, Float:oz;
  629. GetVehiclePos(playerid, ox, oy, oz);
  630. x = (ox -px);
  631. y = (oy -py);
  632. z = (oz -pz);
  633. if (((x < radi) && (x > -radi)) && ((y < radi) && (y > -radi)) && ((z < radi) && (z > -radi))) return 1;
  634. }
  635. return 0;
  636. }
  637.  
  638. public OnPlayerCommandText(playerid, cmdtext[])
  639. {
  640. if (strcmp("/derby", cmdtext, true, 10) == 0)
  641. {
  642. if(!DerbySettings[Derby_Enabled]) return SendClientMessage(playerid, COLOR_ERROR, "Derbies are currently closed.");
  643. if(!DerbySettings[Derby_Access]) return SendClientMessage(playerid, COLOR_ERROR, "Derby signups are currently closed, wait for the next one to start.");
  644. if(DerbyPlayers[playerid][DerbySigned]) return SendClientMessage(playerid, COLOR_ERROR, "You already signed up for the derby, wait for it to start!");
  645. if(DerbyWait[playerid] - gettime() > 1) return SendClientMessage(playerid, COLOR_ERROR, "Please wait before you can join the derby!");
  646. if(DerbySettings[DerbyMaxPlayers] >= MAX_DERBY_PLAYERS) return SendClientMessage(playerid, COLOR_ERROR, "The arena is full!");
  647.  
  648. DerbySettings[DerbyMaxPlayers] ++;
  649. DerbyPlayers[playerid][DerbySigned] = true;
  650. GetPlayerName(playerid, DerbyString, MAX_PLAYER_NAME);
  651.  
  652. SendClientMessage(playerid, COLOR_ORANGE, "You have successfully signed up for the derby!");
  653. TextDrawShowForPlayer(playerid, DerbyTextdraw[6]);
  654.  
  655. #if defined ENABLE_CLIENT_MSG
  656. format(DerbyString, sizeof DerbyString, "%s has signed up for derby using /derby", DerbyString);
  657. SendClientMessageToAll(COLOR_ORANGE, DerbyString);
  658. #endif
  659.  
  660. return 1;
  661. }
  662. return 0;
  663. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement