Advertisement
Essle

new duel system

Jan 20th, 2012
2,051
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 10.79 KB | None | 0 0
  1. //==============================================================================
  2. //=============== NEW DUEL SYSTEM BY ESSLE (Mov1c) | version 2.0 ===============
  3. //==============================================================================
  4.  
  5. #include <a_samp>
  6.  
  7. #define DUEL_MIR        2000
  8. #define DUEL_ID             11777
  9.  
  10. new PlayerInDuel[MAX_PLAYERS];
  11. new GetDuelCreate[MAX_PLAYERS];
  12. new StartingDuel[MAX_PLAYERS];
  13. new CountDuelTimer[MAX_PLAYERS];
  14. new WeaponDuel = 24;
  15. new MoneyDuel = 1000;
  16. new bool:DuelPlaceVisit = false;
  17.  
  18. new Float:duelspawn[12][3] = {
  19. {-1129.8909,1057.5424,1346.4141},
  20. {-1103.7913,1086.7838,1341.9036},
  21. {-1082.0232,1043.7269,1343.7159},
  22. {-1053.5138,1023.3488,1343.1503},
  23. {-1048.3635,1058.6753,1343.9337},
  24. {-1060.6057,1092.9423,1342.9473},
  25. {-1036.6921,1088.7567,1343.1466},
  26. {-1015.7525,1069.8811,1344.1016},
  27. {-1020.4619,1034.2771,1342.4492},
  28. {-992.12230,1036.9589,1341.8861},
  29. {-973.94290,1061.5148,1345.6714},
  30. {-992.10420,1090.4716,1342.8617}
  31. };
  32.  
  33. forward DuelStarting(playerid);
  34.  
  35. //==============================================================================
  36.  
  37. public OnPlayerConnect(playerid)
  38. {
  39.     PlayerInDuel[playerid] = 0;
  40.     GetDuelCreate[playerid] = INVALID_PLAYER_ID;
  41.     return 1;
  42. }
  43.  
  44. //==============================================================================
  45.  
  46. public OnPlayerDisconnect(playerid, reason)
  47. {
  48.     KillTimer(CountDuelTimer[playerid]);
  49.     for(new i=0; i<MAX_PLAYERS; i++)
  50.     {
  51.         if(IsPlayerConnected(i))
  52.         {
  53.             if(PlayerInDuel[i] == 1)
  54.                 {
  55.                 PlayerInDuel[i] = 0;
  56.                 DuelPlaceVisit = false;
  57.                 SendClientMessage(i, -1, "Твой противник покинул дуэль!");
  58.                 OnPlayerSpawn(i);
  59.             }
  60.         }
  61.     }
  62.     return 1;
  63. }
  64.  
  65. //==============================================================================
  66.  
  67. public OnPlayerSpawn(playerid)
  68. {
  69.     return 1;
  70. }
  71.  
  72. //==============================================================================
  73.  
  74. public OnPlayerCommandText(playerid, cmdtext[])
  75. {
  76.         new string[1024], cmd[256], tmp[256], giveplayerid, idx;
  77.     cmd = strtok(cmdtext, idx);
  78.         if(strcmp(cmd, "/duel", true) == 0)
  79.     {
  80.         if(PlayerInDuel[playerid] == 1) return SendClientMessage(playerid, -1, "Ты уже участвуешь в дуэли.");
  81.         if(DuelPlaceVisit) return SendClientMessage(playerid, -1, "Подождите пока место для дуэли освободится.");
  82.         tmp = strtok(cmdtext, idx);
  83.         if(!strlen(tmp)) return SendClientMessage(playerid, -1, "Использование: /duel [ id игрока ] [ id оружия ] [ ставка ]");
  84.         giveplayerid = strval(tmp);
  85.         tmp = strtok(cmdtext, idx);
  86.         if(!strlen(tmp)) return SendClientMessage(playerid, -1, "Использование: /duel [ id игрока ] [ id оружия ] [ ставка ]");
  87.         WeaponDuel = strval(tmp);
  88.         if(WeaponDuel < 0 || WeaponDuel > 42) return SendClientMessage(playerid, -1, "Ты ввёл не верный id оружия. Используй id от 0 до 42");
  89.         tmp = strtok(cmdtext, idx);
  90.         if(!strlen(tmp)) return SendClientMessage(playerid, -1, "Использование: /duel [ id игрока ] [ id оружия ] [ ставка ]");
  91.         MoneyDuel = strval(tmp);
  92.         if(MoneyDuel < 1 || MoneyDuel > 100000) return SendClientMessage(playerid, -1, "Ты ввёл не верную сумму ставки. Используй сумму от 1$ до 100000$");
  93.         if(MoneyDuel > GetPlayerMoney(playerid)) return SendClientMessage(playerid, -1, "Тебе не хватает на ставку. Укажи другую сумму!");
  94.         if(MoneyDuel > GetPlayerMoney(giveplayerid)) return SendClientMessage(playerid, -1, "Твоему противнику не хватает на ставку. Укажи другую сумму!");
  95.         if(IsPlayerConnected(giveplayerid))
  96.         {
  97.             new Float:POS[3];
  98.                 GetPlayerPos(giveplayerid, POS[0], POS[1], POS[2]);
  99.                 if(playerid == giveplayerid) return SendClientMessage(playerid, -1, "Ты не можешь применить это действие к самому себе.");
  100.                 if(!IsPlayerInRangeOfPoint(playerid, 5, POS[0], POS[1], POS[2])) return SendClientMessage(playerid, -1, "Ты находишься слишком далеко от этого игрока.");
  101.             if(PlayerInDuel[giveplayerid] == 1) return SendClientMessage(playerid, -1, "Этот игрок уже участвует в дуэли.");
  102.              GetDuelCreate[giveplayerid] = playerid;
  103.                 format(string, sizeof(string), "Ты успешно пригласил игрока {9DDAF2}%s{FFFFFF} на дуэль! Дождись ответа.", pNick(giveplayerid));
  104.                 SendClientMessage(playerid, -1, string);
  105.                 format(string, sizeof(string), "Игрок %s приглашает тебя на дуэль.\n\nОружие: %d\nСтавка: %d$", pNick(playerid), WeaponDuel, MoneyDuel);
  106.                 ShowPlayerDialog(giveplayerid, DUEL_ID, DIALOG_STYLE_MSGBOX, "Приглашение на дуэль", string, "Да", "Нет");
  107.             }
  108.         else
  109.         {
  110.             SendClientMessage(playerid, -1, "Игрок с указанным тобой id не найден!");
  111.         }
  112.         return 1;
  113.     }
  114.     return 0;
  115. }
  116.  
  117. //==============================================================================
  118.  
  119. public DuelStarting(playerid)
  120. {
  121.         new string[256];
  122.         StartingDuel[playerid] -= 1;
  123.         format(string, sizeof(string), "~y~STARTING: ~w~%d", StartingDuel[playerid]);
  124.         GameTextForPlayer(playerid, string, 999, 3);
  125.         SetPlayerHealth(playerid, 100);
  126.         if(StartingDuel[playerid] == 0)
  127.         {
  128.             GameTextForPlayer(playerid, "~g~DUEL START", 3000, 3);
  129.             TogglePlayerControllable(playerid, true);
  130.             KillTimer(CountDuelTimer[playerid]);
  131.         }
  132.     return 1;
  133. }
  134.  
  135. //==============================================================================
  136.  
  137. public OnPlayerDeath(playerid, killerid, reason)
  138. {
  139.     if(PlayerInDuel[killerid] == 1 && PlayerInDuel[playerid] == 1)
  140.     {
  141.         new string[256];
  142.         DuelPlaceVisit = false;
  143.         PlayerInDuel[killerid] = 0;
  144.         PlayerInDuel[playerid] = 0;
  145.         GetDuelCreate[killerid] = INVALID_PLAYER_ID;
  146.         GetDuelCreate[playerid] = INVALID_PLAYER_ID;
  147.         GivePlayerMoney(killerid, MoneyDuel);
  148.         GivePlayerMoney(playerid, -MoneyDuel);
  149.         format(string, sizeof(string), "~g~+%d$", MoneyDuel);
  150.         GameTextForPlayer(killerid, string, 1000, 1);
  151.         format(string, sizeof(string), "~r~-%d$", MoneyDuel);
  152.         GameTextForPlayer(playerid, string, 1000, 1);
  153.         format(string, sizeof(string), ">>> В дуэли между игроками {FFFFFF}%s{00FF00} и {FFFFFF}%s{00FF00} победил игрок {FFFFFF}%s", pNick(killerid), pNick(playerid), pNick(killerid));
  154.         SendClientMessageToAll(0x00FF00FF, string);
  155.         SetTimerEx("OnPlayerSpawn", 1000, false, "i", killerid);
  156.         return 1;
  157.     }
  158.     return 1;
  159. }
  160.  
  161. //==============================================================================
  162.  
  163. public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
  164. {
  165.     new string[1024];
  166.     new dueledid = GetDuelCreate[playerid];
  167.     if(dialogid == DUEL_ID)
  168.     {
  169.         if(response)
  170.         {
  171.             if(PlayerInDuel[playerid] == 1)
  172.             {
  173.                 SendClientMessage(playerid, -1, "Ты уже участвуешь в дуэли.");
  174.                 SendClientMessage(dueledid, -1, "При соглашении на участие в дуэли произошла ошибка!");
  175.                 GetDuelCreate[playerid] = INVALID_PLAYER_ID;
  176.                 return 1;
  177.             }
  178.             if(PlayerInDuel[dueledid] == 1)
  179.             {
  180.                 SendClientMessage(playerid, -1, "Игрок, отославший тебе приглашение, уже участвует в дуэли.");
  181.                 SendClientMessage(dueledid, -1, "При соглашении на участие в дуэли произошла ошибка!");
  182.                 GetDuelCreate[playerid] = INVALID_PLAYER_ID;
  183.                 return 1;
  184.             }
  185.             if(DuelPlaceVisit)
  186.             {
  187.                 SendClientMessage(playerid, -1, "Подожди пока место для дуэли освободится.");
  188.                 SendClientMessage(dueledid, -1, "Подожди пока место для дуэли освободится.");
  189.                 GetDuelCreate[playerid] = INVALID_PLAYER_ID;
  190.                 return 1;
  191.             }
  192.             if(IsPlayerConnected(dueledid))
  193.             {
  194.                     PlayerInDuel[playerid] = 1;
  195.                 PlayerInDuel[dueledid] = 1;
  196.                 DuelPlaceVisit = true;
  197.                 new rand1 = random(sizeof(duelspawn));
  198.                     SetPlayerPos(playerid, duelspawn[rand1][0], duelspawn[rand1][1], duelspawn[rand1][2]);
  199.                     new rand2 = random(sizeof(duelspawn));
  200.                     SetPlayerPos(dueledid, duelspawn[rand2][0], duelspawn[rand2][1], duelspawn[rand2][2]);
  201.                     SetCameraBehindPlayer(playerid);
  202.                 SetCameraBehindPlayer(dueledid);
  203.                 SetPlayerInterior(playerid, 10);
  204.                 SetPlayerInterior(dueledid, 10);
  205.                 SetPlayerHealth(dueledid, 100);
  206.                 SetPlayerHealth(playerid, 100);
  207.                 SetPlayerVirtualWorld(playerid, DUEL_MIR);
  208.                 SetPlayerVirtualWorld(dueledid, DUEL_MIR);
  209.                 TogglePlayerControllable(playerid, false);
  210.                 TogglePlayerControllable(dueledid, false);
  211.                 StartingDuel[playerid] = 6;
  212.                 StartingDuel[dueledid] = 6;
  213.                 CountDuelTimer[playerid] = SetTimerEx("DuelStarting", 1000, true, "i", playerid);
  214.                 CountDuelTimer[dueledid] = SetTimerEx("DuelStarting", 1000, true, "i", dueledid);
  215.                 ResetPlayerWeapons(playerid);
  216.                 ResetPlayerWeapons(dueledid);
  217.                 GivePlayerWeapon(playerid, WeaponDuel, 99999);
  218.                 GivePlayerWeapon(dueledid, WeaponDuel, 99999);
  219.                 GetDuelCreate[playerid] = INVALID_PLAYER_ID;
  220.                 }
  221.                 else
  222.             {
  223.                 SendClientMessage(playerid, -1, "Игрок, отославший тебе приглашение, отсоеденился!");
  224.                 GetDuelCreate[playerid] = INVALID_PLAYER_ID;
  225.             }
  226.         }
  227.         else
  228.         {
  229.             format(string, sizeof(string), "Ты отказался на участие в дуэли с игроком {9DDAF2}%s", pNick(dueledid));
  230.             SendClientMessage(playerid, -1, string);
  231.             format(string, sizeof(string), "Игрок {9DDAF2}%s{FFFFFF} отказался на участие в дуэли с тобой!", pNick(playerid));
  232.             SendClientMessage(GetDuelCreate[playerid], -1, string);
  233.             GetDuelCreate[playerid] = INVALID_PLAYER_ID;
  234.         }
  235.         return 1;
  236.     }
  237.     return 1;
  238. }
  239.  
  240. //==============================================================================
  241.  
  242. stock pNick(playerid)
  243. {
  244.     new nick[MAX_PLAYER_NAME];
  245.     GetPlayerName(playerid, nick, MAX_PLAYER_NAME);
  246.     return nick;
  247. }
  248.  
  249. //==============================================================================
  250.  
  251. strtok(const string[], &index)
  252. {
  253.     new length = strlen(string);
  254.     while ((index < length) && (string[index] <= ' '))
  255.     {
  256.         index++;
  257.     }
  258.  
  259.     new offset = index;
  260.     new result[20];
  261.     while ((index < length) && (string[index] > ' ') && ((index - offset) < (sizeof(result) - 1)))
  262.     {
  263.         result[index - offset] = string[index];
  264.         index++;
  265.     }
  266.     result[index - offset] = EOS;
  267.     return result;
  268. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement