Advertisement
Guest User

duel

a guest
Mar 7th, 2013
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 8.37 KB | None | 0 0
  1. #include <a_samp>
  2.  
  3. /*
  4.  
  5.     Duel Filterscript (Ripped from LW_LVDM)
  6.     Brought to you by [NB]Sneaky
  7.  
  8.     www.99BlaZed.com
  9.     www.sneakyhost.net
  10.  
  11.     You will need to edit line 184,185,201,202
  12.  
  13. */
  14.  
  15. #define dcmd(%1,%2,%3) if (!strcmp((%3)[1], #%1, true, (%2)) && ((((%3)[(%2) + 1] == '\0') && (dcmd_%1(playerid, ""))) || (((%3)[(%2) + 1] == ' ') && (dcmd_%1(playerid, (%3)[(%2) + 2]))))) return 1
  16. #define SendError(%1,%2) SendClientMessage(%1,COLOR_RED,"ERROR: " %2)
  17. #define SendUsage(%1,%2) SendClientMessage(%1,COLOR_WHITE,"USAGE: " %2)
  18.  
  19. #define COLOR_ORANGE    0xFF8040FF
  20. #define COLOR_YELLOW    0xFFFF00AA
  21. #define COLOR_RED       0xFF0000AA
  22. #define COLOR_WHITE     0xFFFFFFAA
  23.  
  24.  
  25. stock
  26.     g_GotInvitedToDuel[MAX_PLAYERS],
  27.     g_HasInvitedToDuel[MAX_PLAYERS],
  28.     g_IsPlayerDueling[MAX_PLAYERS],
  29.     g_DuelCountDown[MAX_PLAYERS],
  30.     g_DuelTimer[MAX_PLAYERS],
  31.     g_DuelInProgress,
  32.     g_DuelingID1,
  33.     g_DuelingID2;
  34.  
  35. public OnFilterScriptInit()
  36. {
  37.     print("\t============================================");
  38.     print("\tDuel Filterscript");
  39.     print("\t-");
  40.     print("\tLoaded");
  41.     print("\t============================================");
  42.     return 1;
  43. }
  44.  
  45. public OnFilterScriptExit()
  46. {
  47.     print("\t============================================");
  48.     print("\tDuel Filterscript");
  49.     print("\t-");
  50.     print("\tLoaded");
  51.     print("\t============================================");
  52.     return 1;
  53. }
  54.  
  55. public OnPlayerConnect(playerid)
  56. {
  57.     g_GotInvitedToDuel[playerid] = 0;
  58.     g_HasInvitedToDuel[playerid] = 0;
  59.     g_IsPlayerDueling[playerid]  = 0;
  60.     return 1;
  61. }
  62.  
  63. public OnPlayerDisconnect(playerid, reason)
  64. {
  65.     if(playerid == g_DuelingID1 || playerid == g_DuelingID2)
  66.     {
  67.         g_DuelInProgress = 0;
  68.     }
  69.     return 1;
  70. }
  71.  
  72. public OnPlayerCommandText(playerid, cmdtext[])
  73. {
  74.     dcmd(duel,4,cmdtext);
  75.     dcmd(cduel,5,cmdtext);
  76.     dcmd(duelaccept,10,cmdtext);
  77.     return 1;
  78. }
  79.  
  80. dcmd_cduel(playerid, params[])
  81. {
  82.     #pragma unused params
  83.  
  84.     if(g_HasInvitedToDuel[playerid] == 0)
  85.         return SendError(playerid, "You did not invite anyone to a duel!");
  86.  
  87.     SendClientMessage(playerid, COLOR_YELLOW, "You have reset your duel invite, you can now use /duel [playerid] again.");
  88.     g_HasInvitedToDuel[playerid] = 0;
  89.  
  90.     return 1;
  91. }
  92.  
  93. dcmd_duelaccept(playerid, params[])
  94. {
  95.     if(params[0] == '\0' || !IsNumeric(params))
  96.         return SendUsage(playerid, "/duelaccept [playerid]");
  97.  
  98.     if(g_DuelInProgress == 1)
  99.         return SendError(playerid, "Another duel is in progress at the moment, wait till that duel is finished!");
  100.  
  101.     new
  102.         DuelID = strvalEx(params),
  103.         pName[MAX_PLAYER_NAME],
  104.         zName[MAX_PLAYER_NAME],
  105.         tString[128];
  106.  
  107.     if(DuelID != g_GotInvitedToDuel[playerid])
  108.         return SendError(playerid, "That player did not invite you to a duel!");
  109.  
  110.     GetPlayerName(playerid, pName, MAX_PLAYER_NAME);
  111.     GetPlayerName(DuelID, zName, MAX_PLAYER_NAME);
  112.  
  113.     format(tString, sizeof(tString), "You accepted the duel with %s (ID:%d), duel will start in 10 seconds..",zName,DuelID);
  114.     SendClientMessage(playerid, COLOR_YELLOW, tString);
  115.  
  116.     format(tString, sizeof(tString), "%s (ID:%d), accepted the duel with you, duel will start in 10 seconds..",pName,playerid);
  117.     SendClientMessage(DuelID, COLOR_YELLOW, tString);
  118.  
  119.     format(tString, sizeof(tString), "(News) Duel between %s and %s will start in 10 seconds",pName,zName);
  120.     SendClientMessageToAll(COLOR_ORANGE, tString);
  121.  
  122.     InitializeDuel(playerid);
  123.     InitializeDuelEx( DuelID);
  124.  
  125.     g_IsPlayerDueling[playerid] = 1;
  126.     g_IsPlayerDueling[DuelID] = 1;
  127.  
  128.     g_DuelingID1 = playerid;
  129.     g_DuelingID2 = DuelID;
  130.  
  131.     g_DuelInProgress = 1;
  132.  
  133.     return 1;
  134. }
  135.  
  136. dcmd_duel(playerid, params[])
  137. {
  138.     if(params[0] == '\0' || !IsNumeric(params))
  139.         return SendUsage(playerid, "/duel [playerid]");
  140.  
  141.     if(g_HasInvitedToDuel[playerid] == 1)
  142.         return SendError(playerid, "You already invited someone to a duel! (Type, /cduel to reset your invite)");
  143.  
  144.     new
  145.         DuelID = strvalEx(params),
  146.         pName[MAX_PLAYER_NAME],
  147.         zName[MAX_PLAYER_NAME],
  148.         tString[128];
  149.  
  150.     GetPlayerName(playerid, pName, MAX_PLAYER_NAME);
  151.     GetPlayerName(DuelID, zName, MAX_PLAYER_NAME);
  152.  
  153.     if (!IsPlayerConnected(DuelID))
  154.         return SendError(playerid, "Player is not connected.");
  155.  
  156.     if( g_HasInvitedToDuel[DuelID] == 1)
  157.         return SendError(playerid, "That player is already invited to a duel!");
  158.  
  159.     if( DuelID  == playerid)
  160.         return SendError(playerid, "You can not duel yourself!");
  161.  
  162.     format(tString, sizeof(tString), "You invited %s (ID:%d) to a 1 on 1 duel, wait till %s accepts your invite.",zName, DuelID, zName);
  163.     SendClientMessage(playerid, COLOR_YELLOW, tString);
  164.  
  165.     format(tString, sizeof(tString), "You got invited by %s (ID:%d) to a 1 on 1 duel, type /duelaccept [playerid] to accept and start the duel. ",pName, playerid);
  166.     SendClientMessage(DuelID, COLOR_YELLOW, tString);
  167.  
  168.     g_GotInvitedToDuel[DuelID] = playerid;
  169.     g_HasInvitedToDuel[playerid] = 1;
  170.  
  171.     return 1;
  172. }
  173.  
  174. forward InitializeDuel(playerid);
  175. public InitializeDuel(playerid)
  176. {
  177.     g_DuelTimer[playerid]  = SetTimerEx("DuelCountDown", 1000, 1, "i", playerid);
  178.  
  179.     SetPlayerHealth(playerid, 100);
  180.     SetPlayerArmour(playerid, 100);
  181.  
  182.     //SetPlayerPos(playerid, 1138.4370, 1206.9835, 10.8203); // da1
  183.     //SetPlayerFacingAngle(playerid, 4.1095);
  184.     GivePlayerWeapon(playerid, 9, 1);
  185.     GivePlayerWeapon(playerid, 24, 999);
  186.     GivePlayerWeapon(playerid, 26, 9999);
  187.     GivePlayerWeapon(playerid, 28, 9999);
  188.     GivePlayerWeapon(playerid, 31, 9999);
  189.     GivePlayerWeapon(playerid, 34, 9999);
  190.     SetCameraBehindPlayer(playerid);
  191.     TogglePlayerControllable(playerid, 0);
  192.     g_DuelCountDown[playerid] = 11;
  193.  
  194.     return 1;
  195. }
  196.  
  197. forward InitializeDuelEx(playerid);
  198. public InitializeDuelEx(playerid)
  199. {
  200.     g_DuelTimer[playerid]  = SetTimerEx("DuelCountDown", 1000, 1, "i", playerid);
  201.  
  202.     SetPlayerHealth(playerid, 100);
  203.     SetPlayerArmour(playerid, 100);
  204.  
  205.     //SetPlayerPos(playerid, 1129.7950, 1359.1833, 10.8203);
  206.     //SetPlayerFacingAngle(playerid, 181.4745);
  207.     GivePlayerWeapon(playerid, 9, 1);
  208.     GivePlayerWeapon(playerid, 24, 999);
  209.     GivePlayerWeapon(playerid, 26, 9999);
  210.     GivePlayerWeapon(playerid, 28, 9999);
  211.     GivePlayerWeapon(playerid, 31, 9999);
  212.     GivePlayerWeapon(playerid, 34, 9999);
  213.     SetCameraBehindPlayer(playerid);
  214.     TogglePlayerControllable(playerid, 0);
  215.     g_DuelCountDown[playerid] = 11;
  216.  
  217.     return 1;
  218. }
  219.  
  220. forward DuelCountDown(playerid);
  221. public DuelCountDown(playerid)
  222. {
  223.     new
  224.         tString[128] ;
  225.  
  226.     g_DuelCountDown[playerid] --;
  227.  
  228.     PlayerPlaySound(playerid, 1057, 0.0, 0.0, 0.0);
  229.  
  230.     format(tString, sizeof(tString), "~w~%d", g_DuelCountDown[playerid]);
  231.     GameTextForPlayer(playerid, tString, 900, 3);
  232.  
  233.     if(g_DuelCountDown[playerid] == 0)
  234.     {
  235.         KillTimer(g_DuelTimer[playerid]);
  236.         TogglePlayerControllable(playerid, 1);
  237.         GameTextForPlayer(playerid,"~g~GO GO GO", 900, 3);
  238.         return 1;
  239.     }
  240.  
  241.     return 1;
  242. }
  243.  
  244. strvalEx(xxx[])
  245. {
  246.     if(strlen(xxx) > 9)
  247.     return 0;
  248.     return strval(xxx);
  249. }
  250.  
  251. IsNumeric(const string[])
  252. {
  253.     for (new i = 0, j = strlen(string); i < j; i++)
  254.     {
  255.         if (string[i] > '9' || string[i] < '0') return false;
  256.     }
  257.     return true;
  258. }
  259.  
  260. public OnPlayerDeath(playerid, killerid, reason)
  261. {
  262.     new
  263.         sString[128],
  264.         pName[MAX_PLAYER_NAME],
  265.         zName[MAX_PLAYER_NAME],
  266.         Float:Health,
  267.         Float:Armor;
  268.  
  269.     if(g_IsPlayerDueling[playerid] == 1 && g_IsPlayerDueling[killerid] == 1)
  270.     {
  271.         GetPlayerHealth(killerid, Health);
  272.         GetPlayerArmour(killerid, Armor);
  273.  
  274.         GetPlayerName(playerid, pName, MAX_PLAYER_NAME);
  275.         GetPlayerName(killerid, zName, MAX_PLAYER_NAME);
  276.  
  277.         if(Health > 90.0 && Armor > 90.0)
  278.         {
  279.             format(sString, sizeof(sString),"(News) %s has \"OWNED\" %s in the duel and has %.2f health and %.2f armor left!", zName,pName,Health,Armor);
  280.             SendClientMessageToAll(COLOR_ORANGE, sString);
  281.  
  282.             g_GotInvitedToDuel[playerid] = 0;g_HasInvitedToDuel[playerid] = 0;g_IsPlayerDueling[playerid]  = 0;
  283.             g_GotInvitedToDuel[killerid] = 0;g_HasInvitedToDuel[killerid] = 0;g_IsPlayerDueling[killerid]  = 0;
  284.             g_DuelInProgress = 0;
  285.             return 1;
  286.         }
  287.         else
  288.         {
  289.             format(sString, sizeof(sString),"(News) %s has won the duel from %s and has %.2f health and %.2f armor left!", zName,pName,Health,Armor);
  290.             SendClientMessageToAll(COLOR_ORANGE, sString);
  291.  
  292.             g_GotInvitedToDuel[playerid] = 0;g_HasInvitedToDuel[playerid] = 0;g_IsPlayerDueling[playerid]  = 0;
  293.             g_GotInvitedToDuel[killerid] = 0;g_HasInvitedToDuel[killerid] = 0;g_IsPlayerDueling[killerid]  = 0;
  294.             g_DuelInProgress = 0;
  295.             return 1;
  296.        }
  297.     }
  298.     return 1;
  299. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement