Guest User

Loteria System: By: Zinglish - Trdução & Edição: [NWD]Tweener_

a guest
Aug 28th, 2010
1,017
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 10.08 KB | None | 0 0
  1. // Lotto FS
  2. // By: Zinglish
  3. // Trdução & Edição: [NWD]Tweener_
  4. // Edit to your liking, no need to give credit btw
  5. // Only if wanted
  6.  
  7.  
  8. #include <a_samp>
  9. #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
  10.  
  11. // Colors
  12. #define COLOR_GREY 0x84848455
  13. #define COLOR_WHITE 0xFFFFFFFF
  14. #define COLOR_RED 0xE21F1FFF
  15. #define COLOR_TURQUOISE 0x84FFFFFF
  16. #define COLOR_YELLOW 0xFDFF3DFF
  17. #define COLOR_GREEN 0x62FF32FF
  18.  
  19. // Functions
  20.  
  21. stock RandomLottoCash()
  22. {
  23.     return random(30) * 100000;
  24. }
  25.  
  26.  
  27. stock PlayerName(playerid)
  28. {
  29.     new name[255];
  30.     GetPlayerName(playerid, name, 255);
  31.     return name;
  32. }
  33.  
  34. // Lotto variables
  35. new hasPlayedLotto[MAX_PLAYERS];
  36. new pLottoNumber[MAX_PLAYERS];
  37. new lottoWinner;
  38. new lottoCashAmount;
  39. new lottoCashAmountIncrease;
  40. new chosenLottoNumber[MAX_PLAYERS];
  41. new Text:lottoDrawText;
  42. new lottoDestroy;
  43. new Menu:lottoBacking;
  44.  
  45. runLotto()
  46. {
  47.     new stringLotto[512], stringClientMessage[256];
  48.     new lottoNumber = random(100);
  49.  
  50.     for (new i=0; i<MAX_PLAYERS; i++)
  51.     {
  52.         if (hasPlayedLotto[i] == 1)
  53.         {
  54.             if(chosenLottoNumber[i] == lottoNumber)
  55.             {
  56.                 lottoWinner = i;
  57.             }
  58.             hasPlayedLotto[i] = 0;
  59.             pLottoNumber[i] = 0;
  60.         }
  61.         ShowMenuForPlayer(lottoBacking, i);
  62.     }
  63.  
  64.     if(lottoWinner >= 0) //Se houver um Ganhador
  65.     {
  66.         format(stringLotto, sizeof(stringLotto), "~w~Loteria~n~~n~Premio: ~g~$%i        ~w~Numero Sorteado: ~b~%i~n~~n~~w~Ganhador: ~r~%s", lottoCashAmount, lottoNumber, PlayerName(lottoWinner));
  67.         format(stringClientMessage, sizeof(stringClientMessage), "| Loteria | %s ganhou $%i com a loteria.Jogue você também! /Loto", PlayerName(lottoWinner), lottoCashAmount);
  68.         GivePlayerMoney(lottoWinner, lottoCashAmount);
  69.         SendClientMessageToAll(COLOR_GREEN, stringClientMessage);
  70.         lottoCashAmount = RandomLottoCash();
  71.         lottoWinner = -1;
  72.     }
  73.     else if(lottoWinner == -1) // Sem ganhadores
  74.     {
  75.         format(stringLotto, sizeof(stringLotto), "~w~Loteria~n~~n~Premio: ~g~$%i        ~w~Numero Sorteado: ~b~%i~n~~w~Nenhum Ganhador", lottoCashAmount, lottoNumber);
  76.         SendClientMessageToAll(COLOR_GREEN, "| Loteria | Seja um ganhador! Jogue na loteria! /Loto" );
  77.         lottoCashAmount = lottoCashAmount + lottoCashAmountIncrease;
  78.     }
  79.  
  80.     TextDrawSetString(lottoDrawText, stringLotto);
  81.     TextDrawShowForAll(lottoDrawText);
  82.     KillTimer(lottoDestroy);
  83.     lottoDestroy = SetTimer("lottoDrawHide", 8000, 0);
  84. }
  85.  
  86. //------------------------------------------------
  87.  
  88. public OnFilterScriptInit()
  89. {
  90.     print("\n*************************************\n");
  91.     print("**      Criação: Zinglish         ***\n");
  92.     print("**Trdução & Edição: [NWD]Tweener_ ***\n");
  93.     print("*************************************\n");
  94.     return 1;
  95. }
  96.  
  97. public OnGameModeInit()
  98. {
  99.     lottoWinner = -1;
  100.     lottoCashAmount = RandomLottoCash();
  101.  
  102.     lottoDrawText = TextDrawCreate(350, 390, " ");
  103.     TextDrawAlignment(lottoDrawText, 2);
  104.     TextDrawSetShadow(lottoDrawText, 0);
  105.     TextDrawSetOutline(lottoDrawText, 1);
  106.     TextDrawFont(lottoDrawText, 1);
  107.     TextDrawLetterSize(lottoDrawText, 0.4, 0.8);
  108.     TextDrawHideForAll(lottoDrawText);
  109.  
  110.     lottoBacking = CreateMenu(" ", 1, 200, 380, 280);
  111.  
  112.     // Timers
  113.     SetTimer("lottoDrawCreate", 3600000, 1);
  114. }
  115.  
  116. public OnPlayerConnect(playerid)
  117. {
  118.     hasPlayedLotto[playerid] = 0;
  119.     pLottoNumber[playerid] = 0;
  120.  
  121.     HideMenuForPlayer(lottoBacking, playerid);
  122.     return 1;
  123. }
  124.  
  125. public OnPlayerCommandText(playerid, cmdtext[])
  126. {
  127.     dcmd(loto,4,cmdtext);
  128.  
  129.     if(strcmp(cmdtext, "/sortear") == 0)
  130.     {
  131.         if(IsPlayerAdmin(playerid))
  132.         {
  133.             runLotto();
  134.             return 1;
  135.         }
  136.         else
  137.         {
  138.             return 0;
  139.         }
  140.     }
  141.     return 0;
  142. }
  143. dcmd_loto(playerid, params[])
  144. {
  145.     new ValidNumber = 1;
  146.     if(sscanf(params, "i", chosenLottoNumber[playerid]))
  147.     {
  148.         SendClientMessage(playerid, COLOR_RED, "[ERRO] /loto [numero 1-50]");
  149.         SendClientMessage(playerid, COLOR_RED, "[ERRO] O Número custa: $900");
  150.     }
  151.     else if(chosenLottoNumber[playerid] < 1 || chosenLottoNumber[playerid] > 100)
  152.     {
  153.         SendClientMessage(playerid, COLOR_RED, "[ERRO] Número deve estar entre 0 e 100");
  154.     }
  155.     else if(hasPlayedLotto[playerid] == 0)
  156.     {
  157.         if(GetPlayerMoney(playerid) < 899)
  158.         {
  159.             SendClientMessage(playerid, COLOR_RED, "[ERRO] Você não tem $900 para comprar o Número");
  160.         }
  161.         if(GetPlayerMoney(playerid) > 899)
  162.         {
  163.             for(new i; i < MAX_PLAYERS; i++)
  164.             {
  165.                 if(pLottoNumber[playerid] == pLottoNumber[i] && pLottoNumber[playerid] != pLottoNumber[playerid])
  166.                 {
  167.                     ValidNumber = 0;
  168.                 }
  169.             }
  170.             if(ValidNumber == 1)
  171.             {
  172.                 new string[256];
  173.                 format(string, sizeof(string), "[INFO] Você jogou na loteria com o numero: %i ", chosenLottoNumber[playerid]);
  174.                 SendClientMessage(playerid, COLOR_YELLOW, string);
  175.                 GivePlayerMoney(playerid, -900);
  176.                 hasPlayedLotto[playerid] = 1;
  177.                 pLottoNumber[playerid] = chosenLottoNumber[playerid];
  178.             }
  179.             if(ValidNumber == 0)
  180.             {
  181.                 SendClientMessage(playerid, COLOR_RED, "[ERRO] Esse número já foi escolhido!");
  182.             }
  183.         }
  184.     }
  185.     else if(hasPlayedLotto[playerid] == 1)
  186.     {
  187.         SendClientMessage(playerid, COLOR_RED, "[ERRO] Você já está jogando na Loteria!");
  188.     }
  189.  
  190.     return 1;
  191. }
  192.  
  193. forward lottoDrawCreate(playerid);
  194. public lottoDrawCreate(playerid)
  195. {
  196.     runLotto();
  197. }
  198.  
  199. forward lottoDrawHide(playerid);
  200. public lottoDrawHide(playerid)
  201. {
  202.     TextDrawHideForAll(lottoDrawText);
  203.     for(new i; i < MAX_PLAYERS; i++)
  204.     {
  205.         HideMenuForPlayer(lottoBacking, i);
  206.     }
  207.     KillTimer(lottoDestroy);
  208. }
  209. stock sscanf(string[], format[], {Float,_}:...)
  210. {
  211.     #if defined isnull
  212.         if (isnull(string))
  213.     #else
  214.         if (string[0] == 0 || (string[0] == 1 && string[1] == 0))
  215.     #endif
  216.         {
  217.             return format[0];
  218.         }
  219.     #pragma tabsize 4
  220.     new
  221.         formatPos = 0,
  222.         stringPos = 0,
  223.         paramPos = 2,
  224.         paramCount = numargs(),
  225.         delim = ' ';
  226.     while (string[stringPos] && string[stringPos] <= ' ')
  227.     {
  228.         stringPos++;
  229.     }
  230.     while (paramPos < paramCount && string[stringPos])
  231.     {
  232.         switch (format[formatPos++])
  233.         {
  234.             case '\0':
  235.             {
  236.                 return 0;
  237.             }
  238.             case 'i', 'd':
  239.             {
  240.                 new
  241.                     neg = 1,
  242.                     num = 0,
  243.                     ch = string[stringPos];
  244.                 if (ch == '-')
  245.                 {
  246.                     neg = -1;
  247.                     ch = string[++stringPos];
  248.                 }
  249.                 do
  250.                 {
  251.                     stringPos++;
  252.                     if ('0' <= ch <= '9')
  253.                     {
  254.                         num = (num * 10) + (ch - '0');
  255.                     }
  256.                     else
  257.                     {
  258.                         return -1;
  259.                     }
  260.                 }
  261.                 while ((ch = string[stringPos]) > ' ' && ch != delim);
  262.                 setarg(paramPos, 0, num * neg);
  263.             }
  264.             case 'h', 'x':
  265.             {
  266.                 new
  267.                     ch,
  268.                     num = 0;
  269.                 while ((ch = string[stringPos]) > ' ' && ch != delim)
  270.                 {
  271.                     switch (ch)
  272.                     {
  273.                         case 'x', 'X':
  274.                         {
  275.                             num = 0;
  276.                             continue;
  277.                         }
  278.                         case '0' .. '9':
  279.                         {
  280.                             num = (num << 4) | (ch - '0');
  281.                         }
  282.                         case 'a' .. 'f':
  283.                         {
  284.                             num = (num << 4) | (ch - ('a' - 10));
  285.                         }
  286.                         case 'A' .. 'F':
  287.                         {
  288.                             num = (num << 4) | (ch - ('A' - 10));
  289.                         }
  290.                         default:
  291.                         {
  292.                             return -1;
  293.                         }
  294.                     }
  295.                 }
  296.                 setarg(paramPos, 0, num);
  297.             }
  298.             case 'c':
  299.             {
  300.                 setarg(paramPos, 0, string[stringPos++]);
  301.             }
  302.             case 'f':
  303.             {
  304.                 setarg(paramPos, 0, _:floatstr(string[stringPos]));
  305.             }
  306.             case 'p':
  307.             {
  308.                 delim = format[formatPos++];
  309.                 continue;
  310.             }
  311.             case '\'':
  312.             {
  313.                 new
  314.                     end = formatPos - 1,
  315.                     ch;
  316.                 while ((ch = format[++end]) && ch != '\'') {}
  317.                 if (!ch)
  318.                 {
  319.                     return -1;
  320.                 }
  321.                 format[end] = '\0';
  322.                 if ((ch = strfind(string, format[formatPos], false, stringPos)) == -1)
  323.                 {
  324.                     if (format[end + 1])
  325.                     {
  326.                         return -1;
  327.                     }
  328.                     return 0;
  329.                 }
  330.                 format[end] = '\'';
  331.                 stringPos = ch + (end - formatPos);
  332.                 formatPos = end + 1;
  333.             }
  334.             case 'u':
  335.             {
  336.                 new
  337.                     end = stringPos - 1,
  338.                     id = 0,
  339.                     bool:num = true,
  340.                     ch;
  341.                 while ((ch = string[++end]) && ch != delim)
  342.                 {
  343.                     if (num)
  344.                     {
  345.                         if ('0' <= ch <= '9')
  346.                         {
  347.                             id = (id * 10) + (ch - '0');
  348.                         }
  349.                         else
  350.                         {
  351.                             num = false;
  352.                         }
  353.                     }
  354.                 }
  355.                 if (num && IsPlayerConnected(id))
  356.                 {
  357.                     setarg(paramPos, 0, id);
  358.                 }
  359.                 else
  360.                 {
  361.                     #if !defined foreach
  362.                         #define foreach(%1,%2) for (new %2 = 0; %2 < MAX_PLAYERS; %2++) if (IsPlayerConnected(%2))
  363.                         #define __SSCANF_FOREACH__
  364.                     #endif
  365.                     string[end] = '\0';
  366.                     num = false;
  367.                     new
  368.                         name[MAX_PLAYER_NAME];
  369.                     id = end - stringPos;
  370.                     foreach (Player, playerid)
  371.                     {
  372.                         GetPlayerName(playerid, name, sizeof (name));
  373.                         if (!strcmp(name, string[stringPos], true, id))
  374.                         {
  375.                             setarg(paramPos, 0, playerid);
  376.                             num = true;
  377.                             break;
  378.                         }
  379.                     }
  380.                     if (!num)
  381.                     {
  382.                         setarg(paramPos, 0, INVALID_PLAYER_ID);
  383.                     }
  384.                     string[end] = ch;
  385.                     #if defined __SSCANF_FOREACH__
  386.                         #undef foreach
  387.                         #undef __SSCANF_FOREACH__
  388.                     #endif
  389.                 }
  390.                 stringPos = end;
  391.             }
  392.             case 's', 'z':
  393.             {
  394.                 new
  395.                     i = 0,
  396.                     ch;
  397.                 if (format[formatPos])
  398.                 {
  399.                     while ((ch = string[stringPos++]) && ch != delim)
  400.                     {
  401.                         setarg(paramPos, i++, ch);
  402.                     }
  403.                     if (!i)
  404.                     {
  405.                         return -1;
  406.                     }
  407.                 }
  408.                 else
  409.                 {
  410.                     while ((ch = string[stringPos++]))
  411.                     {
  412.                         setarg(paramPos, i++, ch);
  413.                     }
  414.                 }
  415.                 stringPos--;
  416.                 setarg(paramPos, i, '\0');
  417.             }
  418.             default:
  419.             {
  420.                 continue;
  421.             }
  422.         }
  423.         while (string[stringPos] && string[stringPos] != delim && string[stringPos] > ' ')
  424.         {
  425.             stringPos++;
  426.         }
  427.         while (string[stringPos] && (string[stringPos] == delim || string[stringPos] <= ' '))
  428.         {
  429.             stringPos++;
  430.         }
  431.         paramPos++;
  432.     }
  433.     do
  434.     {
  435.         if ((delim = format[formatPos++]) > ' ')
  436.         {
  437.             if (delim == '\'')
  438.             {
  439.                 while ((delim = format[formatPos++]) && delim != '\'') {}
  440.             }
  441.             else if (delim != 'z')
  442.             {
  443.                 return delim;
  444.             }
  445.         }
  446.     }
  447.     while (delim > ' ');
  448.     return 0;
  449. }
Advertisement
Add Comment
Please, Sign In to add comment