GhostOwneD157

[FS] Sistema De Racha

Jan 23rd, 2012
412
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 12.92 KB | None | 0 0
  1. #include <a_samp>
  2.  
  3. new carroDU[2];
  4. new correndo[MAX_PLAYERS];
  5. new corrida = 0;
  6. new cashp = 0;
  7. new desafiante;
  8. new colocado = 0;
  9. new correndos[MAX_PLAYERS];
  10. stock PlayerName(playerid)
  11. {
  12.     new Name[MAX_PLAYER_NAME];
  13.     GetPlayerName(playerid, Name, MAX_PLAYER_NAME);
  14.     return Name;
  15. }
  16. new Float:carroe[2][4] = //4 = 4 coordenadas | 3 = 3 "valores" (X,Y,Z)
  17. {
  18.     {2062.4832,-1810.0673,13.0877,91.2496},
  19.     {2059.8037,-1815.0095,13.0877,90.4774}
  20. };
  21. new Float:racha[5][3] = //4 = 4 coordenadas | 3 = 3 "valores" (X,Y,Z)
  22. {
  23.      {1965.8903,-1812.1543,13.0874},
  24.      {1960.6847,-1918.1187,13.0883},
  25.      {1961.8507,-2163.1030,13.0868},
  26.      {1823.5540,-2165.9551,13.0879},
  27.      {1822.8104,-2026.0538,13.0867}
  28. };
  29. public OnFilterScriptInit()
  30. {
  31.     print("\n--------------------------------------");
  32.     print(" Blank Filterscript by your name here");
  33.     print("--------------------------------------\n");
  34.     return 1;
  35. }
  36.  
  37. public OnFilterScriptExit()
  38. {
  39.     return 1;
  40. }
  41.  
  42. public OnPlayerRequestClass(playerid, classid)
  43. {
  44.     SetPlayerPos(playerid, 1958.3783, 1343.1572, 15.3746);
  45.     SetPlayerCameraPos(playerid, 1958.3783, 1343.1572, 15.3746);
  46.     SetPlayerCameraLookAt(playerid, 1958.3783, 1343.1572, 15.3746);
  47.     return 1;
  48. }
  49.  
  50. stock strtok(const string[], &index)
  51. {
  52.     new length = strlen(string);
  53.     while ((index < length) && (string[index] <= ' '))
  54.     {
  55.         index++;
  56.     }
  57.     new offset = index;
  58.     new result[20];
  59.     while ((index < length) && (string[index] > ' ') && ((index - offset) < (sizeof(result) - 1)))
  60.     {
  61.         result[index - offset] = string[index];
  62.         index++;
  63.     }
  64.     result[index - offset] = EOS;
  65.     return result;
  66. }
  67. stock strtokEx(const string[], &index)
  68. {
  69.     new length = strlen(string);
  70.     while ((index < length) && (string[index] <= ' '))
  71.     {
  72.         index++;
  73.     }
  74.     new offset = index;
  75.     new result[64];
  76.     while ((index < length) && ((index - offset) < (sizeof(result) - 1)))
  77.     {
  78.         result[index - offset] = string[index];
  79.         index++;
  80.     }
  81.     result[index - offset] = EOS;
  82.     return result;
  83. }
  84. public OnPlayerCommandText(playerid, cmdtext[])
  85. {
  86.     new cmd[128];
  87.     new tmp[128];
  88.     new string[128];
  89.     new idx;
  90.     cmd = strtok(cmdtext, idx);
  91.     if(strcmp(cmd, "/duelarc", true) == 0)
  92.     {
  93.         if(IsPlayerConnected(playerid))
  94.         {
  95.             tmp = strtok(cmdtext, idx);
  96.             if(!strlen(tmp))
  97.             {
  98.                 SendClientMessage(playerid, 0xFFFFFFAA, "USE: /duelarc [id] [Aposta]");
  99.                 return 1;
  100.             }
  101.             new playa;
  102.             new money;
  103.             playa = ReturnUser(tmp);
  104.             tmp = strtok(cmdtext, idx);
  105.             money = strval(tmp);
  106.             if(GetPlayerMoney(playerid) < money)
  107.             {
  108.                 SendClientMessage(playerid,0xFFFFFFAA,"Você não tem Dinheiro Suficiente");
  109.                 return 1;
  110.             }
  111.             if(corrida == 1)
  112.             {
  113.                 SendClientMessage(playerid,0xFFFFFFAA,"Está tendo um Racha");
  114.                 return 1;
  115.             }
  116.             if(IsPlayerConnected(playa))
  117.             {
  118.                 if(playa != INVALID_PLAYER_ID)
  119.                 {
  120.                     correndo[playerid] = 1;
  121.                     carroDU[0] = CreateVehicle(434,carroe[0][0],carroe[0][1],carroe[0][2],carroe[0][3],1,0,60000);
  122.                     cashp = money;
  123.                     desafiante = playerid;
  124.                     PutPlayerInVehicle(playerid, carroDU[0], 0);
  125.                     TogglePlayerControllable(playerid, 0);
  126.                     format(string,sizeof(string),"O Jogador %s Desafiou Você para uma Corrida , Aposta %d Cash !",PlayerName(playerid),money);
  127.                     ShowPlayerDialog(playa,10,DIALOG_STYLE_MSGBOX,"Duelo",string,"Aceitar","Fechar");
  128.  
  129.                 }
  130.             }
  131.         }
  132.         return 1;
  133.     }
  134.     return 0;
  135. }
  136.  
  137. public OnPlayerEnterRaceCheckpoint(playerid)
  138. {
  139.     switch(correndos[playerid])
  140.     {
  141.         case 1:
  142.         {
  143.             DisablePlayerRaceCheckpoint(playerid);
  144.             SetPlayerRaceCheckpoint(playerid, 0, racha[1][0], racha[1][1], racha[1][2], racha[2][0], racha[2][1], racha[2][2], 10);
  145.             correndos[playerid] = 2;
  146.         }
  147.         case 2:
  148.         {
  149.             DisablePlayerRaceCheckpoint(playerid);
  150.             SetPlayerRaceCheckpoint(playerid, 0, racha[2][0], racha[2][1], racha[2][2], racha[3][0], racha[3][1], racha[3][2], 10);
  151.             correndos[playerid] = 3;
  152.         }
  153.         case 3:
  154.         {
  155.             DisablePlayerRaceCheckpoint(playerid);
  156.             SetPlayerRaceCheckpoint(playerid, 0, racha[3][0], racha[3][1], racha[3][2], racha[4][0], racha[4][1], racha[4][2], 10);
  157.             correndos[playerid] = 4;
  158.         }
  159.         case 4:
  160.         {
  161.             DisablePlayerRaceCheckpoint(playerid);
  162.             SetPlayerRaceCheckpoint(playerid, 1, racha[4][0], racha[4][1], racha[4][2], racha[4][0], racha[4][1], racha[4][2]-5, 10);
  163.             correndos[playerid] = 5;
  164.         }
  165.         case 5:
  166.         {
  167.             new strev[256];
  168.             DisablePlayerRaceCheckpoint(playerid);
  169.             colocado++;
  170.             switch(colocado)
  171.             {
  172.                 case 1:
  173.                 {
  174.                     format(strev,sizeof(strev),"{ffffff}Você Chegou em {037b00}Primeiro {ffffff}Lugar no {037b00}Racha{ffffff} e Ganhou {037b00}%d Cash",cashp*2);
  175.                     SendClientMessage(playerid,0xFFFFFFAA,strev);
  176.                     format(strev,sizeof(strev),"{ffffff}O Jogador {037b00}%s{ffffff}Venceu o Racha e faturou {037b00}%d Cash",PlayerName(playerid),cashp*2);
  177.                     SendClientMessageToAll(0xFFFFFFAA,strev);
  178.                     DestroyVehicle(GetPlayerVehicleID(playerid));
  179.                     correndo[playerid] = 0;
  180.                     correndos[playerid] = 0;
  181.                     corrida = 0;
  182.                     GivePlayerMoney(playerid, cashp*2);
  183.                 }
  184.                 case 2:
  185.                 {
  186.                     format(strev,sizeof(strev),"{ffffff} Você {ff080e}perdeu {ffffff}o Racha ");
  187.                     SendClientMessage(playerid,0xFFFFFFAA,strev);
  188.                     cashp = 0;
  189.                     correndo[playerid] = 0;
  190.                     DestroyVehicle(GetPlayerVehicleID(playerid));
  191.                     colocado = 0;
  192.                     correndos[playerid] = 0;
  193.                     desafiante = 0;
  194.                     return 1;
  195.                 }
  196.             }
  197.         }
  198.     }
  199.     return 1;
  200. }
  201.  
  202. ReturnUser(text[], playerid = INVALID_PLAYER_ID)
  203. {
  204.     new pos = 0;
  205.     while (text[pos] < 0x21) // Strip out leading spaces
  206.     {
  207.         if (text[pos] == 0) return INVALID_PLAYER_ID; // No passed text
  208.         pos++;
  209.     }
  210.     new userid = INVALID_PLAYER_ID;
  211.     if (IsNumeric(text[pos])) // Check whole passed string
  212.     {
  213.         // If they have a numeric name you have a problem (although names are checked on id failure)
  214.         userid = strval(text[pos]);
  215.         if (userid >=0 && userid < MAX_PLAYERS)
  216.         {
  217.             if(!IsPlayerConnected(userid))
  218.             {
  219.                 /*if (playerid != INVALID_PLAYER_ID)
  220.                 {
  221.                     SendClientMessage(playerid, 0xFF0000AA, "User not connected");
  222.                 }*/
  223.                 userid = INVALID_PLAYER_ID;
  224.             }
  225.             else
  226.             {
  227.                 return userid; // A player was found
  228.             }
  229.         }
  230.         /*else
  231.         {
  232.             if (playerid != INVALID_PLAYER_ID)
  233.             {
  234.                 SendClientMessage(playerid, 0xFF0000AA, "Invalid user ID");
  235.             }
  236.             userid = INVALID_PLAYER_ID;
  237.         }
  238.         return userid;*/
  239.         // Removed for fallthrough code
  240.     }
  241.     // They entered [part of] a name or the id search failed (check names just incase)
  242.     new len = strlen(text[pos]);
  243.     new count = 0;
  244.     new name[MAX_PLAYER_NAME];
  245.     for (new i = 0; i < MAX_PLAYERS; i++)
  246.     {
  247.         if (IsPlayerConnected(i))
  248.         {
  249.             GetPlayerName(i, name, sizeof (name));
  250.             if (strcmp(name, text[pos], true, len) == 0) // Check segment of name
  251.             {
  252.                 if (len == strlen(name)) // Exact match
  253.                 {
  254.                     return i; // Return the exact player on an exact match
  255.                     // Otherwise if there are two players:
  256.                     // Me and MeYou any time you entered Me it would find both
  257.                     // And never be able to return just Me's id
  258.                 }
  259.                 else // Partial match
  260.                 {
  261.                     count++;
  262.                     userid = i;
  263.                 }
  264.             }
  265.         }
  266.     }
  267.     if (count != 1)
  268.     {
  269.         if (playerid != INVALID_PLAYER_ID)
  270.         {
  271.             if (count)
  272.             {
  273.                 SendClientMessage(playerid, 0xFF0000AA, "Multiple users found, please narrow earch");
  274.             }
  275.             else
  276.             {
  277.                 SendClientMessage(playerid, 0xFF0000AA, "No matching user found");
  278.             }
  279.         }
  280.         userid = INVALID_PLAYER_ID;
  281.     }
  282.     return userid; // INVALID_USER_ID for bad return
  283. }
  284. public OnVehicleStreamOut(vehicleid, forplayerid)
  285. {
  286.     return 1;
  287. }
  288.  
  289. public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
  290. {
  291.     if(dialogid == 10)
  292.     {
  293.     if(response)
  294.     {
  295.         TogglePlayerControllable(playerid, 0);
  296.         correndo[playerid] = 1;
  297.         GivePlayerMoney(desafiante, - cashp);
  298.         SetVehicleToRespawn(carroDU[1]);
  299.         carroDU[1] = CreateVehicle(434,carroe[1][0],carroe[1][1],carroe[1][2],carroe[1][3],1,0,60000);
  300.         PutPlayerInVehicle(playerid, carroDU[1], 0);
  301.         GivePlayerMoney(playerid, - cashp);
  302.         corrida = 1;
  303.         SetTimer("InicioCorrida", 1000, false);
  304.     }
  305.     else
  306.     {
  307.         TogglePlayerControllable(desafiante, 1);
  308.         cashp = 0;
  309.         SendClientMessage(desafiante,0xFFFF00AA," O Desafiado Recusou, Saia do Veiculo ");
  310.         return 1;
  311.     }
  312.     }
  313.     return 1;
  314. }
  315. forward InicioCorrida();
  316. forward InicioCorrida2();
  317. forward InicioCorrida3();
  318. forward InicioCorrida4();
  319. forward InicioCorrida5();
  320. forward InicioCorridaGo();
  321. public InicioCorrida()
  322. {
  323.     for(new i = 0; i<MAX_PLAYERS; i++)
  324.     {
  325.         if(IsPlayerConnected(i))
  326.         {
  327.             if(correndo[i] == 1)
  328.             {
  329.                 GameTextForPlayer(i, "5", 1001, 5);
  330.                 PlayerPlaySound(i, 1056, 0.0, 0.0, 0.0);
  331.             }
  332.         }
  333.     }
  334.     SetTimer("InicioCorrida2", 1000, false);
  335.     return 1;
  336. }
  337.  
  338. public InicioCorrida2()
  339. {
  340.         for(new i = 0; i<MAX_PLAYERS; i++)
  341.         {
  342.             if(IsPlayerConnected(i))
  343.             {
  344.                 if(correndo[i] == 1)
  345.                 {
  346.                     GameTextForPlayer(i, "4", 1001, 5);
  347.                     PlayerPlaySound(i, 1056, 0.0, 0.0, 0.0);
  348.                 }
  349.             }
  350.         }
  351.         SetTimer("InicioCorrida3", 1000, false);
  352.         return 1;
  353. }
  354. public InicioCorrida3()
  355. {
  356.         for(new i = 0; i<MAX_PLAYERS; i++)
  357.         {
  358.             if(IsPlayerConnected(i))
  359.             {
  360.                 if(correndo[i] == 1)
  361.                 {
  362.                     GameTextForPlayer(i, "3", 1001, 5);
  363.                     PlayerPlaySound(i, 1056, 0.0, 0.0, 0.0);
  364.                 }
  365.             }
  366.         }
  367.         SetTimer("InicioCorrida4", 1000, false);
  368.         return 1;
  369. }
  370.  
  371. public InicioCorrida4()
  372. {
  373.         for(new i = 0; i<MAX_PLAYERS; i++)
  374.         {
  375.             if(IsPlayerConnected(i))
  376.             {
  377.                 if(correndo[i] == 1)
  378.                 {
  379.                     GameTextForPlayer(i, "2", 1001, 5);
  380.                     PlayerPlaySound(i, 1056, 0.0, 0.0, 0.0);
  381.                 }
  382.             }
  383.         }
  384.         SetTimer("InicioCorrida5", 1000, false);
  385.         return 1;
  386. }
  387.  
  388. public InicioCorrida5()
  389. {
  390.         for(new i = 0; i<MAX_PLAYERS; i++)
  391.         {
  392.             if(IsPlayerConnected(i))
  393.             {
  394.                 if(correndo[i] == 1)
  395.                 {
  396.                     PlayerPlaySound(i, 1056, 0.0, 0.0, 0.0);
  397.                     GameTextForPlayer(i, "1", 1001, 5);
  398.                 }
  399.             }
  400.         }
  401.         SetTimer("InicioCorridaGo", 1000, false);
  402.         return 1;
  403. }
  404. IsNumeric(const string[])
  405. {
  406.     for (new i = 0, j = strlen(string); i < j; i++)
  407.     {
  408.         if (string[i] > '9' || string[i] < '0') return 0;
  409.     }
  410.     return 1;
  411. }
  412. public InicioCorridaGo()
  413. {
  414.         for(new i = 0; i<MAX_PLAYERS; i++)
  415.         {
  416.             if(IsPlayerConnected(i))
  417.             {
  418.                 if(correndo[i] == 1)
  419.                 {
  420.                     GameTextForPlayer(i, "~r~VALENDO!", 1001, 5);
  421.                     TogglePlayerControllable(i, 1);
  422.                     correndos[i] = 1;
  423.                     SetPlayerRaceCheckpoint(i, 0, racha[0][0], racha[0][1], racha[0][2], racha[1][0], racha[1][1], racha[1][2], 10);
  424.                 }
  425.             }
  426.         }
  427.         return 1;
  428. }
Add Comment
Please, Sign In to add comment