Shadoww5

/declararguerra

Jun 2nd, 2011
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 4.79 KB | None | 0 0
  1. #include <a_samp>
  2.  
  3. #define X 0.0
  4. #define Y 0.0
  5. #define Z 0.0
  6.  
  7. new bool:Guerra;
  8.  
  9. public OnPlayerCommandText(playerid, cmdtext[])
  10. {
  11.     new Tick, tmp[256], idx, cmd[256];
  12.     cmd = strtok(cmdtext, idx);
  13.     if(strcmp(cmd, "/declararguerra", true) == 0)
  14.     {
  15.         new id, str[128];
  16.         tmp = strtok(cmdtext,idx);
  17.         id = strval(tmp);
  18.         if(Guerra == true) return SendClientMessage(playerid,-1,"Já está ocorrendo uma guerra.");
  19.         if(GetTickCount() - Tick < 60000) return SendClientMessage(playerid,-1,"Aguarde  2 minutos para declarar guerra novamente.");
  20.         if(!strlen(tmp)) return SendClientMessage(playerid, -1, "USO: /declararguerra [ID]");
  21.         if(GetPVarInt(playerid, "Guerra") == 1) return SendClientMessage(playerid, -1, "Você já está em uma guerra.");
  22.         if(GetPVarInt(id, "Guerra") == 1) return SendClientMessage(playerid, -1, "O jogador já está em uma guerra.");
  23.         if(id == playerid) return SendClientMessage(playerid, -1,"Você não pode declarar guerra a você mesmo.");
  24.         if(!IsPlayerConnected(id)) return SendClientMessage(playerid, -1,"Jogador Invalido.");
  25.     format(str, sizeof(str), "Você declarou guerra ao ID %d. Aguarde até que ele aceite.", id);
  26.         SendClientMessage(playerid, -1, str);
  27.         format(str, sizeof(str), "O ID %d declarou guerra à você. Para aceitar digite /aceitar, para recusar digite /recusar.", playerid);
  28.         SendClientMessage(playerid, -1, str);
  29.         SetPVarInt(playerid, "Guerra", 1);
  30.         SetPVarInt(id, "Guerra", 1);
  31.         SetPVarInt(id, "User", playerid);
  32.         Tick = GetTickCount();
  33.         return 1;
  34.     }
  35.     if(strcmp(cmd, "/recusar", true) == 0)
  36.     {
  37.         if(GetPVarInt(playerid, "Guerra") == 0) return SendClientMessage(playerid, -1, "Você não está em guerra alguma !");
  38.         SendClientMessage(playerid, -1, "Você recusou o pedido de guerra.");
  39.         SendClientMessage(GetPVarInt(playerid, "User"), -1, "Seu pedido de guerra foi recusado.");
  40.         SetPVarInt(playerid, "Guerra", 0);
  41.         SetPVarInt(GetPVarInt(playerid, "User"), "Guerra", 0);
  42.         DeletePVar(playerid, "User");
  43.         return 1;
  44.     }
  45.     if(strcmp(cmd, "/aceitar", true) == 0)
  46.     {
  47.         new n[MAX_PLAYER_NAME],n2[MAX_PLAYER_NAME], str[128];
  48.         if(GetPVarInt(playerid, "Guerra") == 0) return SendClientMessage(playerid, -1, "Você não está em guerra alguma !");
  49.         if(GetPVarInt(playerid, "Guerra") == 2) return SendClientMessage(playerid, -1, "Você já está em uma guerra.");
  50.         SendClientMessage(playerid, -1, "Você aceitou o pedido de guerra e foi teleportado.");
  51.         SendClientMessage(GetPVarInt(playerid, "User"), -1, "Seu pedido de guerra foi aceito e você foi teleportado.");
  52.         SetPlayerPos(GetPVarInt(playerid, "User"), X, Y, Z);
  53.         SetPlayerPos(playerid, X, Y, Z);
  54.         SetPVarInt(GetPVarInt(playerid, "User"), "Guerra", 2);
  55.         SetPVarInt(GetPVarInt(playerid, "User"), "User", playerid);
  56.         SetPVarInt(playerid, "Guerra", 2);
  57.         GetPlayerName(playerid, n, sizeof(n));
  58.         GetPlayerName(GetPVarInt(playerid, "User"), n2, sizeof(n2));
  59.         format(str, sizeof(str),"%s e %s entraram numa guerra.");
  60.         SendClientMessageToAll(-1, str);
  61.         Guerra = true;
  62.         return 1;
  63.     }
  64.     return 0;
  65. }
  66. public OnPlayerDeath(playerid, killerid, reason)
  67. {
  68.     if(Guerra == true)
  69.     {
  70.         if(GetPVarInt(playerid,"Guerra") == 2)
  71.         {
  72.             new n[MAX_PLAYER_NAME], n2[MAX_PLAYER_NAME], str[128];
  73.             GetPlayerName(GetPVarInt(playerid, "User"), n, sizeof(n));
  74.             GetPlayerName(playerid, n2, sizeof(n2));
  75.             format(str, sizeof(str), "%s matou %s em uma guerra !");
  76.             SendClientMessageToAll(-1,str);
  77.             GivePlayerMoney(playerid, -5000);
  78.             GivePlayerMoney(GetPVarInt(playerid, "User"), 5000);
  79.             SendClientMessage(playerid, -1,"Você morreu na guerra e por isso perdeu 5000.");
  80.             SendClientMessage(GetPVarInt(playerid, "User"), -1,"Você venceu a guerra e por isso ganhou 5000.");
  81.             SpawnPlayer(GetPVarInt(playerid, "User"));
  82.             Guerra = false;
  83.             SetPVarInt(playerid,"Guerra", 0);
  84.             SetPVarInt(GetPVarInt(playerid, "User"),"Guerra", 0);
  85.             DeletePVar(GetPVarInt(playerid, "User"), "User");
  86.             DeletePVar(playerid,"User");
  87.             return 1;
  88.         }
  89.         return 1;
  90.     }
  91.     return 1;
  92. }
  93. strtok(const string[], &index)
  94. {
  95.     new length = strlen(string);
  96.     while ((index < length) && (string[index] <= ' '))
  97.     {
  98.         index++;
  99.     }
  100.  
  101.     new offset = index;
  102.     new result[20];
  103.     while ((index < length) && (string[index] > ' ') && ((index - offset) < (sizeof(result) - 1)))
  104.     {
  105.         result[index - offset] = string[index];
  106.         index++;
  107.     }
  108.     result[index - offset] = EOS;
  109.     return result;
  110. }
Advertisement
Add Comment
Please, Sign In to add comment