DjoLe11

Untitled

Sep 28th, 2019
254
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 53.39 KB | None | 0 0
  1. #include <a_samp>
  2. #include <zcmd>
  3. #include <dini>
  4. #include <sscanf2>
  5.  
  6. //=====[Internal Settings]=====
  7. #define MINMONEY 0 //Minimum duel bet money - Useful for A/D servers. Set to 0 for A/D
  8. #define MAX_DUELS 40 //Max duel maps.
  9. #define MAX_DUEL_WEPS 3
  10. #define MAX_INVITES 14
  11. #define INVITERESET 60000 //Total time until an invite is considered denied
  12.  
  13. #define Money_GivePlayerMoney GivePlayerMoney //Replace with your own money functions if you have a money anticheat
  14. #define Money_GetPlayerMoney GetPlayerMoney
  15. #define DUELFILES "/Duels/%d.ini" //Set your own directory for the duel system.. Change DUEL_IDFILE too.
  16. #define DUEL_IDFILE "/Duels/idset.ini"
  17.  
  18. #define SPEC_UPDATE 1000
  19. #define DUELDIAG 6550
  20. //=============================
  21.  
  22. #define COLOR_RED 0xFF0000
  23. #define COLOR_DUEL 0x00C224
  24.  
  25. //String Color
  26. #define G> 009900 //Green
  27. #define R> CC0000 //Red
  28. #define B> 0004B6 //Blue
  29. #define LB> 00EFFC //Light Blue
  30. #define O> FFD700 //Orange
  31. #define Y> FFD700 //Yellow
  32. #define W> FFFFFF //White
  33. #define BV> 8A2BE2 //Blue Violet
  34.  
  35. new DuelTimer[MAX_PLAYERS];
  36. new UpdateSpecTimer[MAX_PLAYERS];
  37.  
  38. forward DuelReset(player1, player2);
  39. forward DuelCDUpdate(playerid);
  40. forward UpdateSpectate(playerid);
  41.  
  42. new dFile[70];
  43. new diagstr[900];
  44. new Text:SpecTD[MAX_PLAYERS][2];
  45.  
  46. new diagitem[25];
  47. new dinvitem[MAX_PLAYERS][MAX_INVITES];
  48.  
  49. new InDuel[MAX_PLAYERS];
  50.  
  51. enum duels
  52. {
  53. Inviter,
  54. Invitee,
  55. BetMoney,
  56. Location,
  57. Started
  58. }
  59. new dInfo[MAX_DUELS][duels];
  60. new dWeps[MAX_DUELS][MAX_DUEL_WEPS];
  61. new TotalDuels; //Total duels in progress
  62.  
  63. public OnFilterScriptInit()
  64. {
  65. SendClientMessageToAll(COLOR_DUEL, "Duel System v1.6 by PotH3Ad initialized!");
  66. print(" Duel System v1.6 by PotH3Ad initialized!");
  67. for(new x=0; x<MAX_INVITES; x++) ResetDuelInvites(x);
  68. return 1;
  69. }
  70.  
  71. public OnFilterScriptExit()
  72. {
  73. SendClientMessageToAll(COLOR_DUEL, "Duel System v1.6 by PotH3Ad has been unloaded!");
  74. print(" Duel System v1.6 by PotH3Ad has been unloaded!");
  75. return 1;
  76. }
  77.  
  78. public OnPlayerConnect(playerid)
  79. {
  80. LoadDuelSpecTextdraw(playerid);
  81. ResetDuelInvites(playerid);
  82. SetPVarInt(playerid, "DuelDID", -1);
  83. InDuel[playerid] = 0;
  84. return 1;
  85. }
  86.  
  87. public OnPlayerDisconnect(playerid, reason)
  88. {
  89. new duelid = GetPVarInt(playerid, "DuelDID");
  90. new dueler, dueler2;
  91. dueler = dInfo[duelid][Inviter];
  92. dueler2 = dInfo[duelid][Invitee];
  93.  
  94. if(InDuel[dueler] == 1 && InDuel[dueler2] == 1)
  95. {
  96. new sReason[15];
  97. switch(reason)
  98. {
  99. case 0: format(sReason, sizeof(sReason), "Timeout");
  100. case 1: format(sReason, sizeof(sReason), "Leaving");
  101. case 2: format(sReason, sizeof(sReason), "Kicked");
  102. }
  103.  
  104. new gBet = dInfo[duelid][BetMoney];
  105. new gDuelSpot = dInfo[duelid][Location];
  106.  
  107. new Slot[MAX_DUEL_WEPS];
  108. for(new i=0; i < MAX_DUEL_WEPS; i++) Slot[i] = dWeps[duelid][i];
  109.  
  110. new winner, loser;
  111. if(dueler == playerid)
  112. {
  113. winner = dueler2;
  114. loser = dueler;
  115. }
  116. else if(dueler2 == playerid)
  117. {
  118. winner = dueler;
  119. loser = dueler2;
  120. }
  121. Money_GivePlayerMoney(winner, gBet);
  122.  
  123. new wepstr[200];
  124. for(new x=0; x < MAX_DUEL_WEPS; x++)
  125. {
  126. if(IsValidWeapon(Slot[x])) format(wepstr, sizeof(wepstr), "%s%s ", wepstr, weaponNames(Slot[x]));
  127. }
  128.  
  129. new str[150];
  130. format(str, sizeof(str), "Duel | %s has left the server during a duel with %s (Reason: %s)", pName(loser), pName(winner), sReason);
  131. SendClientMessageToAll(COLOR_DUEL, str);
  132. format(str, sizeof(str), "Duel | %s won the duel against %s (Weapons %s) (Bet: $%d) (%s [ID %d])", pName(winner), pName(loser), wepstr, gBet, ReturnDuelNameFromID(gDuelSpot), gDuelSpot);
  133. SendClientMessageToAll(COLOR_DUEL, str);
  134.  
  135. SetPlayerArmour(winner, 0);
  136. RemoveFromDuel(loser);
  137. RemoveFromDuel(winner);
  138. ResetDuelInformation(duelid);
  139. RemoveDuelInvite(dueler2, dueler);
  140. SpawnPlayer(winner);
  141. SetPlayerVirtualWorld(winner, 0);
  142. TotalDuels--;
  143. }
  144.  
  145. TextDrawDestroy(SpecTD[playerid][0]);
  146. TextDrawDestroy(SpecTD[playerid][1]);
  147. InDuel[playerid] = 0;
  148. KillTimer(DuelTimer[playerid]);
  149. return 1;
  150. }
  151.  
  152. public OnPlayerDeath(playerid, killerid, reason)
  153. {
  154. new duelid = GetPVarInt(killerid, "DuelDID");
  155. new dueler, dueler2;
  156. dueler = dInfo[duelid][Inviter];
  157. dueler2 = dInfo[duelid][Invitee];
  158.  
  159. if(InDuel[dueler] == 1 && InDuel[dueler2] == 1)
  160. {
  161. new gBet = dInfo[duelid][BetMoney];
  162. new gDuelSpot = dInfo[duelid][Location];
  163.  
  164. new Slot[MAX_DUEL_WEPS];
  165. for(new i=0; i < MAX_DUEL_WEPS; i++) Slot[i] = dWeps[duelid][i];
  166.  
  167. new winner, loser;
  168. if(dueler == playerid)
  169. {
  170. winner = dueler2;
  171. loser = dueler;
  172. }
  173. else if(dueler2 == playerid)
  174. {
  175. winner = dueler;
  176. loser = dueler2;
  177. }
  178. Money_GivePlayerMoney(winner, gBet);
  179. Money_GivePlayerMoney(loser, -gBet);
  180.  
  181. new wepstr[200];
  182. for(new x=0; x < MAX_DUEL_WEPS; x++)
  183. {
  184. if(IsValidWeapon(Slot[x])) format(wepstr, sizeof(wepstr), "%s%s ", wepstr, weaponNames(Slot[x]));
  185. }
  186.  
  187. new str[230], duelloc[40];
  188. new HPT = GetRoundedTotalHP(playerid);
  189. format(duelloc, sizeof(duelloc), "%s", ReturnDuelNameFromID(gDuelSpot));
  190. format(str, sizeof(str), "Duel | %s won the duel against %s {0004B6}(HP %d) (Weapons %s) {009900}(Bet: $%d) {F8FF3D}(%s [ID %d])", pName(killerid), pName(playerid), HPT, wepstr, gBet, duelloc, gDuelSpot);
  191. SendClientMessageToAll(COLOR_RED, str);
  192.  
  193. SetPlayerArmour(playerid, 0);
  194. SetPlayerArmour(killerid, 0);
  195. RemoveFromDuel(playerid);
  196. RemoveFromDuel(killerid);
  197. ResetDuelInformation(duelid);
  198. SpawnPlayer(killerid);
  199. TotalDuels--;
  200. RemoveDuelInvite(dueler2, dueler);
  201. }
  202. else if(killerid == INVALID_PLAYER_ID && InDuel[playerid] == 1)
  203. {
  204. new gBet = dInfo[duelid][BetMoney];
  205. new gDuelSpot = dInfo[duelid][Location];
  206.  
  207. new Slot[MAX_DUEL_WEPS];
  208. for(new i=0; i < MAX_DUEL_WEPS; i++) Slot[i] = dWeps[duelid][i];
  209.  
  210. Money_GivePlayerMoney(playerid, -gBet);
  211. Money_GivePlayerMoney(killerid, gBet);
  212.  
  213. new winner, loser;
  214. if(dueler == playerid)
  215. {
  216. winner = dueler2;
  217. loser = dueler;
  218. }
  219. else if(dueler2 == playerid)
  220. {
  221. winner = dueler;
  222. loser = dueler2;
  223. }
  224.  
  225. new wepstr[200];
  226. for(new x=0; x < MAX_DUEL_WEPS; x++)
  227. {
  228. if(IsValidWeapon(Slot[x])) format(wepstr, sizeof(wepstr), "%s%s ", wepstr, weaponNames(Slot[x]));
  229. }
  230.  
  231. new str[220];
  232. format(str, sizeof(str), "Duel | %s commited suicide during a duel with %s {0004B6}(Weapons %s) {009900}(Bet: $%d) {F8FF3D}(%s [ID %d])", pName(loser), pName(winner), wepstr, gBet, ReturnDuelNameFromID(gDuelSpot), gDuelSpot);
  233. SendClientMessageToAll(COLOR_DUEL, str);
  234.  
  235. SetPlayerArmour(winner, 0);
  236. SetPlayerArmour(loser, 0);
  237. RemoveDuelInvite(dueler2, dueler);
  238. RemoveFromDuel(winner);
  239. RemoveFromDuel(loser);
  240. ResetDuelInformation(duelid);
  241. SpawnPlayer(winner);
  242. SetPlayerVirtualWorld(winner, 0);
  243. TotalDuels--;
  244. }
  245. return 1;
  246. }
  247.  
  248. public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
  249. {
  250. if(newkeys == KEY_FIRE)
  251. {
  252. new specid = GetPVarInt(playerid, "DuelSpecID");
  253. if(GetPVarInt(playerid, "DuelSpec") && IsPlayerInDuel(specid))
  254. {
  255. SetPlayerSpectatingDuel(playerid, GetDuelerID(specid));
  256. }
  257. }
  258. return 1;
  259. }
  260.  
  261. public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
  262. {
  263. if(dialogid == DUELDIAG)
  264. {
  265. if(response)
  266. {
  267. switch(listitem)
  268. {
  269. case 0: //Choose player
  270. {
  271. ShowPlayerDialog(playerid, DUELDIAG+1, DIALOG_STYLE_INPUT, "Duel - Select a player", "{"#BV>"}Type in the playername or ID of the player you want\nto invite to a duel.\n\n{"#B>"}NOTE: You can enter partial names.", "Invite", "Back");
  272. }
  273. case 1: //Choose Duel location
  274. {
  275. format(diagstr, sizeof(diagstr), "ID\tDuel Name\n");
  276. for(new x=0; x<MAX_DUELS; x++)
  277. {
  278. format(dFile, sizeof(dFile), DUELFILES, x);
  279. if(strlen(dini_Get(dFile, "duelName")) > 0) format(diagstr, sizeof(diagstr), "%s%d\t%s\n", diagstr, x, dini_Get(dFile, "duelName"));
  280. else format(diagstr, sizeof(diagstr), "%s%d\tEmpty Slot\n", diagstr, x);
  281. }
  282. ShowPlayerDialog(playerid, DUELDIAG+2, DIALOG_STYLE_LIST, "Duel List", diagstr, "Select", "Exit");
  283. return 1;
  284. }
  285. case 2: //Choose weapons
  286. {
  287. ShowPlayerDialog(playerid, DUELDIAG+5, DIALOG_STYLE_LIST, "Select Weapon Slot", "Slot 1\nSlot 2\nSlot 3", "Select", "Back");
  288. }
  289. case 3: //Choose Duel Money
  290. {
  291. ShowPlayerDialog(playerid, DUELDIAG+4, DIALOG_STYLE_INPUT, "Set Bet Amount", "{"#B>"}NOTE: {"#W>"}Set the bet amount for the duel.\n\n{"#G>"}The winner takes the money and the loser\nloses this amount of money.", "Set", "Back");
  292. }
  293. case 4: //Send invitation
  294. {
  295. new str[80];
  296. new dPID = GetPVarInt(playerid, "dPID");
  297. new dBet = GetPVarInt(playerid, "dBet");
  298. new dLoc = GetPVarInt(playerid, "dLoc");
  299. new dWep[3], key[7];
  300. for(new x=0; x<=2; x++)
  301. {
  302. format(key, sizeof(key), "dWep%d", x);
  303. dWep[x] = GetPVarInt(playerid, key);
  304. }
  305. format(str, sizeof(str), "invite %d %d %d %d %d %d", dPID, dBet, dLoc, dWep[0], dWep[1], dWep[2]);
  306. return cmd_duel(playerid, str);
  307. }
  308. case 5: //Cancel invitation
  309. {
  310. return SendClientMessage(playerid, COLOR_DUEL, "Duel invite was canceled, duel settings were saved.");
  311. }
  312. }
  313. }
  314. }
  315. if(dialogid == DUELDIAG+1)
  316. {
  317. if(response)
  318. {
  319. new invitee;
  320. if(sscanf(inputtext, "u", invitee)) return ShowPlayerDialog(playerid, DUELDIAG+1, DIALOG_STYLE_INPUT, "Duel - Select a player", "{"#BV>"}Type in the playername or ID of the player you want\nto invite to a duel.\n\n{"#B>"}NOTE: You can enter partial names.", "Invite", "Back");
  321. if(invitee == playerid) return ShowPlayerDialog(playerid, DUELDIAG+1, DIALOG_STYLE_INPUT, "Duel - Select a player", "{"#R>"}ERROR: You cannot invite yourself to a duel!\n\n{"#BV>"}Type in the playername or ID of the player you want\nto invite to a duel.\n\n{"#B>"}NOTE: You can enter partial names.", "Invite", "Back");
  322. if(invitee == INVALID_PLAYER_ID || !IsPlayerConnected(invitee)) return ShowPlayerDialog(playerid, DUELDIAG+1, DIALOG_STYLE_INPUT, "Duel - Select a player", "{"#R>"}ERROR: The player specified is not connected, try again!\n\n{"#BV>"}Type in the playername or ID of the player you want\nto invite to a duel.\n\n{"#B>"}NOTE: You can enter partial names.", "Invite", "Back");
  323. SetPVarInt(playerid, "dPID", invitee);
  324. ShowDuelSettingsDialog(playerid);
  325. }
  326. else ShowDuelSettingsDialog(playerid);
  327. }
  328. if(dialogid == DUELDIAG+2)
  329. {
  330. if(response)
  331. {
  332. format(dFile, sizeof(dFile), DUELFILES, listitem-1);
  333. if(!dini_Exists(dFile)) return OnDialogResponse(playerid, DUELDIAG, 1, 1, "blank");
  334. SetPVarInt(playerid, "dLoc", listitem-1);
  335. ShowDuelSettingsDialog(playerid);
  336. }
  337. else ShowDuelSettingsDialog(playerid);
  338. }
  339. if(dialogid == DUELDIAG+4) //Duel money
  340. {
  341. if(response)
  342. {
  343. new amount;
  344. if(sscanf(inputtext, "d", amount)) return ShowPlayerDialog(playerid, DUELDIAG+4, DIALOG_STYLE_INPUT, "Set Bet Amount", "Enter the bet amount for the duel.\nThe winner takes the money and the loser\nloses this amount of money.", "Set", "Back");
  345. if(MINMONEY != 0 && amount < 500) return ShowPlayerDialog(playerid, DUELDIAG+4, DIALOG_STYLE_INPUT, "Set Bet Amount", "ERROR: Bet amount must be higher then $500!\nSet the bet amount for the duel.\nThe winner takes the money and the loser\nloses this amount of money.", "Set", "Back");
  346. SetPVarInt(playerid, "dBet", amount);
  347. ShowDuelSettingsDialog(playerid);
  348. }
  349. else ShowDuelSettingsDialog(playerid);
  350. }
  351. if(dialogid == DUELDIAG+5) //Weapon slots
  352. {
  353. if(response)
  354. {
  355. SetPVarInt(playerid, "dWSlot", listitem);
  356. ShowPlayerDialog(playerid, DUELDIAG+6, DIALOG_STYLE_LIST, "Choose a weapon", "Brass Knuckles\nGolf Club\nNite Stick\nKnife\nBaseball Bat\nShovel\nPool Cue\nKatana\nChainsaw\nDildo\nVibrator\nFlowers\nCane\nGrenade\nTeargas\nMolotov\nColt 45\nSilenced Pistol\nDeagle\nShotgun\nSawns\nSpas\nUzi\nMP5\nAK47\nM4\nTec9\nRifle\nSniper", "Select", "Back");
  357. }
  358. else ShowDuelSettingsDialog(playerid);
  359. }
  360. if(dialogid == DUELDIAG+6)
  361. {
  362. if(response)
  363. {
  364. new key[7];
  365. format(key, sizeof(key), "dWep%d", GetPVarInt(playerid, "dWSlot"));
  366. switch(listitem)
  367. {
  368. case 13..15:
  369. {
  370. ShowPlayerDialog(playerid, DUELDIAG+6, DIALOG_STYLE_LIST, "Choose a weapon", "Brass Knuckles\nGolf Club\nNite Stick\nKnife\nBaseball Bat\nShovel\nPool Cue\nKatana\nChainsaw\nDildo\nVibrator\nFlowers\nCane\nGrenade\nTeargas\nMolotov\nColt 45\nSilenced Pistol\nDeagle\nShotgun\nSawns\nSpas\nUzi\nMP5\nAK47\nM4\nTec9\nRifle\nSniper", "Select", "Back");
  371. return SendClientMessage(playerid, COLOR_RED, "ERROR: This weapon is disabled!");
  372. }
  373. }
  374. switch(listitem)
  375. {
  376. case 0: SetPVarInt(playerid, key, 1);
  377. case 1: SetPVarInt(playerid, key, 2);
  378. case 2: SetPVarInt(playerid, key, 3);
  379. case 3: SetPVarInt(playerid, key, 4);
  380. case 4: SetPVarInt(playerid, key, 5);
  381. case 5: SetPVarInt(playerid, key, 6);
  382. case 6: SetPVarInt(playerid, key, 7);
  383. case 7: SetPVarInt(playerid, key, 8);
  384. case 8: SetPVarInt(playerid, key, 9);
  385. case 9: SetPVarInt(playerid, key, 10);
  386. case 10: SetPVarInt(playerid, key, 11);
  387. case 11: SetPVarInt(playerid, key, 14);
  388. case 12: SetPVarInt(playerid, key, 15);
  389. case 13: SetPVarInt(playerid, key, 16);
  390. case 14: SetPVarInt(playerid, key, 17);
  391. case 15: SetPVarInt(playerid, key, 18);
  392. case 16: SetPVarInt(playerid, key, 22);
  393. case 17: SetPVarInt(playerid, key, 23);
  394. case 18: SetPVarInt(playerid, key, 24);
  395. case 19: SetPVarInt(playerid, key, 25);
  396. case 20: SetPVarInt(playerid, key, 26);
  397. case 21: SetPVarInt(playerid, key, 27);
  398. case 22: SetPVarInt(playerid, key, 28);
  399. case 23: SetPVarInt(playerid, key, 29);
  400. case 24: SetPVarInt(playerid, key, 30);
  401. case 25: SetPVarInt(playerid, key, 31);
  402. case 26: SetPVarInt(playerid, key, 32);
  403. case 27: SetPVarInt(playerid, key, 33);
  404. case 28: SetPVarInt(playerid, key, 34);
  405. }
  406. ShowDuelSettingsDialog(playerid);
  407. }
  408. else ShowDuelSettingsDialog(playerid);
  409. }
  410. if(dialogid == DUELDIAG+7)
  411. {
  412. if(response)
  413. {
  414. if(!IsPlayerInDuel(diagitem[listitem])) return 1;
  415. SetPlayerSpectatingDuel(playerid, diagitem[listitem]);
  416. }
  417. else return 1;
  418. }
  419. if(dialogid == DUELDIAG+8)
  420. {
  421. if(response)
  422. {
  423. if(listitem > MAX_INVITES) return 1;
  424. new dueler = dinvitem[playerid][listitem];
  425. if(!IsPlayerConnected(dueler)) return ShowPlayerDialog(playerid, DUELDIAG-1, DIALOG_STYLE_MSGBOX, "Duel Invites", "ERROR: This player is no longer connected!", "Ok", "");
  426. SetPVarInt(playerid, "DuelDID", listitem);
  427. AcceptDuel(playerid);
  428. return 1;
  429. }
  430. }
  431. return 0;
  432. }
  433.  
  434. CMD:dreset(playerid, params[])
  435. {
  436. if(!IsPlayerAdmin(playerid)) return 1;
  437. for(new x=0; x<MAX_PLAYERS; x++)
  438. {
  439. if(!IsPlayerConnected(x)) continue;
  440. if(InDuel[x] == 1)
  441. {
  442. InDuel[x] = 0;
  443. SpawnPlayer(x);
  444. }
  445. }
  446. SendClientMessageToAll(COLOR_DUEL, "The duel system has been reset!");
  447. return 1;
  448. }
  449.  
  450. CMD:dinvites(playerid, params[])
  451. {
  452. ShowDuelInvitesDialog(playerid);
  453. return 1;
  454. }
  455.  
  456. CMD:daccept(playerid, params[])
  457. {
  458. new listitem;
  459. if(sscanf(params, "d", listitem)) return SendClientMessage(playerid, COLOR_RED, "ERROR: This duel invite is not valid!");
  460. if(listitem > MAX_INVITES) return 1;
  461. new dueler = dinvitem[playerid][listitem];
  462. if(!IsPlayerConnected(dueler)) return ShowPlayerDialog(playerid, DUELDIAG-1, DIALOG_STYLE_MSGBOX, "Duel Invites", "ERROR: This player is no longer connected!", "Ok", "");
  463. SetPVarInt(playerid, "DuelDID", listitem);
  464. AcceptDuel(playerid);
  465. return 1;
  466. }
  467.  
  468. CMD:duelmenu(playerid, params[])
  469. {
  470. ShowDuelSettingsDialog(playerid);
  471. return 1;
  472. }
  473.  
  474. CMD:duels(playerid, params[])
  475. {
  476. format(diagstr, sizeof(diagstr), "");
  477. for(new x=0; x<MAX_PLAYERS; x++)
  478. {
  479. for(new i=0; i<sizeof(diagitem); i++) if(x == diagitem[i]) continue; //Prevent duplicate duels
  480. if(InDuel[x] == 1)
  481. {
  482. new dueler = GetDuelerID(x);
  483. format(diagstr, sizeof(diagstr), "%s%s vs %s\n", diagstr, pName(x), pName(dueler));
  484. diagitem[TotalDuels] = x;
  485. }
  486. }
  487. if(TotalDuels < 1) format(diagstr, sizeof(diagstr), "There are currently no duels.");
  488. ShowPlayerDialog(playerid, DUELDIAG+7, DIALOG_STYLE_LIST, "Current Duels", diagstr, "Select", "Cancel");
  489. return 1;
  490. }
  491.  
  492. CMD:dspecoff(playerid, params[])
  493. {
  494. if(GetPVarInt(playerid, "DuelSpec") == 0) return SendClientMessage(playerid, COLOR_RED, "ERROR: You are not spectating any duels!");
  495. EndDuelSpectate(playerid);
  496. return 1;
  497. }
  498.  
  499. CMD:duel(playerid, params[])
  500. {
  501. if(strfind(params, "create", true) != -1)
  502. {
  503. new third[60];
  504. sscanf(params[7], "s[60]", third);
  505. if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, COLOR_RED, "You are not an admin!");
  506. if(GetPVarInt(playerid, "DuelEdit") == 1) return SendClientMessage(playerid, COLOR_RED, "You are already editing a duel!");
  507.  
  508. new dName[90];
  509. if(unformat(third, "s[90]", dName)) return SendClientMessage(playerid, COLOR_RED, "USAGE: /duel <create> <duelname>");
  510. else if(!strlen(dName)) return SendClientMessage(playerid, COLOR_RED, "USAGE: /duel <create> <duelname>");
  511. else if(DuelNameExists(dName)) return SendClientMessage(playerid, COLOR_RED, "This duel name already exists");
  512.  
  513. new getid = GetLowestDuelSlotID();
  514. format(dFile, sizeof(dFile), DUELFILES, getid);
  515.  
  516. new Float:X, Float:Y, Float:Z, Float:A;
  517. GetPlayerPos(playerid, X, Y, Z);
  518. GetPlayerFacingAngle(playerid, A);
  519. new dInterior = GetPlayerInterior(playerid);
  520.  
  521. dini_Create(dFile);
  522. dini_IntSet(dFile, "duelID", getid);
  523. dini_Set(dFile, "duelName", dName);
  524. dini_FloatSet(dFile, "duelX", X);
  525. dini_FloatSet(dFile, "duelY", Y);
  526. dini_FloatSet(dFile, "duelZ", Z);
  527. dini_FloatSet(dFile, "duelA", A);
  528. dini_IntSet(dFile, "duelInt", dInterior);
  529. SetPVarInt(playerid, "DuelEdit", 1);
  530. SetPVarInt(playerid, "DuelID", getid);
  531.  
  532. new str[200];
  533. format(str, sizeof(str), "Duel \"%s\" (ID: %d) created at: %f, %f, %f (Interior: %d)", dName, getid, X, Y, Z, dInterior);
  534. SendClientMessage(playerid, COLOR_DUEL, str);
  535. SendClientMessage(playerid, COLOR_DUEL, "Now go the second duelist position and type \"/duel <save>\" to set the position.");
  536. return 1;
  537. }
  538. if(strfind(params, "save", true) != -1)
  539. {
  540. if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, COLOR_RED, "You are not an admin!");
  541. if(GetPVarInt(playerid, "DuelEdit") == 0) return SendClientMessage(playerid, COLOR_RED, "You are not editing a duel.");
  542.  
  543. new duelID = GetPVarInt(playerid, "DuelID");
  544. format(dFile, sizeof(dFile), DUELFILES, duelID);
  545.  
  546. new Float:X, Float:Y, Float:Z, Float:A;
  547. GetPlayerPos(playerid, X, Y, Z);
  548. GetPlayerFacingAngle(playerid, A);
  549.  
  550. dini_FloatSet(dFile, "duel2X", X);
  551. dini_FloatSet(dFile, "duel2Y", Y);
  552. dini_FloatSet(dFile, "duel2Z", Z);
  553. dini_FloatSet(dFile, "duel2A", A);
  554.  
  555. new str[180];
  556. format(str, sizeof(str), "Duel \"%s\" (ID: %d) second position set at: %f, %f, %f", ReturnDuelNameFromID(duelID), duelID, X, Y, Z);
  557. SendClientMessage(playerid, COLOR_DUEL, str);
  558.  
  559. SetPVarInt(playerid, "DuelEdit", 0);
  560. SetPVarInt(playerid, "DuelID", -1);
  561. return 1;
  562. }
  563. if(strfind(params, "invite", true) != -1)
  564. {
  565. new third[60];
  566. sscanf(params[7], "s[60]", third);
  567. new target, gBet, gDuelSpot[85], gWeap[85], gWeap2[85], gWeap3[85];
  568. sscanf(third, "uis[85]s[85]s[85]s[85]", target, gBet, gDuelSpot, gWeap, gWeap2, gWeap3);
  569. if(target == INVALID_PLAYER_ID) return SendClientMessage(playerid, COLOR_RED, "Duel | Player not found");
  570. if(target == playerid) return SendClientMessage(playerid, COLOR_RED, "Duel | You can't invite yourself noob!");
  571. if(InDuel[playerid] == 1) return SendClientMessage(playerid, COLOR_DUEL, "Duel | You are already in a duel!");
  572. if(MINMONEY != 0 && gBet < 500) return SendClientMessage(playerid, COLOR_RED, "Duel | Minimum bet amount is 500");
  573. if(MINMONEY != 0 && Money_GetPlayerMoney(playerid) < gBet) return SendClientMessage(playerid, COLOR_RED, "Duel | You don't have that amount of money to bet");
  574. if(MINMONEY != 0 && Money_GetPlayerMoney(target) < gBet) return SendClientMessage(playerid, COLOR_RED, "Duel | This player does not have that amount of money!");
  575. if(ReturnDuelIDOrName(gDuelSpot) == -1) return SendClientMessage(playerid, COLOR_RED, "The duel id/name you entered does not exist!");
  576. if(ReturnWeaponIDOrName(gWeap) == -1) return SendClientMessage(playerid, COLOR_RED, "Slot 1: Invalid Weapon ID or Name");
  577. if(GetPlayerState(target) == 9) return SendClientMessage(playerid, COLOR_RED, "Duel | This player is in spectate mode!");
  578. if(!strlen(gWeap2)) format(gWeap2, sizeof(gWeap2), "48");
  579. if(!strlen(gWeap3)) format(gWeap3, sizeof(gWeap3), "48");
  580.  
  581. new duelloc = ReturnDuelIDOrName(gDuelSpot);
  582. new duelid = GetLowestUnusedDuelID();
  583.  
  584. dInfo[duelid][Inviter] = playerid;
  585. dInfo[duelid][Invitee] = target;
  586. dInfo[duelid][BetMoney] = gBet;
  587. dInfo[duelid][Location] = duelloc;
  588.  
  589. new Slot[3];
  590. Slot[0] = ReturnWeaponIDOrName(gWeap);
  591. Slot[1] = ReturnWeaponIDOrName(gWeap2);
  592. Slot[2] = ReturnWeaponIDOrName(gWeap3);
  593.  
  594. dWeps[duelid][0] = Slot[0];
  595. dWeps[duelid][1] = Slot[1];
  596. dWeps[duelid][2] = Slot[2];
  597.  
  598. new invid = GetLowestUnusedDuelSlot(target);
  599. dinvitem[target][invid] = playerid;
  600.  
  601. SetTimerEx("DuelReset", INVITERESET, 0, "ii", playerid, target);
  602.  
  603. new str[200];
  604. format(str, sizeof(str), "Duel invite from %s | (Bet: $%d) (Weapons: %s %s %s) (%s [ID %d])", pName(playerid), gBet, weaponNames(Slot[0]), weaponNames(Slot[1]), weaponNames(Slot[2]), ReturnDuelNameFromID(duelloc), duelloc);
  605. SendClientMessage(target, COLOR_DUEL, str);
  606. SendClientMessage(target, COLOR_DUEL, "You can accept the invite from the duel invites menu. (Tip: Use /dinvites or /daccept <duelid>)");
  607. format(str, sizeof(str), "Duel | Waiting for %s's response to your duel invite", pName(target));
  608. SendClientMessage(playerid, COLOR_DUEL, str);
  609. return 1;
  610. }
  611. if(strfind(params, "edit", true) != -1)
  612. {
  613. new third[60];
  614. sscanf(params[5], "s[60]", third);
  615. if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, COLOR_RED, "You are not an admin!");
  616. if(GetPVarInt(playerid, "DuelEdit") == 1) return SendClientMessage(playerid, COLOR_RED, "You are already editing a duel!");
  617.  
  618. new dName[90];
  619. if(unformat(third, "s[90]", dName)) return SendClientMessage(playerid, COLOR_RED, "USAGE: /duel <edit> <duelid/name>");
  620. else if(!strlen(dName)) return SendClientMessage(playerid, COLOR_RED, "USAGE: /duel <edit> <duelid/name>");
  621. else if(ReturnDuelIDOrName(dName) == -1) return SendClientMessage(playerid, COLOR_RED, "The duelid/name specified does not exist!");
  622.  
  623. new getid = ReturnDuelIDOrName(dName);
  624. format(dFile, sizeof(dFile), DUELFILES, getid);
  625.  
  626. new Float:X, Float:Y, Float:Z, Float:A;
  627. GetPlayerPos(playerid, X, Y, Z);
  628. GetPlayerFacingAngle(playerid, A);
  629. new dInterior = GetPlayerInterior(playerid);
  630.  
  631. dini_FloatSet(dFile, "duelX", X);
  632. dini_FloatSet(dFile, "duelY", Y);
  633. dini_FloatSet(dFile, "duelZ", Z);
  634. dini_FloatSet(dFile, "duelA", A);
  635. dini_FloatSet(dFile, "duelInt", -dInterior);
  636. SetPVarInt(playerid, "DuelEdit", 1);
  637. SetPVarInt(playerid, "DuelID", getid);
  638.  
  639. new str[200];
  640. format(str, sizeof(str), "Duel \"%s\" (ID %d) edited at: %f, %f, %f (Interior %d)", dName, getid, X, Y, Z, dInterior);
  641. SendClientMessage(playerid, COLOR_DUEL, str);
  642. SendClientMessage(playerid, COLOR_DUEL, "Now go the second duelist position and type \"/duel save\" to set the position.");
  643. return 1;
  644. }
  645. if(strfind(params, "setname", true) != -1)
  646. {
  647. new third[60];
  648. sscanf(params[8], "s[60]", third);
  649. if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, COLOR_RED, "You are not an admin!");
  650.  
  651. new dName[90], dNewName[35];
  652. if(unformat(third, "s[90]s[35]", dName, dNewName)) return SendClientMessage(playerid, COLOR_RED, "USAGE: /duel <setname> <duelid/name> <newduelname>");
  653. else if(!strlen(dName)) return SendClientMessage(playerid, COLOR_RED, "USAGE: /duel <setname> <duelid/name> <newduelname>");
  654. else if(ReturnDuelIDOrName(dName) == -1) return SendClientMessage(playerid, COLOR_RED, "The duelid/name specified does not exist!");
  655. else if(strlen(dNewName) > 35) return SendClientMessage(playerid, COLOR_RED, "Max duel name length is 50 characters");
  656.  
  657. new getid = ReturnDuelIDOrName(dName);
  658. format(dFile, sizeof(dFile), DUELFILES, getid);
  659. dini_Set(dFile, "duelName", dNewName);
  660.  
  661. new str[200];
  662. format(str, sizeof(str), "Duel \"%s\" (ID: %d) is now named \"%s\"", dName, getid, dNewName);
  663. SendClientMessage(playerid, COLOR_DUEL, str);
  664. return 1;
  665. }
  666. if(strfind(params, "remove", true) != -1)
  667. {
  668. new third[60];
  669. sscanf(params[7], "s[60]", third);
  670. if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, COLOR_RED, "ERROR: You are not an admin!");
  671.  
  672. new dName[90];
  673. if(unformat(third, "s[90]", dName)) return SendClientMessage(playerid, COLOR_RED, "USAGE: /duel <remove> <duelid/name>");
  674. else if(!strlen(dName)) return SendClientMessage(playerid, COLOR_RED, "USAGE: /duel <remove> <duelid/name>");
  675. else if(!DuelNameExists(dName)) return SendClientMessage(playerid, COLOR_RED, "The duel id/name specified does not exist");
  676. else if(ReturnDuelIDOrName(dName) == -1) return SendClientMessage(playerid, COLOR_RED, "The duel id/name specified does not exist");
  677.  
  678. new duelID = ReturnDuelIDOrName(dName);
  679. format(dFile, sizeof(dFile), DUELFILES, duelID);
  680. dini_Remove(dFile);
  681.  
  682. new str[100];
  683. format(str, sizeof(str), "Duel \"%s\" (ID: %d) has been removed!", dName, duelID);
  684. SendClientMessage(playerid, COLOR_DUEL, str);
  685. return 1;
  686. }
  687. if(strfind(params, "help", true) != -1)
  688. {
  689. ShowPlayerDialog(playerid, 21, DIALOG_STYLE_MSGBOX, "{"#Y>"}Duel Help", "{"#G>"}Invite someone to a duel:\n{"#W>"}/duel <invite> <playerid/name> <betamount> <duelspot> <wep1> <wep2> <wep3>\n\nExample: \"/duel invite Noob 500 SFBridge spas deagle\"\n{"#BV>"}You may enter partial weapon names.\nMinimum 1 weapon, max weps is 3.\n\n{"#B>"}Command '/duels' shows current duels to spectate or /duel <spec> <playerid/name>!\t\t\n\n{"#R>"}Duel system by [ABK]PotH3Ad. | ABKclan.com", "Ok", "");
  690. return 1;
  691. }
  692. if(strfind(params, "cmds", true) != -1)
  693. {
  694. if(!IsPlayerAdmin(playerid)) ShowPlayerDialog(playerid, 20, DIALOG_STYLE_MSGBOX, "{"#Y>"}Duel Commands", "{"#B>"}User Commands\t\t\t{"#W>"}Description\n\n{"#B>"}/duels\t\t\t\t\t{"#W>"}Show the duel invite dialog!\n{"#B>"}/duel <cmds>\t\t\t\t{"#W>"}Show a list of duel commands.\n{"#B>"}/duel <help>\t\t\t\t{"#W>"}Help for dueling another player.\n{"#B>"}/duel <invite> <playerid/name>\t{"#W>"}Invite a player to a duel!", "Ok", "");
  695. else
  696. {
  697. ShowPlayerDialog(playerid, 20, DIALOG_STYLE_MSGBOX, "{"#Y>"}Duel Commands", "{"#B>"}User Commands\t\t\t{"#W>"}Description\n\n{"#B>"}/duels\t\t\t\t\t{"#W>"}Show the duel invite dialog!\n{"#B>"}/duel <cmds>\t\t\t\t{"#W>"}Show a list of duel commands.\n{"#B>"}/duel <help>\t\t\t\t{"#W>"}Help for dueling another player.\n{"#B>"}/duel <invite> <playerid/name>\t{"#W>"}Invite a player to a duel!", "Ok", "");
  698. SendClientMessage(playerid, COLOR_DUEL, "DBuild: {"#G>"}/duel <create> <name> {"#W>"}Create map. Set 1st dueler position! | {"#G>"}/duel <save> {"#W>"}Save map, set 2nd dueler pos!");
  699. SendClientMessage(playerid, COLOR_DUEL, "{"#G>"}/duel <edit> <mapid/name> {"#W>"}Edit a map. Set 1st dueler position!");
  700. SendClientMessage(playerid, COLOR_DUEL, "{"#G>"}duel <remove> <mapid/name> {"#W>"}Delete a map. | {"#G>"}/duel <setname> <mapid/name> <newname> {"#W>"}Change a map name");
  701. }
  702. return 1;
  703. }
  704. if(strfind(params, "spec", true) != -1)
  705. {
  706. new third[60];
  707. sscanf(params[5], "s[60]", third);
  708.  
  709. new target;
  710. sscanf(third, "u", target);
  711. if(target == INVALID_PLAYER_ID) return SendClientMessage(playerid, COLOR_RED, "Duel | Player not found");
  712. if(InDuel[target] == 0) return SendClientMessage(playerid, COLOR_DUEL, "Duel | This player is not currently in a duel!");
  713.  
  714. new str[90];
  715. format(str, sizeof(str), "Duel | You are now spectating %s duel.", pName(target));
  716. SendClientMessage(target, COLOR_DUEL, "Duel | Type /dspecoff to exit at anytime!");
  717. SetPlayerSpectatingDuel(playerid, target);
  718. return 1;
  719. }
  720. else ShowDuelSettingsDialog(playerid);
  721. return 1;
  722. }
  723.  
  724. public OnPlayerUpdate(playerid)
  725. {
  726. if(InDuel[playerid] == 1) SetPlayerTeam(playerid, NO_TEAM);
  727. return 1;
  728. }
  729.  
  730. //=========[Duel Callbacks]========
  731. public DuelReset(player1, player2)
  732. {
  733. if(InDuel[player1] == 1) return 1;
  734. new str[50];
  735. format(str, sizeof(str), "%s didn't respond to your duel invite", pName(player2));
  736. SendClientMessage(player1, COLOR_DUEL, str);
  737. SetPlayerArmour(player1, 0);
  738. SetPlayerArmour(player2, 0);
  739. RemoveFromDuel(player1);
  740. RemoveFromDuel(player2);
  741. return 1;
  742. }
  743.  
  744. public DuelCDUpdate(playerid)
  745. {
  746. SetPVarInt(playerid, "CDTick", GetPVarInt(playerid, "CDTick")+1);
  747. if(GetPVarInt(playerid, "CDTick") > 3)
  748. {
  749. TogglePlayerControllable(playerid, 1);
  750. GameTextForPlayer(playerid, "~R~Fight!", 1000, 6);
  751. SetPVarInt(playerid, "CDTick", 0);
  752. PlayerPlaySound(playerid, 1057, 0.0, 0.0, 0.0);
  753. KillTimer(DuelTimer[playerid]);
  754. }
  755. else
  756. {
  757. GameTextForPlayer(playerid, "~P~Starting...", 500, 6);
  758. PlayerPlaySound(playerid, 1056, 0.0, 0.0, 0.0);
  759. }
  760. return 1;
  761. }
  762. //=========[Duel Callbacks - END]==========
  763.  
  764. //=========[Duel Functions]===============
  765. stock AddToDuel(playerid, Float:X, Float:Y, Float:Z, Float:A, interior, world, wep1, wep2, wep3)
  766. {
  767. SetPVarInt(playerid, "CDTick", 0);
  768. InDuel[playerid] = 1;
  769. SetPVarInt(playerid, "ArmourReport", 1);
  770. SetPlayerPosEx(playerid, X, Y, Z, A, interior, world);
  771. SetPlayerArmour(playerid, 100);
  772. SetPlayerHealth(playerid, 100);
  773. ResetPlayerWeapons(playerid);
  774.  
  775. GivePlayerWeapon(playerid, wep1, 1337);
  776. GivePlayerWeapon(playerid, wep2, 1337);
  777. GivePlayerWeapon(playerid, wep3, 1337);
  778.  
  779. TogglePlayerControllable(playerid, 0);
  780. SetCameraBehindPlayer(playerid);
  781. DuelTimer[playerid] = SetTimerEx("DuelCDUpdate", 1000, 1, "i", playerid);
  782. SetPlayerColor(playerid, COLOR_DUEL);
  783. return 1;
  784. }
  785.  
  786. stock AcceptDuel(playerid)
  787. {
  788. if(InDuel[playerid] == 1) return SendClientMessage(playerid, COLOR_RED, "You are already in a duel");
  789.  
  790. new duelid = GetPVarInt(playerid, "DuelDID");
  791. new gPlayer = dInfo[duelid][Inviter];
  792. new gBet = dInfo[duelid][BetMoney];
  793.  
  794. if(MINMONEY != 0 && Money_GetPlayerMoney(playerid) < gBet)
  795. {
  796. SendClientMessage(playerid, COLOR_RED, "Duel | You don't have that amount of money!");
  797. SendClientMessage(gPlayer, COLOR_RED, "Duel | The player you invited no longer has that amount of money to bet!");
  798.  
  799. SetPlayerArmour(playerid, 0);
  800. SetPlayerArmour(gPlayer, 0);
  801. RemoveFromDuel(playerid);
  802. RemoveFromDuel(gPlayer);
  803. return 1;
  804. }
  805.  
  806. new gDuelSpot = dInfo[duelid][Location];
  807. format(dFile, sizeof(dFile), DUELFILES, gDuelSpot);
  808.  
  809. new Interior = dini_Int(dFile, "duelInt");
  810. new Float:X, Float:Y, Float:Z, Float:A;
  811. X = dini_Float(dFile, "duelX");
  812. Y = dini_Float(dFile, "duelY");
  813. Z = dini_Float(dFile, "duelZ");
  814. A = dini_Float(dFile, "duelA");
  815. new Float:X2, Float:Y2, Float:Z2, Float:A2;
  816. X2 = dini_Float(dFile, "duel2X");
  817. Y2 = dini_Float(dFile, "duel2Y");
  818. Z2 = dini_Float(dFile, "duel2Z");
  819. A2 = dini_Float(dFile, "duelA2");
  820.  
  821. new Slot[3];
  822. Slot[0] = dWeps[duelid][0];
  823. Slot[1] = dWeps[duelid][1];
  824. Slot[2] = dWeps[duelid][2];
  825. TotalDuels++;
  826.  
  827. SetPVarInt(playerid, "DuelDID", duelid);
  828. SetPVarInt(gPlayer, "DuelDID", duelid);
  829. RemoveDuelInvite(playerid, gPlayer);
  830. KillTimer(DuelTimer[playerid]);
  831. KillTimer(DuelTimer[gPlayer]);
  832.  
  833. new world = playerid;
  834. if(gPlayer > playerid) world = gPlayer+1;
  835. else if(playerid > gPlayer) world = playerid+1;
  836. AddToDuel(gPlayer, X2, Y2, Z2, A2, Interior, world, Slot[0], Slot[1], Slot[2]);
  837. AddToDuel(playerid, X, Y, Z, A, Interior, world, Slot[0], Slot[1], Slot[2]);
  838.  
  839. new str[150];
  840. format(str, sizeof(str), "Duel | %s vs %s {0004B6}(Weapons: %s %s %s) {009900}(Bet: $%d) {F8FF3D}(Place: %s [ID %d])", pName(gPlayer), pName(playerid), weaponNames(Slot[0]), weaponNames(Slot[1]), weaponNames(Slot[2]), gBet, ReturnDuelNameFromID(gDuelSpot), gDuelSpot);
  841. SendClientMessageToAll(COLOR_DUEL, str);
  842. return 1;
  843. }
  844.  
  845. stock RemoveFromDuel(playerid)
  846. {
  847. KillTimer(DuelTimer[playerid]);
  848. SetPlayerArmour(playerid, 0);
  849. SetPlayerVirtualWorld(playerid, 0);
  850. SetPVarInt(playerid, "ArmorReport", 0);
  851. InDuel[playerid] = 0;
  852. SetPVarInt(playerid, "DuelDID", -1);
  853. return 1;
  854. }
  855.  
  856. stock ShowDuelSettingsDialog(playerid)
  857. {
  858. new str[255], wepstr[3][40], key[7];
  859. new dPID = GetPVarInt(playerid, "dPID");
  860. new dLoc = GetPVarInt(playerid, "dLoc");
  861. for(new x=0; x<=2; x++)
  862. {
  863. format(key, sizeof(key), "dWep%d", x);
  864. new wep = GetPVarInt(playerid, key);
  865. format(wepstr[x], 40, "%s", weaponNames(wep));
  866. }
  867. format(str, sizeof(str), "{009900}Player:\t\t{0004B6}%s [%d]\n{009900}Location:\t{0004B6}%s [%d]\n{009900}Weapons:\t{0004B6}%s/%s/%s\n{009900}Bet Money:{009900}\t{0004B6}$%d\n{009900}Send Invite\n{009900}Cancel Invite", pName(dPID), dPID, ReturnDuelNameFromID(dLoc), dLoc, wepstr[0], wepstr[1], wepstr[2], GetPVarInt(playerid, "dBet"));
  868. ShowPlayerDialog(playerid, DUELDIAG, DIALOG_STYLE_LIST, "Duel Settings", str, "Select", "Cancel");
  869. return 1;
  870. }
  871.  
  872. stock ShowDuelInvitesDialog(playerid)
  873. {
  874. new total;
  875. format(diagstr, sizeof(diagstr), "");
  876. for(new x=0; x<MAX_INVITES; x++)
  877. {
  878. new inviter = dinvitem[playerid][x];
  879. if(inviter == playerid || inviter == -1) continue;
  880. format(diagstr, sizeof(diagstr), "%s%s\n", diagstr, pName(inviter));
  881. total++;
  882. }
  883. if(total == 0) format(diagstr, sizeof(diagstr), "{CC0000}You have not been recently invited!");
  884. ShowPlayerDialog(playerid, DUELDIAG+8, DIALOG_STYLE_LIST, "Duel Invites", diagstr, "Accept", "Cancel");
  885. return 1;
  886. }
  887.  
  888. stock RemoveDuelInvite(playerid, inviter)
  889. {
  890. for(new x=0; x<MAX_INVITES; x++)
  891. {
  892. if(dinvitem[playerid][x] == inviter) dinvitem[playerid][x] = -1;
  893. }
  894. }
  895.  
  896. stock ResetDuelInvites(playerid)
  897. {
  898. for(new x=0; x<MAX_INVITES; x++) dinvitem[playerid][x] = -1;
  899. }
  900.  
  901. stock ResetDuelInformation(duelid)
  902. {
  903. dInfo[duelid][Inviter] = -1;
  904. dInfo[duelid][Invitee] = -1;
  905. dInfo[duelid][BetMoney] = 0;
  906. dInfo[duelid][Location] = -1;
  907. dInfo[duelid][Location] = 0;
  908. for(new x=0; x<MAX_DUEL_WEPS; x++) dWeps[duelid][x] = 0;
  909. }
  910.  
  911. stock GetDuelerID(playerid)
  912. {
  913. new duelerid = -1;
  914. new duelid = GetPVarInt(playerid, "DuelDID");
  915. if(dInfo[duelid][Inviter] == playerid) duelerid = dInfo[duelid][Invitee];
  916. else duelerid = dInfo[duelid][Inviter];
  917. return duelerid;
  918. }
  919. //=========[Duel Functions - END]===============
  920.  
  921. //=========[Duel Spectate Functions]==========
  922. stock LoadDuelSpecTextdraw(playerid)
  923. {
  924. SpecTD[playerid][0] = TextDrawCreate(180.000000, 364.000000, "_");
  925. TextDrawBackgroundColor(SpecTD[playerid][0], 255);
  926. TextDrawFont(SpecTD[playerid][0], 3);
  927. TextDrawLetterSize(SpecTD[playerid][0], 0.469999, 1.200000);
  928. TextDrawColor(SpecTD[playerid][0], 52479);
  929. TextDrawSetOutline(SpecTD[playerid][0], 0);
  930. TextDrawSetProportional(SpecTD[playerid][0], 1);
  931. TextDrawSetShadow(SpecTD[playerid][0], 1);
  932. SpecTD[playerid][1] = TextDrawCreate(180.000000, 387.000000, "_");
  933. TextDrawBackgroundColor(SpecTD[playerid][1], 255);
  934. TextDrawFont(SpecTD[playerid][1], 3);
  935. TextDrawLetterSize(SpecTD[playerid][1], 0.469999, 1.200000);
  936. TextDrawColor(SpecTD[playerid][1], -1);
  937. TextDrawSetOutline(SpecTD[playerid][1], 0);
  938. TextDrawSetProportional(SpecTD[playerid][1], 1);
  939. TextDrawSetShadow(SpecTD[playerid][1], 1);
  940. TextDrawHideForAll(SpecTD[playerid][0]);
  941. TextDrawHideForAll(SpecTD[playerid][1]);
  942. }
  943.  
  944. public UpdateSpectate(playerid)
  945. {
  946. new specid = GetPVarInt(playerid, "DuelSpecID");
  947. if(!IsPlayerInDuel(specid)) return EndDuelSpectate(playerid);
  948. else ShowDuelSpecTextdraw(playerid, specid);
  949. SetPlayerVirtualWorld(playerid, GetPlayerVirtualWorld(specid));
  950. SetPlayerInterior(playerid, GetPlayerInterior(specid));
  951. return 1;
  952. }
  953.  
  954. stock EndDuelSpectate(playerid)
  955. {
  956. KillTimer(UpdateSpecTimer[playerid]);
  957. SetPVarInt(playerid, "DuelSpecID", -1);
  958. SetPVarInt(playerid, "DuelSpec", 0);
  959. SendClientMessage(playerid, COLOR_DUEL, "Duel spectate ended, duel is no longer in progress.");
  960. TogglePlayerSpectating(playerid, 0);
  961. KillTimer(UpdateSpecTimer[playerid]);
  962. TextDrawHideForPlayer(playerid, SpecTD[playerid][0]);
  963. TextDrawHideForPlayer(playerid, SpecTD[playerid][1]);
  964. return 1;
  965. }
  966.  
  967. stock SetPlayerSpectatingDuel(playerid, duelerid)
  968. {
  969. TogglePlayerSpectating(playerid, 1);
  970. SendClientMessage(playerid, COLOR_DUEL, "You have entered duel spectate mode!");
  971. SendClientMessage(playerid, COLOR_DUEL, "Press the FIRE key to switch between duelists.");
  972. ShowDuelSpecTextdraw(playerid, duelerid);
  973. KillTimer(UpdateSpecTimer[playerid]);
  974. UpdateSpecTimer[playerid] = SetTimerEx("UpdateSpectate", 1000, 1, "d", playerid);
  975. SetPVarInt(playerid, "DuelSpecID", duelerid);
  976. SetPVarInt(playerid, "DuelSpec", 1);
  977. SetPlayerVirtualWorld(playerid, GetPlayerVirtualWorld(duelerid));
  978. SetPlayerInterior(playerid, GetPlayerInterior(duelerid));
  979. PlayerSpectatePlayer(playerid, duelerid, SPECTATE_MODE_NORMAL);
  980. }
  981.  
  982. stock ShowDuelSpecTextdraw(playerid, duelerid)
  983. {
  984. new sstr[100], sstr2[140];
  985.  
  986. new duelloc[40];
  987. new duelid, dueler;
  988. duelid = GetPVarInt(duelerid, "DuelDID");
  989. if(dInfo[duelid][Inviter] == duelerid) dueler = dInfo[duelid][Invitee];
  990. else dueler = dInfo[duelid][Inviter];
  991.  
  992. new gBet = dInfo[duelid][BetMoney];
  993. new gDuelSpot = dInfo[duelid][Location];
  994. format(duelloc, sizeof(duelloc), "%s", ReturnDuelNameFromID(gDuelSpot));
  995.  
  996. new Slot[3];
  997. Slot[0] = dWeps[duelid][0];
  998. Slot[1] = dWeps[duelid][1];
  999. Slot[2] = dWeps[duelid][2];
  1000.  
  1001. format(sstr, sizeof(sstr), "%s vs %s~n~~R~HP ~W~%d %d", pName(duelerid), pName(dueler), GetRoundedTotalHP(duelerid), GetRoundedTotalHP(dueler));
  1002. format(sstr2, sizeof(sstr2), "~Y~Location ~w~%s~n~~p~Weapons ~w~%s %s %s~n~~g~Bet Money ~w~$%d",
  1003. duelloc, weaponNames(Slot[0]), weaponNames(Slot[1]), weaponNames(Slot[2]), gBet);
  1004. TextDrawHideForPlayer(playerid, SpecTD[playerid][0]);
  1005. TextDrawHideForPlayer(playerid, SpecTD[playerid][1]);
  1006. TextDrawSetString(SpecTD[playerid][0], sstr);
  1007. TextDrawSetString(SpecTD[playerid][1], sstr2);
  1008. TextDrawShowForPlayer(playerid, SpecTD[playerid][0]);
  1009. TextDrawShowForPlayer(playerid, SpecTD[playerid][1]);
  1010. }
  1011. //=======================[Spectate - END]==========================
  1012.  
  1013. //======================[Internal Functions]=======================
  1014. stock IsPlayerInDuel(playerid)
  1015. {
  1016. if(InDuel[playerid] == 1) return 1;
  1017. return 0;
  1018. }
  1019.  
  1020. stock SetPlayerPosEx(playerid, Float:X, Float:Y, Float:Z, Float:angle, interior, world)
  1021. {
  1022. SetPlayerPos(playerid, X, Y, Z);
  1023. SetPlayerFacingAngle(playerid, angle);
  1024. SetPlayerInterior(playerid, interior);
  1025. SetPlayerVirtualWorld(playerid, world);
  1026. return 1;
  1027. }
  1028.  
  1029. stock IsValidWeapon(weaponid)
  1030. {
  1031. switch(weaponid)
  1032. {
  1033. case 0, 19, 20, 21, 35..46: return 0;
  1034. }
  1035. if(weaponid < 0 || weaponid > 48) return 0;
  1036. return 1;
  1037. }
  1038.  
  1039. stock ReturnWeaponIDOrName(idname[])
  1040. {
  1041. if(!IsNumeric(idname))
  1042. {
  1043. new gWeap = GetWeaponModelIDFromName(idname);
  1044. if(IsValidWeapon(gWeap)) return gWeap;
  1045. }
  1046. else if(IsNumeric(idname))
  1047. {
  1048. new gWeap = strval(idname);
  1049. if(IsValidWeapon(gWeap)) return gWeap;
  1050. }
  1051. return -1;
  1052. }
  1053.  
  1054. stock GetRoundedTotalHP(playerid)
  1055. {
  1056. new Float:HP, Float:Armour, HPT;
  1057. GetPlayerHealth(playerid, HP);
  1058. GetPlayerArmour(playerid, Armour);
  1059. HPT = floatround(HP) + floatround(Armour);
  1060. return HPT;
  1061. }
  1062.  
  1063. GetWeaponModelIDFromName(wname[])
  1064. {
  1065. for(new i=0; i<49; i++)
  1066. {
  1067. if(i == 19 || i == 20 || i == 21) continue;
  1068. if(strfind(weaponNames(i), wname, true) != -1) return i;
  1069. }
  1070. return -1;
  1071. }
  1072.  
  1073. stock DuelNameExists(duelname[])
  1074. {
  1075. for(new x=0; x<MAX_DUELS; x++)
  1076. {
  1077. format(dFile, sizeof(dFile), DUELFILES, x);
  1078. if(strfind(duelname, dini_Get(dFile, "duelName"), true) != -1) return 1;
  1079. break;
  1080. }
  1081. return 0;
  1082. }
  1083.  
  1084. stock ReturnDuelIDOrName(duelname[])
  1085. {
  1086. if(!IsNumeric(duelname))
  1087. {
  1088. for(new x=0; x<MAX_DUELS; x++)
  1089. {
  1090. new dName[128];
  1091. new idfromname = x;
  1092. format(dFile, sizeof(dFile), DUELFILES, x);
  1093. format(dName, sizeof(dName), "%s", dini_Get(dFile, "duelName"));
  1094. if(strfind(dName, duelname, true) != -1) return idfromname;
  1095. break;
  1096. }
  1097. }
  1098. else if(IsNumeric(duelname))
  1099. {
  1100. new dName = strval(duelname);
  1101. format(dFile, sizeof(dFile), DUELFILES, dName);
  1102. if(fexist(dFile)) return dName;
  1103. }
  1104. return -1;
  1105. }
  1106.  
  1107. stock weaponNames(weaponid)
  1108. {
  1109. new str[25];
  1110. switch(weaponid)
  1111. {
  1112. case 0: str = "Fist";
  1113. case 1: str = "Brass Knuckles";
  1114. case 2: str = "Golf Club";
  1115. case 3: str = "Night Stick";
  1116. case 4: str = "Knife";
  1117. case 5: str = "Baseball Bat";
  1118. case 6: str = "Shovel";
  1119. case 7: str = "Pool Cue";
  1120. case 8: str = "Katana";
  1121. case 9: str = "Chainsaw";
  1122. case 10: str = "Purple Dildo";
  1123. case 11: str = "Vibrator";
  1124. case 12: str = "Vibrator";
  1125. case 13: str = "Vibrator";
  1126. case 14: str = "Flowers";
  1127. case 15: str = "Cane";
  1128. case 16: str = "Grenade";
  1129. case 17: str = "Teargas";
  1130. case 18: str = "Molotov";
  1131. case 19: str = " ";
  1132. case 20: str = " ";
  1133. case 21: str = " ";
  1134. case 22: str = "Colt 45";
  1135. case 23: str = "Silenced Pistol";
  1136. case 24: str = "Deagle";
  1137. case 25: str = "Shotgun";
  1138. case 26: str = "Sawns";
  1139. case 27: str = "Spas";
  1140. case 28: str = "Uzi";
  1141. case 29: str = "MP5";
  1142. case 30: str = "AK47";
  1143. case 31: str = "M4";
  1144. case 32: str = "Tec9";
  1145. case 33: str = "County Rifle";
  1146. case 34: str = "Sniper Rifle";
  1147. case 35: str = "Rocket Launcher";
  1148. case 36: str = "Heat-Seeker";
  1149. case 37: str = "Flamethrower";
  1150. case 38: str = "Minigun";
  1151. case 39: str = "Satchel Charge";
  1152. case 40: str = "Detonator";
  1153. case 41: str = "Spray Can";
  1154. case 42: str = "Fire Extinguisher";
  1155. case 43: str = "Camera";
  1156. case 44: str = "Night Vision Goggles";
  1157. case 45: str = "Infrared Goggles";
  1158. case 46: str = "Parachute";
  1159. case 47: str = "Fake Pistol";
  1160. case 48: str = "None"; //For duel msgs
  1161. }
  1162. return str;
  1163. }
  1164.  
  1165. stock ReturnDuelNameFromID(duelid)
  1166. {
  1167. new dName[80];
  1168. format(dFile, sizeof(dFile), DUELFILES, duelid);
  1169. format(dName, sizeof(dName), "%s", dini_Get(dFile, "duelName"));
  1170. return dName;
  1171. }
  1172.  
  1173. stock pName(playerid)
  1174. {
  1175. new paname[MAX_PLAYER_NAME];
  1176. GetPlayerName(playerid, paname, sizeof(paname));
  1177. return paname;
  1178. }
  1179.  
  1180. stock IsNumeric(string[])
  1181. {
  1182. for(new i=0, j=strlen(string); i<j; i++)
  1183. {
  1184. if(string[i] > '9' || string[i] < '0') return 0;
  1185. }
  1186. return 1;
  1187. }
  1188.  
  1189. stock GetLowestUnusedDuelSlot(playerid)
  1190. {
  1191. new duelid;
  1192. for(new x=0; x<MAX_INVITES; x++)
  1193. {
  1194. if(!IsPlayerConnected(dinvitem[playerid][x]))
  1195. {
  1196. duelid = x;
  1197. break;
  1198. }
  1199. }
  1200. return duelid;
  1201. }
  1202.  
  1203. stock GetLowestUnusedDuelID()
  1204. {
  1205. new duelid;
  1206. for(new x=0; x<MAX_DUELS; x++)
  1207. {
  1208. if(!IsPlayerConnected(dInfo[x][Inviter]) || !IsPlayerConnected(dInfo[x][Invitee]))
  1209. {
  1210. duelid = x;
  1211. break;
  1212. }
  1213. }
  1214. return duelid;
  1215. }
  1216.  
  1217. stock GetLowestDuelSlotID()
  1218. {
  1219. for(new x=0; x<MAX_DUELS; x++)
  1220. {
  1221. format(dFile, sizeof(dFile), DUELFILES, x);
  1222. if(!dini_Exists(dFile)) return x;
  1223. }
  1224. return 1;
  1225. }
  1226. //======================[Internal Functions - END]=======================
Advertisement
Add Comment
Please, Sign In to add comment