Advertisement
LVPYassine

Untitled

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