Guest User

cDuel v1.4.6

a guest
May 8th, 2011
1,502
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 38.62 KB | None | 0 0
  1. /* Duel Script Update v1.3
  2.     -Patched glitch which allows players to join duel while spectating.
  3.     -Fixed bug with duel info broken weapon format
  4.    
  5.   Duel Script Update v1.4.5
  6.     .Add duel statistics dialog
  7.     -Added duel spectate system
  8.     -Player's color changes while in duel
  9.     -Added sounds for the countdown
  10.     -Fixed spec textdraw showing on exiting
  11.     -Fixed spectate mode not showing right away
  12. */
  13.  
  14.  
  15. #include <a_samp>
  16. #include <zcmd>
  17. #include <dini>
  18. #include <sscanf2>
  19.  
  20. //=====[Internal Settings]=====
  21. #define DUELDIAG                6550
  22. #define MAX_DUELS               40
  23. #define DUELFILES               "/Duels/%d.ini"
  24. #define DUEL_IDFILE             "/Duels/idset.ini"
  25. #define SPEC_UPDATE             1000
  26. #define Money_GivePlayerMoney   GivePlayerMoney     //Replace with your own money functions
  27. #define Money_GetPlayerMoney    GetPlayerMoney
  28. #define MINMONEY                500                 //Minimum duel bet money - Useful for A/D servers, set to 0 for A/D
  29. //=============================
  30.  
  31. #define COLOR_RED       0xFF0000
  32. #define COLOR_DUEL      0x00C224
  33.  
  34. new DuelTimer[MAX_PLAYERS];
  35. new UpdateSpecTimer[MAX_PLAYERS];
  36.  
  37. forward DuelReset(player1, player2);
  38. forward DuelCDUpdate(playerid);
  39. forward UpdateSpectate(playerid);
  40.  
  41. new dFile[70];
  42. new diagstr[900];
  43. new Text:SpecTD[MAX_PLAYERS][2];
  44.  
  45. //Spec Diag
  46. new diagitem[25]; //store player id
  47.  
  48. public OnFilterScriptInit()
  49. {
  50.     SendClientMessageToAll(COLOR_DUEL, "Duel System v1.4 by PotH3Ad initialized!");
  51.     print("  Duel System v1.4 by PotH3Ad initialized!");
  52.     return 1;
  53. }
  54.  
  55. public OnFilterScriptExit()
  56. {
  57.     SendClientMessageToAll(COLOR_DUEL, "Duel System v1.4 by PotH3Ad has been unloaded!");
  58.     print("  Duel System v1.4 by PotH3Ad has been unloaded!");
  59.     return 1;
  60. }
  61.  
  62. public OnPlayerConnect(playerid)
  63. {
  64.     SetPVarInt(playerid, "dWep0", 0);
  65.     SetPVarInt(playerid, "dWep1", 0);
  66.     SetPVarInt(playerid, "dWep2", 0);
  67.     SetPVarInt(playerid, "dPID", -1);
  68.     SetPVarInt(playerid, "dLoc", -1);
  69.     SetPVarInt(playerid, "dBet", 0);
  70.     LoadDuelSpecTextdraw(playerid);
  71.     return 1;
  72. }
  73.  
  74. public OnPlayerDisconnect(playerid, reason)
  75. {
  76.     new duelerid = GetPVarInt(playerid, "InviterID");
  77.     if(GetPVarInt(duelerid, "InDuel") == 1 && GetPVarInt(playerid, "InDuel") == 1)
  78.     {
  79.         new sReason[56];
  80.         switch(reason)
  81.         {
  82.             case 0: format(sReason, sizeof(sReason), "Timeout");
  83.             case 1: format(sReason, sizeof(sReason), "Leaving");
  84.             case 2: format(sReason, sizeof(sReason), "Kicked");
  85.         }
  86.         new gBet = GetPVarInt(playerid, "DuelBet");
  87.         new gDuelSpot = GetPVarInt(playerid, "DuelSpot");
  88.  
  89.         new Slot[3];
  90.         Slot[0] = GetPVarInt(playerid, "dWeap1");
  91.         Slot[1] = GetPVarInt(playerid, "dWeap2");
  92.         Slot[2] = GetPVarInt(playerid, "dWeap3");
  93.  
  94.         Money_GivePlayerMoney(duelerid, gBet);
  95.  
  96.         new str[150];
  97.         format(str, sizeof(str), "Duel | %s has left the server during a duel with %s (Reason: %s)", pName(playerid), pName(duelerid), sReason);
  98.         SendClientMessageToAll(COLOR_DUEL, str);
  99.         format(str, sizeof(str), "Duel | %s won the duel against %s (%s, %s, %s) (Bet: $%d) (%s [ID %d])", pName(duelerid), pName(playerid), weaponNames(Slot[0]), weaponNames(Slot[1]), weaponNames(Slot[2]), gBet, ReturnDuelNameFromID(gDuelSpot), gDuelSpot);
  100.         SendClientMessageToAll(COLOR_DUEL, str);
  101.        
  102.         SetPlayerArmour(playerid, 0);
  103.         SetPlayerArmour(duelerid, 0);
  104.  
  105.         RemoveFromDuel(playerid);
  106.         RemoveFromDuel(duelerid);
  107.         SpawnPlayer(duelerid);
  108.     }
  109.     TextDrawDestroy(SpecTD[playerid][0]);
  110.     TextDrawDestroy(SpecTD[playerid][1]);
  111.     return 1;
  112. }
  113.  
  114. public OnPlayerDeath(playerid, killerid, reason)
  115. {
  116.     if(GetPVarInt(killerid, "InDuel") == 1 && GetPVarInt(playerid, "InDuel") == 1)
  117.     {
  118.         new gBet = GetPVarInt(playerid, "DuelBet");
  119.         new gDuelSpot = GetPVarInt(playerid, "DuelSpot");
  120.  
  121.         new Slot[3];
  122.         Slot[0] = GetPVarInt(killerid, "dWeap1");
  123.         Slot[1] = GetPVarInt(killerid, "dWeap2");
  124.         Slot[2] = GetPVarInt(killerid, "dWeap3");
  125.  
  126.         Money_GivePlayerMoney(playerid, -gBet);
  127.         Money_GivePlayerMoney(killerid, gBet);
  128.  
  129.         new str[230], duelid[40];
  130.         new HPT = GetRoundedTotalHP(playerid);
  131.         format(duelid, sizeof(duelid), "%s", ReturnDuelNameFromID(gDuelSpot));
  132.         format(str, sizeof(str), "Duel | %s won the duel against %s {0004B6}(HP %d) (%s %s %s) {009900}(Bet: $%d) {F8FF3D}(%s [ID %d])", pName(killerid), pName(playerid), HPT, weaponNames(Slot[0]), weaponNames(Slot[1]), weaponNames(Slot[2]), gBet, duelid, gDuelSpot);
  133.         SendClientMessageToAll(COLOR_RED, str);
  134.  
  135.         SetPlayerArmour(playerid, 0);
  136.         SetPlayerArmour(killerid, 0);
  137.  
  138.         RemoveFromDuel(playerid);
  139.         RemoveFromDuel(killerid);
  140.         SpawnPlayer(killerid);
  141.     }
  142.     else if(killerid == INVALID_PLAYER_ID && GetPVarInt(playerid, "InDuel") == 1)
  143.     {
  144.         new gBet = GetPVarInt(playerid, "DuelBet");
  145.         new gDuelSpot = GetPVarInt(playerid, "DuelSpot");
  146.  
  147.         new Slot[3];
  148.         Slot[0] = GetPVarInt(playerid, "dWeap1");
  149.         Slot[1] = GetPVarInt(playerid, "dWeap2");
  150.         Slot[2] = GetPVarInt(playerid, "dWeap3");
  151.  
  152.         Money_GivePlayerMoney(playerid, -gBet);
  153.         Money_GivePlayerMoney(killerid, gBet);
  154.  
  155.         new str[220];
  156.         format(str, sizeof(str), "Duel | %s commited suicide during a duel with %s {0004B6}(%s %s %s) {009900}(Bet: $%d) {F8FF3D}(%s [ID %d])", pName(playerid), pName(GetPVarInt(playerid, "InviterID")), weaponNames(Slot[0]), weaponNames(Slot[1]), weaponNames(Slot[2]), gBet, ReturnDuelNameFromID(gDuelSpot), gDuelSpot);
  157.         SendClientMessageToAll(COLOR_DUEL, str);
  158.  
  159.         new duelerid = GetPVarInt(playerid, "InviterID");
  160.  
  161.         SetPlayerArmour(playerid, 0);
  162.         SetPlayerArmour(duelerid, 0);
  163.         RemoveFromDuel(duelerid);
  164.         RemoveFromDuel(playerid);
  165.         SpawnPlayer(duelerid);
  166.     }
  167.     return 1;
  168. }
  169.  
  170. public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
  171. {
  172.     if(newkeys == KEY_FIRE)
  173.     {
  174.         new specid = GetPVarInt(playerid, "DuelSpecID");
  175.         if(GetPVarInt(playerid, "DuelSpec") && IsPlayerInDuel(specid))
  176.         {
  177.             new dueler = GetPVarInt(specid, "InviterID");
  178.             SetPlayerSpectatingDuel(playerid, dueler);
  179.         }
  180.     }
  181.     return 1;
  182. }
  183.  
  184. public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
  185. {
  186.     if(dialogid == DUELDIAG)
  187.     {
  188.         if(response)
  189.         {
  190.             switch(listitem)
  191.             {
  192.                 case 0: //Choose player
  193.                 {
  194.                     ShowPlayerDialog(playerid, DUELDIAG+1, DIALOG_STYLE_INPUT, "Select a player", "Type in the name/playerid of the player you want\nto invite to a duel.\nNOTE: You can enter partial names.", "Continue", "Back");
  195.                 }
  196.                 case 1: //Choose Duel location
  197.                 {
  198.                     format(diagstr, sizeof(diagstr), "ID\tDuel Name\n");
  199.                     for(new x=0; x<MAX_DUELS; x++)
  200.                     {
  201.                         format(dFile, sizeof(dFile), DUELFILES, x);
  202.                         if(strlen(dini_Get(dFile, "duelName")) > 0) format(diagstr, sizeof(diagstr), "%s%d\t%s\n", diagstr, x, dini_Get(dFile, "duelName"));
  203.                         else format(diagstr, sizeof(diagstr), "%s%d\tEmpty Slot\n", diagstr, x);
  204.                     }
  205.                     ShowPlayerDialog(playerid, DUELDIAG+2, DIALOG_STYLE_LIST, "Duel List", diagstr, "Select", "Exit");
  206.                     return 1;
  207.                 }
  208.                 case 2: //Choose weapons
  209.                 {
  210.                     ShowPlayerDialog(playerid, DUELDIAG+5, DIALOG_STYLE_LIST, "Select Weapon Slot", "Slot 1\nSlot 2\nSlot 3", "Select", "Back");
  211.                 }
  212.                 case 3: //Choose Duel Money
  213.                 {
  214.                     ShowPlayerDialog(playerid, DUELDIAG+4, DIALOG_STYLE_INPUT, "Set Bet Amount", "Set the bet amount for the duel.\nThe winner takes the money and the loser\nloses this amount of money.", "Set", "Back");
  215.                 }
  216.                 case 4: //Send invitation
  217.                 {
  218.                     new str[80];
  219.                     new dPID = GetPVarInt(playerid, "dPID");
  220.                     new dBet = GetPVarInt(playerid, "dBet");
  221.                     new dLoc = GetPVarInt(playerid, "dLoc");
  222.                     new dWep[3], key[7];
  223.                     for(new x=0; x<=2; x++)
  224.                     {
  225.                         format(key, sizeof(key), "dWep%d", x);
  226.                         dWep[x] = GetPVarInt(playerid, key);
  227.                     }
  228.                     format(str, sizeof(str), "invite %d %d %d %d %d %d", dPID, dBet, dLoc, dWep[0], dWep[1], dWep[2]);
  229.                     return cmd_duel(playerid, str);
  230.                 }
  231.                 case 5: //Cancel invitation
  232.                 {
  233.                     return SendClientMessage(playerid, COLOR_DUEL, "Duel invite was canceled, duel settings were saved.");
  234.                 }
  235.             }
  236.         }
  237.     }
  238.     if(dialogid == DUELDIAG+1)
  239.     {
  240.         if(response)
  241.         {
  242.             new invitee;
  243.             if(sscanf(inputtext, "u", invitee)) return ShowPlayerDialog(playerid, DUELDIAG+1, DIALOG_STYLE_INPUT, "Select a player", "Type in the name/playerid of the player you want\nto invite to a duel.\nNOTE: You can enter partial names.", "Continue", "Back");
  244.             if(invitee == INVALID_PLAYER_ID) return ShowPlayerDialog(playerid, DUELDIAG+1, DIALOG_STYLE_INPUT, "Select a player", "ERROR: The player specified is not connected, try again!\nType in the name/playerid of the player you want\nto invite to a duel.\nNOTE: You can enter partial names.", "Continue", "Back");
  245.             SetPVarInt(playerid, "dPID", invitee);
  246.             ShowDuelSettingsDialog(playerid);
  247.         }
  248.         else ShowDuelSettingsDialog(playerid);
  249.     }
  250.     if(dialogid == DUELDIAG+2)
  251.     {
  252.         if(response)
  253.         {
  254.             format(dFile, sizeof(dFile), DUELFILES, listitem-1);
  255.             if(!dini_Exists(dFile)) return OnDialogResponse(playerid, DUELDIAG, 1, 1, "blank");
  256.             SetPVarInt(playerid, "dLoc", listitem-1);
  257.             ShowDuelSettingsDialog(playerid);
  258.         }
  259.         else ShowDuelSettingsDialog(playerid);
  260.     }
  261.     if(dialogid == DUELDIAG+4) //Duel money
  262.     {
  263.         if(response)
  264.         {
  265.             new amount;
  266.  
  267.             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");
  268.             if(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");
  269.             SetPVarInt(playerid, "dBet", amount);
  270.             ShowDuelSettingsDialog(playerid);
  271.         }
  272.         else ShowDuelSettingsDialog(playerid);
  273.     }
  274.     if(dialogid == DUELDIAG+5) //Weapon slots
  275.     {
  276.         if(response)
  277.         {
  278.             SetPVarInt(playerid, "dWSlot", listitem);
  279.             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");
  280.         }
  281.         else ShowDuelSettingsDialog(playerid);
  282.     }
  283.     if(dialogid == DUELDIAG+6)
  284.     {
  285.         if(response)
  286.         {
  287.             new key[7];
  288.             format(key, sizeof(key), "dWep%d", GetPVarInt(playerid, "dWSlot"));
  289.             switch(listitem)
  290.             {
  291.                 case 13..15:
  292.                 {
  293.                     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");
  294.                     return SendClientMessage(playerid, COLOR_RED, "ERROR: This weapon is disabled!");
  295.                 }
  296.             }
  297.             switch(listitem)
  298.             {
  299.                 case 0: SetPVarInt(playerid, key, 1);
  300.                 case 1: SetPVarInt(playerid, key, 2);
  301.                 case 2: SetPVarInt(playerid, key, 3);
  302.                 case 3: SetPVarInt(playerid, key, 4);
  303.                 case 4: SetPVarInt(playerid, key, 5);
  304.                 case 5: SetPVarInt(playerid, key, 6);
  305.                 case 6: SetPVarInt(playerid, key, 7);
  306.                 case 7: SetPVarInt(playerid, key, 8);
  307.                 case 8: SetPVarInt(playerid, key, 9);
  308.                 case 9: SetPVarInt(playerid, key, 10);
  309.                 case 10: SetPVarInt(playerid, key, 11);
  310.                 case 11: SetPVarInt(playerid, key, 14);
  311.                 case 12: SetPVarInt(playerid, key, 15);
  312.                 case 13: SetPVarInt(playerid, key, 16);
  313.                 case 14: SetPVarInt(playerid, key, 17);
  314.                 case 15: SetPVarInt(playerid, key, 18);
  315.                 case 16: SetPVarInt(playerid, key, 22);
  316.                 case 17: SetPVarInt(playerid, key, 23);
  317.                 case 18: SetPVarInt(playerid, key, 24);
  318.                 case 19: SetPVarInt(playerid, key, 25);
  319.                 case 20: SetPVarInt(playerid, key, 26);
  320.                 case 21: SetPVarInt(playerid, key, 27);
  321.                 case 22: SetPVarInt(playerid, key, 28);
  322.                 case 23: SetPVarInt(playerid, key, 29);
  323.                 case 24: SetPVarInt(playerid, key, 30);
  324.                 case 25: SetPVarInt(playerid, key, 31);
  325.                 case 26: SetPVarInt(playerid, key, 32);
  326.                 case 27: SetPVarInt(playerid, key, 33);
  327.                 case 28: SetPVarInt(playerid, key, 34);
  328.             }
  329.             ShowDuelSettingsDialog(playerid);
  330.         }
  331.         else ShowDuelSettingsDialog(playerid);
  332.     }
  333.     if(dialogid == DUELDIAG+7)
  334.     {
  335.         if(response)
  336.         {
  337.             if(!IsPlayerInDuel(diagitem[listitem])) return 1;
  338.             SetPlayerSpectatingDuel(playerid, diagitem[listitem]);
  339.         }
  340.         else return 1;
  341.     }
  342.     return 0;
  343. }
  344.  
  345. CMD:duelmenu(playerid, params[])
  346. {
  347.     ShowDuelSettingsDialog(playerid);
  348.     return 1;
  349. }
  350.  
  351. CMD:duels(playerid, params[])
  352. {
  353.     new tduels;
  354.     format(diagstr, sizeof(diagstr), "");
  355.     for(new x=0; x<MAX_PLAYERS; x++)
  356.     {
  357.         if(GetPVarInt(x, "InDuel") == 1)
  358.         {
  359.             for(new i=0; i<sizeof(diagitem); i++) if(x == diagitem[i]) continue; //Prevent duplicate duels
  360.             new dueler = GetPVarInt(x, "InviterID");
  361.             format(diagstr, sizeof(diagstr), "%s%s vs %s\n", diagstr, pName(x), pName(dueler));
  362.             diagitem[tduels] = x;
  363.             tduels++;
  364.         }
  365.     }
  366.     if(tduels < 1) format(diagstr, sizeof(diagstr), "There are currently no duels.");
  367.     ShowPlayerDialog(playerid, DUELDIAG+7, DIALOG_STYLE_LIST, "Current Duels", diagstr, "Select", "Cancel");
  368.     return 1;
  369. }
  370.  
  371. CMD:duel(playerid, params[])
  372. {
  373.     if(strfind(params, "create", true) != -1)
  374.     {
  375.         new third[60];
  376.         sscanf(params[7], "s[60]", third);
  377.         if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, COLOR_RED, "You are not an admin!");
  378.         if(GetPVarInt(playerid, "DuelEdit") == 1) return SendClientMessage(playerid, COLOR_RED, "You are already editing a duel!");
  379.  
  380.         new dName[90];
  381.         if(unformat(third, "s[90]", dName)) return SendClientMessage(playerid, COLOR_RED, "USAGE: /duel <create> <duelname>");
  382.         else if(!strlen(dName)) return SendClientMessage(playerid, COLOR_RED, "USAGE: /duel <create> <duelname>");
  383.         else if(DuelNameExists(dName)) return SendClientMessage(playerid, COLOR_RED, "This duel name already exists");
  384.  
  385.         new getid = GetLowestDuelSlotID();
  386.         format(dFile, sizeof(dFile), DUELFILES, getid);
  387.  
  388.         new Float:X, Float:Y, Float:Z, Float:A;
  389.         GetPlayerPos(playerid, X, Y, Z);
  390.         GetPlayerFacingAngle(playerid, A);
  391.         new dInterior = GetPlayerInterior(playerid);
  392.  
  393.         dini_Create(dFile);
  394.         dini_IntSet(dFile, "duelID", getid);
  395.         dini_Set(dFile, "duelName", dName);
  396.         dini_FloatSet(dFile, "duelX", X);
  397.         dini_FloatSet(dFile, "duelY", Y);
  398.         dini_FloatSet(dFile, "duelZ", Z);
  399.         dini_FloatSet(dFile, "duelA", A);
  400.         dini_IntSet(dFile, "duelInt", dInterior);
  401.         SetPVarInt(playerid, "DuelEdit", 1);
  402.         SetPVarInt(playerid, "DuelID", getid);
  403.  
  404.         new str[200];
  405.         format(str, sizeof(str), "Duel \"%s\" (ID: %d) created at: %f, %f, %f (Interior: %d)", dName, getid, X, Y, Z, dInterior);
  406.         SendClientMessage(playerid, COLOR_DUEL, str);
  407.         SendClientMessage(playerid, COLOR_DUEL, "Now go the second duelist position and type \"/duel <save>\" to set the position.");
  408.         return 1;
  409.     }
  410.     if(strfind(params, "save", true) != -1)
  411.     {
  412.         if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, COLOR_RED, "You are not an admin!");
  413.         if(GetPVarInt(playerid, "DuelEdit") == 0) return SendClientMessage(playerid, COLOR_RED, "You are not editing a duel.");
  414.  
  415.         new duelID = GetPVarInt(playerid, "DuelID");
  416.         format(dFile, sizeof(dFile), DUELFILES, duelID);
  417.  
  418.         new Float:X, Float:Y, Float:Z, Float:A;
  419.         GetPlayerPos(playerid, X, Y, Z);
  420.         GetPlayerFacingAngle(playerid, A);
  421.  
  422.         dini_FloatSet(dFile, "duel2X", X);
  423.         dini_FloatSet(dFile, "duel2Y", Y);
  424.         dini_FloatSet(dFile, "duel2Z", Z);
  425.         dini_FloatSet(dFile, "duel2A", A);
  426.  
  427.         new str[180];
  428.         format(str, sizeof(str), "Duel \"%s\" (ID: %d) second position set at: %f, %f, %f", ReturnDuelNameFromID(duelID), duelID, X, Y, Z);
  429.         SendClientMessage(playerid, COLOR_DUEL, str);
  430.  
  431.         SetPVarInt(playerid, "DuelEdit", 0);
  432.         SetPVarInt(playerid, "DuelID", -1);
  433.         return 1;
  434.     }
  435.     if(strfind(params, "invite", true) != -1)
  436.     {
  437.         new third[60];
  438.         sscanf(params[7], "s[60]", third);
  439.         new gTarget, gBet, gDuelSpot[85], gWeap[85], gWeap2[85], gWeap3[85];
  440.  
  441.         sscanf(third, "uis[85]s[85]s[85]s[85]", gTarget, gBet, gDuelSpot, gWeap, gWeap2, gWeap3);
  442.         if(gTarget == INVALID_PLAYER_ID) return SendClientMessage(playerid, COLOR_RED, "Duel | Player not found");
  443.         if(GetPVarInt(playerid, "InDuel") == 1) return SendClientMessage(playerid, COLOR_DUEL, "Duel | You are already in a duel!");
  444.         if(GetPVarInt(playerid, "DInvited") == 1 || GetPVarInt(playerid, "DInvited") == 2) return SendClientMessage(playerid, COLOR_DUEL, "Duel | You can't invite someone when you have been invited!");
  445.         if(gBet < 500) return SendClientMessage(playerid, COLOR_RED, "Duel | Minimum bet amount is 500");
  446.         if(MINMONEY != 0 && Money_GetPlayerMoney(playerid) < gBet) return SendClientMessage(playerid, COLOR_RED, "Duel | You don't have that amount of money to bet");
  447.         if(MINMONEY != 0 && Money_GetPlayerMoney(gTarget) < gBet) return SendClientMessage(playerid, COLOR_RED, "Duel | This player does not have that amount of money!");
  448.         if(ReturnDuelIDOrName(gDuelSpot) == -1) return SendClientMessage(playerid, COLOR_RED, "The duel id/name you entered does not exist!");
  449.         if(ReturnWeaponIDOrName(gWeap) == -1) return SendClientMessage(playerid, COLOR_RED, "Slot 1: Invalid Weapon ID or Name");
  450.         if(GetPlayerState(gTarget) == 9) return SendClientMessage(playerid, COLOR_RED, "Duel | This player is in spectate mode!");
  451.         if(!strlen(gWeap2)) format(gWeap2, sizeof(gWeap2), "48");
  452.         if(!strlen(gWeap3)) format(gWeap3, sizeof(gWeap3), "48");
  453.  
  454.         new duelID = ReturnDuelIDOrName(gDuelSpot);
  455.  
  456.         if(GetPVarInt(gTarget, "DInvited") == 1 || GetPVarInt(gTarget, "DInvited") == 2) return SendClientMessage(playerid, COLOR_DUEL, "Duel | This player has already been invited to a duel");
  457.         if(GetPVarInt(gTarget, "InDuel") == 1) return SendClientMessage(playerid, COLOR_DUEL, "Duel | This player is currently in a duel!");
  458.  
  459.         SetPVarInt(playerid, "DInvited", 1);
  460.         SetPVarInt(playerid, "InviterID", gTarget);
  461.         SetPVarInt(playerid, "DuelBet", gBet);
  462.         SetPVarInt(playerid, "DuelSpot", duelID);
  463.         SetPVarInt(gTarget, "DInvited", 2);
  464.         SetPVarInt(gTarget, "InviterID", playerid);
  465.         SetPVarInt(gTarget, "DuelBet", gBet);
  466.         SetPVarInt(gTarget, "DuelSpot", duelID);
  467.  
  468.         DuelTimer[playerid] = SetTimerEx("DuelReset", 15000, 0, "ii", playerid, gTarget);
  469.  
  470.         new Slot[3];
  471.         Slot[0] = ReturnWeaponIDOrName(gWeap);
  472.         Slot[1] = ReturnWeaponIDOrName(gWeap2);
  473.         Slot[2] = ReturnWeaponIDOrName(gWeap3);
  474.  
  475.         SetPVarInt(gTarget, "dWeap1", Slot[0]);
  476.         SetPVarInt(gTarget, "dWeap2", Slot[1]);
  477.         SetPVarInt(gTarget, "dWeap3", Slot[2]);
  478.         SetPVarInt(playerid, "dWeap1", Slot[0]);
  479.         SetPVarInt(playerid, "dWeap2", Slot[1]);
  480.         SetPVarInt(playerid, "dWeap3", Slot[2]);
  481.  
  482.         new str[150];
  483.         format(str, sizeof(str), "Duel invite from %s | (Bet: $%d) (%s %s %s) (%s [ID %d])", pName(playerid), gBet, weaponNames(Slot[0]), weaponNames(Slot[1]), weaponNames(Slot[2]), ReturnDuelNameFromID(duelID), duelID);
  484.         SendClientMessage(gTarget, COLOR_DUEL, str);
  485.         SendClientMessage(gTarget, COLOR_DUEL, "Type /yes or /no to accept/deny the duel invite");
  486.         format(str, sizeof(str), "Duel | Waiting for %s's response to your duel invite", pName(gTarget));
  487.         SendClientMessage(playerid, COLOR_DUEL, str);
  488.         return 1;
  489.     }
  490.     if(strfind(params, "edit", true) != -1)
  491.     {
  492.         new third[60];
  493.         sscanf(params[5], "s[60]", third);
  494.         if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, COLOR_RED, "You are not an admin!");
  495.         if(GetPVarInt(playerid, "DuelEdit") == 1) return SendClientMessage(playerid, COLOR_RED, "You are already editing a duel!");
  496.  
  497.         new dName[90];
  498.         if(unformat(third, "s[90]", dName)) return SendClientMessage(playerid, COLOR_RED, "USAGE: /duel <edit> <duelid/name>");
  499.         else if(!strlen(dName)) return SendClientMessage(playerid, COLOR_RED, "USAGE: /duel <edit> <duelid/name>");
  500.         else if(ReturnDuelIDOrName(dName) == -1) return SendClientMessage(playerid, COLOR_RED, "The duelid/name specified does not exist!");
  501.  
  502.         new getid = ReturnDuelIDOrName(dName);
  503.         format(dFile, sizeof(dFile), DUELFILES, getid);
  504.  
  505.         new Float:X, Float:Y, Float:Z, Float:A;
  506.         GetPlayerPos(playerid, X, Y, Z);
  507.         GetPlayerFacingAngle(playerid, A);
  508.         new dInterior = GetPlayerInterior(playerid);
  509.  
  510.         dini_FloatSet(dFile, "duelX", X);
  511.         dini_FloatSet(dFile, "duelY", Y);
  512.         dini_FloatSet(dFile, "duelZ", Z);
  513.         dini_FloatSet(dFile, "duelA", A);
  514.         dini_FloatSet(dFile, "duelInt", -dInterior);
  515.         SetPVarInt(playerid, "DuelEdit", 1);
  516.         SetPVarInt(playerid, "DuelID", getid);
  517.  
  518.         new str[200];
  519.         format(str, sizeof(str), "Duel \"%s\" (ID: %d) edited at: %f, %f, %f (Interior: %d)", dName, getid, X, Y, Z, dInterior);
  520.         SendClientMessage(playerid, COLOR_DUEL, str);
  521.         SendClientMessage(playerid, COLOR_DUEL, "Now go the second duelist position and type \"/duel save\" to set the position.");
  522.         return 1;
  523.     }
  524.     if(strfind(params, "setname", true) != -1)
  525.     {
  526.         new third[60];
  527.         sscanf(params[8], "s[60]", third);
  528.         if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, COLOR_RED, "You are not an admin!");
  529.  
  530.         new dName[90], dNewName[35];
  531.         if(unformat(third, "s[90]s[35]", dName, dNewName)) return SendClientMessage(playerid, COLOR_RED, "USAGE: /duel <setname> <duelid/name> <newduelname>");
  532.         else if(!strlen(dName)) return SendClientMessage(playerid, COLOR_RED, "USAGE: /duel <setname> <duelid/name> <newduelname>");
  533.         else if(ReturnDuelIDOrName(dName) == -1) return SendClientMessage(playerid, COLOR_RED, "The duelid/name specified does not exist!");
  534.         else if(strlen(dNewName) > 35) return SendClientMessage(playerid, COLOR_RED, "Max duel name length is 50 characters");
  535.  
  536.         new getid = ReturnDuelIDOrName(dName);
  537.         format(dFile, sizeof(dFile), DUELFILES, getid);
  538.  
  539.         dini_Set(dFile, "duelName", dNewName);
  540.  
  541.         new str[200];
  542.         format(str, sizeof(str), "Duel \"%s\" (ID: %d) is now named \"%s\"", dName, getid, dNewName);
  543.         SendClientMessage(playerid, COLOR_DUEL, str);
  544.         return 1;
  545.     }
  546.     if(strfind(params, "remove", true) != -1)
  547.     {
  548.         new third[60];
  549.         sscanf(params[7], "s[60]", third);
  550.         if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, COLOR_RED, "ERROR: You are not an admin!");
  551.  
  552.         new dName[90];
  553.         if(unformat(third, "s[90]", dName)) return SendClientMessage(playerid, COLOR_RED, "USAGE: /duel <remove> <duelid/name>");
  554.         else if(!strlen(dName)) return SendClientMessage(playerid, COLOR_RED, "USAGE: /duel <remove> <duelid/name>");
  555.         else if(!DuelNameExists(dName)) return SendClientMessage(playerid, COLOR_RED, "The duel id/name specified does not exist");
  556.         else if(ReturnDuelIDOrName(dName) == -1) return SendClientMessage(playerid, COLOR_RED, "The duel id/name specified does not exist");
  557.  
  558.         new duelID = ReturnDuelIDOrName(dName);
  559.         format(dFile, sizeof(dFile), DUELFILES, duelID);
  560.         dini_Remove(dFile);
  561.  
  562.         new str[100];
  563.         format(str, sizeof(str), "Duel \"%s\" (ID: %d) has been removed!", dName, duelID);
  564.         SendClientMessage(playerid, COLOR_DUEL, str);
  565.         return 1;
  566.     }
  567.     if(strfind(params, "help", true) != -1)
  568.     {
  569.         ShowPlayerDialog(playerid, 0, DIALOG_STYLE_MSGBOX, "Duel Help", "Invite someone to a duel:\n/duel <invite> <playerid/name> <betamount> <duelspot> <wep1> <wep2> <wep3>\n\nExample: \"/duel invite Noob 500 SFBridge spas deagle\"\nYou may enter partial weapon names.\nYou may use a minimum of 1 weapon and a max of 3.", "Ok", "");
  570.         return 1;
  571.     }
  572.     if(strfind(params, "cmds", true) != -1)
  573.     {
  574.         if(!IsPlayerAdmin(playerid)) ShowPlayerDialog(playerid, 0, DIALOG_STYLE_MSGBOX, "Duel Commands", "User Commands:\n\n/duel <cmds>, /duel <help>, /duel <invite>", "Ok", "");
  575.         else ShowPlayerDialog(playerid, 0, DIALOG_STYLE_MSGBOX, "Duel Commands", "User Commands:\n\n/duel <cmds>, /duel <help>, /duel <invite>\n\nBuilder Commands\n\n/duel <create>\n/duel <save>\n/duel <edit>\n/duel <setname>\n/duel <remove>", "Ok", "");
  576.         return 1;
  577.     }
  578.     if(strfind(params, "spec", true) != -1)
  579.     {
  580.         new third[60];
  581.         sscanf(params[5], "s[60]", third);
  582.  
  583.         new target;
  584.         sscanf(third, "u", target);
  585.         if(target == INVALID_PLAYER_ID) return SendClientMessage(playerid, COLOR_RED, "Duel | Player not found");
  586.         if(GetPVarInt(target, "InDuel") == 0) return SendClientMessage(playerid, COLOR_DUEL, "Duel | This player is not currently in a duel!");
  587.  
  588.         /*new str[150];
  589.         format(str, sizeof(str), "Duel invite from %s | (Bet: $%d) (Weapons: %s, %s, %s) (Place: %s [ID: %d])", pName(playerid), gBet, weaponNames(Slot[0]), weaponNames(Slot[1]), weaponNames(Slot[2]), ReturnDuelNameFromID(duelID), duelID);
  590.         SendClientMessage(gTarget, COLOR_DUEL, str);
  591.         SendClientMessage(gTarget, COLOR_DUEL, "Type /yes or /no to accept/deny the duel invite");
  592.         format(str, sizeof(str), "Duel | Waiting for %s's response to your duel invite", pName(gTarget));
  593.         SendClientMessage(playerid, COLOR_DUEL, str);*/
  594.         SetPlayerSpectatingDuel(playerid, target);
  595.         return 1;
  596.     }
  597.     else ShowDuelSettingsDialog(playerid);
  598.     return 1;
  599. }
  600.  
  601. CMD:yes(playerid, params[])
  602. {
  603.     if(GetPVarInt(playerid, "DInvited") != 2) return SendClientMessage(playerid, COLOR_RED, "You haven't been invited to a duel!");
  604.     if(GetPVarInt(playerid, "InDuel") == 1) return SendClientMessage(playerid, COLOR_RED, "You are already in a duel");
  605.  
  606.     new gPlayer = GetPVarInt(playerid, "InviterID");
  607.     new gBet = GetPVarInt(playerid, "DuelBet");
  608.     if(MINMONEY != 0 && Money_GetPlayerMoney(playerid) < gBet)
  609.     {
  610.         SendClientMessage(playerid, COLOR_RED, "Duel | You don't have that amount of money!");
  611.         SendClientMessage(gPlayer, COLOR_RED, "Duel | The player you invited no longer has that amount of money to bet!");
  612.        
  613.         SetPlayerArmour(playerid, 0);
  614.         SetPlayerArmour(gPlayer, 0);
  615.        
  616.         RemoveFromDuel(playerid);
  617.         RemoveFromDuel(gPlayer);
  618.         return 1;
  619.     }
  620.     new gDuelSpot = GetPVarInt(playerid, "DuelSpot");
  621.  
  622.     format(dFile, sizeof(dFile), DUELFILES, gDuelSpot);
  623.  
  624.     new Interior = dini_Int(dFile, "duelInt");
  625.     new Float:X, Float:Y, Float:Z, Float:A;
  626.     X = dini_Float(dFile, "duelX");
  627.     Y = dini_Float(dFile, "duelY");
  628.     Z = dini_Float(dFile, "duelZ");
  629.     A = dini_Float(dFile, "duelA");
  630.     new Float:X2, Float:Y2, Float:Z2, Float:A2;
  631.     X2 = dini_Float(dFile, "duel2X");
  632.     Y2 = dini_Float(dFile, "duel2Y");
  633.     Z2 = dini_Float(dFile, "duel2Z");
  634.     A2 = dini_Float(dFile, "duelA2");
  635.  
  636.     new Slot[3];
  637.     Slot[0] = GetPVarInt(playerid, "dWeap1");
  638.     Slot[1] = GetPVarInt(playerid, "dWeap2");
  639.     Slot[2] = GetPVarInt(playerid, "dWeap3");
  640.  
  641.     new world = playerid;
  642.     if(gPlayer > playerid) world = gPlayer;
  643.     else if(playerid > gPlayer) world = playerid;
  644.     AddToDuel(gPlayer, X2, Y2, Z2, A2, Interior, world, Slot[0], Slot[1], Slot[2]);
  645.     AddToDuel(playerid, X, Y, Z, A, Interior, world, Slot[0], Slot[1], Slot[2]);
  646.  
  647.     new str[150];
  648.     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);
  649.     SendClientMessageToAll(COLOR_DUEL, str);
  650.     return 1;
  651. }
  652.  
  653. CMD:no(playerid, params[])
  654. {
  655.     if(GetPVarInt(playerid, "DInvited") != 2) return SendClientMessage(playerid, COLOR_RED, "You haven't been invited to a duel!");
  656.     if(GetPVarInt(playerid, "InDuel") == 1) return SendClientMessage(playerid, COLOR_RED, "You are currently in a duel");
  657.  
  658.     new gDueler = GetPVarInt(playerid, "InviterID");
  659.  
  660.     new str[50];
  661.     format(str, sizeof(str), "Duel | %s has declined your duel invite", pName(playerid));
  662.     SendClientMessage(gDueler, COLOR_DUEL, str);
  663.    
  664.     SetPlayerArmour(playerid, 0);
  665.     SetPlayerArmour(gDueler, 0);
  666.  
  667.     RemoveFromDuel(playerid);
  668.     RemoveFromDuel(gDueler);
  669.     return 1;
  670. }
  671.  
  672. stock ShowDuelSettingsDialog(playerid)
  673. {
  674.     new str[255], wepstr[3][40], key[7];
  675.     new dPID = GetPVarInt(playerid, "dPID");
  676.     new dLoc = GetPVarInt(playerid, "dLoc");
  677.     for(new x=0; x<=2; x++)
  678.     {
  679.         format(key, sizeof(key), "dWep%d", x);
  680.         new wep = GetPVarInt(playerid, key);
  681.         format(wepstr[x], 40, "%s", weaponNames(wep));
  682.     }
  683.     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"));
  684.     ShowPlayerDialog(playerid, DUELDIAG, DIALOG_STYLE_LIST, "Duel Settings", str, "Select", "Cancel");
  685.     return 1;
  686. }
  687.  
  688. //=========[Duel Callbacks]========
  689. public DuelReset(player1, player2)
  690. {
  691.     new str[50];
  692.     format(str, sizeof(str), "%s didn't respond to your duel invite", pName(player2));
  693.     SendClientMessage(player1, COLOR_DUEL, str);
  694.    
  695.     SetPlayerArmour(player1, 0);
  696.     SetPlayerArmour(player2, 0);
  697.    
  698.     RemoveFromDuel(player1);
  699.     RemoveFromDuel(player2);
  700.     return 1;
  701. }
  702.  
  703. public DuelCDUpdate(playerid)
  704. {
  705.     SetPVarInt(playerid, "CDTick", GetPVarInt(playerid, "CDTick")+1);
  706.     if(GetPVarInt(playerid, "CDTick") > 3)
  707.     {
  708.         TogglePlayerControllable(playerid, 1);
  709.         GameTextForPlayer(playerid, "~R~Fight!", 1000, 6);
  710.         SetPVarInt(playerid, "CDTick", 0);
  711.         KillTimer(DuelTimer[playerid]);
  712.         PlayerPlaySound(playerid, 1057, 0.0, 0.0, 0.0);
  713.     }
  714.     else
  715.     {
  716.         GameTextForPlayer(playerid, "~P~Starting...", 500, 6);
  717.         PlayerPlaySound(playerid, 1056, 0.0, 0.0, 0.0);
  718.     }
  719.     return 1;
  720. }
  721. //=========[Duel Callbacks - END]==========
  722.  
  723. stock AddToDuel(playerid, Float:X, Float:Y, Float:Z, Float:A, interior, world, wep1, wep2, wep3)
  724. {
  725.     KillTimer(DuelTimer[playerid]);
  726.     SetPVarInt(playerid, "CDTick", 0);
  727.     SetPVarInt(playerid, "InDuel", 1);
  728.     SetPVarInt(playerid, "ArmourReport", 1);
  729.     SetPVarInt(playerid, "DInvited", 0);
  730.     SetPlayerPosEx(playerid, X, Y, Z, A, interior, world);
  731.     SetPlayerArmour(playerid, 100);
  732.     SetPlayerHealth(playerid, 100);
  733.     ResetPlayerWeapons(playerid);
  734.     GivePlayerWeapon(playerid, wep1, 1337);
  735.     GivePlayerWeapon(playerid, wep2, 1337);
  736.     GivePlayerWeapon(playerid, wep3, 1337);
  737.     TogglePlayerControllable(playerid, 0);
  738.     SetCameraBehindPlayer(playerid);
  739.     DuelTimer[playerid] = SetTimerEx("DuelCDUpdate", 1000, 1, "i", playerid);
  740.     SetPlayerColor(playerid, COLOR_DUEL);
  741.     return 1;
  742. }
  743.  
  744. stock RemoveFromDuel(playerid)
  745. {
  746.     KillTimer(DuelTimer[playerid]);
  747.     SetPlayerArmour(playerid, 0);
  748.     SetPlayerVirtualWorld(playerid, 0);
  749.     SetPVarInt(playerid, "DInvited", 0);
  750.     SetPVarInt(playerid, "InviterID", -1);
  751.     SetPVarInt(playerid, "DuelBet", -1);
  752.     SetPVarInt(playerid, "DuelSpot", -1);
  753.     SetPVarInt(playerid, "dWeap1", -1);
  754.     SetPVarInt(playerid, "dWeap2", -1);
  755.     SetPVarInt(playerid, "dWeap3", -1);
  756.     SetPVarInt(playerid, "ArmorReport", 0);
  757.     SetPVarInt(playerid, "InDuel", 0);
  758.     return 1;
  759. }
  760.  
  761. stock SetPlayerPosEx(playerid, Float:X, Float:Y, Float:Z, Float:angle, interior, world)
  762. {
  763.     SetPlayerPos(playerid, X, Y, Z);
  764.     SetPlayerFacingAngle(playerid, angle);
  765.     SetPlayerInterior(playerid, interior);
  766.     SetPlayerVirtualWorld(playerid, world);
  767.     return 1;
  768. }
  769.  
  770. stock IsValidWeapon(weaponid)
  771. {
  772.     switch(weaponid)
  773.     {
  774.         case 0, 19, 20, 21, 35..46: return 0;
  775.     }
  776.     if(weaponid < 0 || weaponid > 48) return 0;
  777.     return 1;
  778. }
  779.  
  780. //=========[Duel Spectate Functions]==========
  781. stock LoadDuelSpecTextdraw(playerid)
  782. {
  783.     SpecTD[playerid][0] = TextDrawCreate(180.000000, 364.000000, "_");
  784.     TextDrawBackgroundColor(SpecTD[playerid][0], 255);
  785.     TextDrawFont(SpecTD[playerid][0], 3);
  786.     TextDrawLetterSize(SpecTD[playerid][0], 0.469999, 1.200000);
  787.     TextDrawColor(SpecTD[playerid][0], 52479);
  788.     TextDrawSetOutline(SpecTD[playerid][0], 0);
  789.     TextDrawSetProportional(SpecTD[playerid][0], 1);
  790.     TextDrawSetShadow(SpecTD[playerid][0], 1);
  791.     SpecTD[playerid][1] = TextDrawCreate(180.000000, 387.000000, "_");
  792.     TextDrawBackgroundColor(SpecTD[playerid][1], 255);
  793.     TextDrawFont(SpecTD[playerid][1], 3);
  794.     TextDrawLetterSize(SpecTD[playerid][1], 0.469999, 1.200000);
  795.     TextDrawColor(SpecTD[playerid][1], -1);
  796.     TextDrawSetOutline(SpecTD[playerid][1], 0);
  797.     TextDrawSetProportional(SpecTD[playerid][1], 1);
  798.     TextDrawSetShadow(SpecTD[playerid][1], 1);
  799.     TextDrawHideForAll(SpecTD[playerid][0]);
  800.     TextDrawHideForAll(SpecTD[playerid][1]);
  801. }
  802.  
  803. public UpdateSpectate(playerid)
  804. {
  805.     new specid = GetPVarInt(playerid, "DuelSpecID");
  806.     if(!IsPlayerInDuel(specid)) return EndDuelSpectate(playerid);
  807.     else ShowDuelSpecTextdraw(playerid, specid);
  808.     SetPlayerVirtualWorld(playerid, GetPlayerVirtualWorld(specid));
  809.     SetPlayerInterior(playerid, GetPlayerInterior(specid));
  810.     return 1;
  811. }
  812.  
  813. stock EndDuelSpectate(playerid)
  814. {
  815.     KillTimer(UpdateSpecTimer[playerid]);
  816.     SetPVarInt(playerid, "DuelSpecID", -1);
  817.     SetPVarInt(playerid, "DuelSpec", 0);
  818.     SendClientMessage(playerid, COLOR_DUEL, "Duel spectate ended, duel is no longer in progress.");
  819.     TogglePlayerSpectating(playerid, 0);
  820.     KillTimer(UpdateSpecTimer[playerid]);
  821.     TextDrawHideForPlayer(playerid, SpecTD[playerid][0]);
  822.     TextDrawHideForPlayer(playerid, SpecTD[playerid][1]);
  823.     return 1;
  824. }
  825.  
  826. stock SetPlayerSpectatingDuel(playerid, duelerid)
  827. {
  828.     TogglePlayerSpectating(playerid, 1);
  829.     SendClientMessage(playerid, COLOR_DUEL, "You have entered duel spectate mode!");
  830.     SendClientMessage(playerid, COLOR_DUEL, "Press ~k~~PED_FIREWEAPON~ to switch between duelists.");
  831.     ShowDuelSpecTextdraw(playerid, duelerid);
  832.     KillTimer(UpdateSpecTimer[playerid]);
  833.     UpdateSpecTimer[playerid] = SetTimerEx("UpdateSpectate", 1000, 1, "d", playerid);
  834.     SetPVarInt(playerid, "DuelSpecID", duelerid);
  835.     SetPVarInt(playerid, "DuelSpec", 1);
  836.     SetPlayerVirtualWorld(playerid, GetPlayerVirtualWorld(duelerid));
  837.     SetPlayerInterior(playerid, GetPlayerInterior(duelerid));
  838.     PlayerSpectatePlayer(playerid, duelerid, SPECTATE_MODE_NORMAL);
  839. }
  840.  
  841. stock ShowDuelSpecTextdraw(playerid, duelerid)
  842. {
  843.     new sstr[100], sstr2[140];
  844.  
  845.     new duelid[40];
  846.     new gBet = GetPVarInt(duelerid, "DuelBet");
  847.     new gDuelSpot = GetPVarInt(duelerid, "DuelSpot");
  848.     new dueler = GetPVarInt(duelerid, "InviterID");
  849.     format(duelid, sizeof(duelid), "%s", ReturnDuelNameFromID(gDuelSpot));
  850.  
  851.     new Slot[3];
  852.     Slot[0] = GetPVarInt(duelerid, "dWeap1");
  853.     Slot[1] = GetPVarInt(duelerid, "dWeap2");
  854.     Slot[2] = GetPVarInt(duelerid, "dWeap3");
  855.  
  856.     format(sstr, sizeof(sstr), "%s vs %s~n~~R~HP ~W~%d      %d", pName(duelerid), pName(dueler), GetRoundedTotalHP(duelerid), GetRoundedTotalHP(dueler));
  857.     format(sstr2, sizeof(sstr2), "~Y~Location ~w~%s~n~~p~Weapons ~w~%s %s %s~n~~g~Bet Money ~w~$%d",
  858.     duelid, weaponNames(Slot[0]), weaponNames(Slot[1]), weaponNames(Slot[2]), gBet);
  859.     TextDrawHideForPlayer(playerid, SpecTD[playerid][0]);
  860.     TextDrawHideForPlayer(playerid, SpecTD[playerid][1]);
  861.     TextDrawSetString(SpecTD[playerid][0], sstr);
  862.     TextDrawSetString(SpecTD[playerid][1], sstr2);
  863.     TextDrawShowForPlayer(playerid, SpecTD[playerid][0]);
  864.     TextDrawShowForPlayer(playerid, SpecTD[playerid][1]);
  865. }
  866. //=======================[Spectate -END-]==========================
  867.  
  868. stock IsPlayerInDuel(playerid)
  869. {
  870.     if(GetPVarInt(playerid, "InDuel") == 1) return 1;
  871.     return 0;
  872. }
  873.  
  874. stock ReturnWeaponIDOrName(idname[])
  875. {
  876.     if(!IsNumeric(idname))
  877.     {
  878.         new gWeap = GetWeaponModelIDFromName(idname);
  879.         if(IsValidWeapon(gWeap)) return gWeap;
  880.     }
  881.     else if(IsNumeric(idname))
  882.     {
  883.         new gWeap = strval(idname);
  884.         if(IsValidWeapon(gWeap)) return gWeap;
  885.     }
  886.     return -1;
  887. }
  888.  
  889. stock GetRoundedTotalHP(playerid)
  890. {
  891.     new Float:HP, Float:Armour, HPT;
  892.     GetPlayerHealth(playerid, HP);
  893.     GetPlayerArmour(playerid, Armour);
  894.     HPT = floatround(HP) + floatround(Armour);
  895.     return HPT;
  896. }
  897.  
  898. GetWeaponModelIDFromName(wname[])
  899. {
  900.     for(new i=0; i<49; i++)
  901.     {
  902.         if(i == 19 || i == 20 || i == 21) continue;
  903.         if(strfind(weaponNames(i), wname, true) != -1) return i;
  904.     }
  905.     return -1;
  906. }
  907.  
  908. stock GetLowestDuelSlotID()
  909. {
  910.     for(new x=0; x<MAX_DUELS; x++)
  911.     {
  912.         format(dFile, sizeof(dFile), DUELFILES, x);
  913.         if(!dini_Exists(dFile)) return x;
  914.     }
  915.     return 1;
  916. }
  917.  
  918. stock DuelNameExists(duelname[])
  919. {
  920.     for(new x=0; x<MAX_DUELS; x++)
  921.     {
  922.         format(dFile, sizeof(dFile), DUELFILES, x);
  923.         if(strfind(duelname, dini_Get(dFile, "duelName"), true) != -1) return 1;
  924.         break;
  925.     }
  926.     return 0;
  927. }
  928.  
  929. stock ReturnDuelIDOrName(duelname[])
  930. {
  931.     if(!IsNumeric(duelname))
  932.     {
  933.         for(new x=0; x<MAX_DUELS; x++)
  934.         {
  935.             new dName[128];
  936.             new idfromname = x;
  937.             format(dFile, sizeof(dFile), DUELFILES, x);
  938.             format(dName, sizeof(dName), "%s", dini_Get(dFile, "duelName"));
  939.             if(strfind(dName, duelname, true) != -1) return idfromname;
  940.             break;
  941.         }
  942.     }
  943.     else if(IsNumeric(duelname))
  944.     {
  945.         new dName = strval(duelname);
  946.         format(dFile, sizeof(dFile), DUELFILES, dName);
  947.         if(fexist(dFile)) return dName;
  948.     }
  949.     return -1;
  950. }
  951.  
  952. stock weaponNames(weaponid)
  953. {
  954.     new str[25];
  955.     switch(weaponid)
  956.     {
  957.         case 0: str = "Fist";
  958.         case 1: str = "Brass Knuckles";
  959.         case 2: str = "Golf Club";
  960.         case 3: str = "Night Stick";
  961.         case 4: str = "Knife";
  962.         case 5: str = "Baseball Bat";
  963.         case 6: str = "Shovel";
  964.         case 7: str = "Pool Cue";
  965.         case 8: str = "Katana";
  966.         case 9: str = "Chainsaw";
  967.         case 10: str = "Purple Dildo";
  968.         case 11: str = "Vibrator";
  969.         case 12: str = "Vibrator";
  970.         case 13: str = "Vibrator";
  971.         case 14: str = "Flowers";
  972.         case 15: str = "Cane";
  973.         case 16: str = "Grenade";
  974.         case 17: str = "Teargas";
  975.         case 18: str = "Molotov";
  976.         case 19: str = " ";
  977.         case 20: str = " ";
  978.         case 21: str = " ";
  979.         case 22: str = "Colt 45";
  980.         case 23: str = "Silenced Pistol";
  981.         case 24: str = "Deagle";
  982.         case 25: str = "Shotgun";
  983.         case 26: str = "Sawns";
  984.         case 27: str = "Spas";
  985.         case 28: str = "Uzi";
  986.         case 29: str = "MP5";
  987.         case 30: str = "AK47";
  988.         case 31: str = "M4";
  989.         case 32: str = "Tec9";
  990.         case 33: str = "County Rifle";
  991.         case 34: str = "Sniper Rifle";
  992.         case 35: str = "Rocket Launcher";
  993.         case 36: str = "Heat-Seeker";
  994.         case 37: str = "Flamethrower";
  995.         case 38: str = "Minigun";
  996.         case 39: str = "Satchel Charge";
  997.         case 40: str = "Detonator";
  998.         case 41: str = "Spray Can";
  999.         case 42: str = "Fire Extinguisher";
  1000.         case 43: str = "Camera";
  1001.         case 44: str = "Night Vision Goggles";
  1002.         case 45: str = "Infrared Goggles";
  1003.         case 46: str = "Parachute";
  1004.         case 47: str = "Fake Pistol";
  1005.         case 48: str = "None"; //For duel msgs
  1006.     }
  1007.     return str;
  1008. }
  1009.  
  1010. stock ReturnDuelNameFromID(duelid)
  1011. {
  1012.     format(dFile, sizeof(dFile), DUELFILES, duelid);
  1013.     new dName[80];
  1014.     format(dName, sizeof(dName), "%s", dini_Get(dFile, "duelName"));
  1015.     return dName;
  1016. }
  1017.  
  1018. stock pName(playerid)
  1019. {
  1020.     new paname[MAX_PLAYER_NAME];
  1021.     GetPlayerName(playerid, paname, sizeof(paname));
  1022.     return paname;
  1023. }
  1024.  
  1025. stock IsNumeric(string[])
  1026. {
  1027.     for(new i=0, j=strlen(string); i<j; i++)
  1028.     {
  1029.         if(string[i] > '9' || string[i] < '0') return 0;
  1030.     }
  1031.     return 1;
  1032. }
Advertisement
Add Comment
Please, Sign In to add comment