Guest User

Lottosystem

a guest
Nov 24th, 2013
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 9.24 KB | None | 0 0
  1.  
  2. //Incldues
  3. #include <a_samp>
  4. #include <dini>
  5. #include <ocmd>
  6.  
  7.  
  8. //Farben
  9. #define Rot     0xFF0000FF
  10. #define Blau    0x0091FFFF
  11. #define DBlau   0x0023FFFF
  12.  
  13.  
  14. //New's
  15. new LottoZahl[MAX_PLAYERS];
  16.  
  17. //Sonstiges
  18. forward Lottotimer();
  19. forward Lottotimer2();
  20. #define lottostart  30      // In wievielen Minuten Lotto immer starten soll ( + lottostart2 )
  21. #define lottostart2 1       // In wievielen Minuten Lotto starten soll nach der Ankündigung
  22. #define PLAYERS     5       // Maximale Playeranzahl auf dem Server die durchgegangen werden soll ( bitte festlegen! -> 50 Slot Server = PLAYERS 50 )
  23. #define Lottotk     50      // Kosten eines Lottotickets festlegen
  24. #define lstartgeld  5000    // Wieviel Geld am Anfang in der Lottokasse ist
  25. #define lpgeld      5000    // Wieviel Geld zu dem Lottogewinn dazu gegeben werden soll, wenn keiner das Lottospiel gewinnt
  26. #define max_lzahl   50      // Maximale Lottozahl die genommen werden kann
  27.  
  28.  
  29. ////////////////////////////////////////////////////////////////////////
  30.  
  31. public OnFilterScriptInit()
  32. {
  33.     print("\n--------------------------------------");
  34.     print("\t\tLottosystem");
  35.     print("--------------------------------------\n");
  36.     SetTimer("Lottotimer",888*60*lottostart,false);
  37.     new Lottodatei[64];
  38.     format(Lottodatei,64,"/Lotto.ini");
  39.     if(!dini_Exists(Lottodatei))
  40.     {
  41.         dini_Create(Lottodatei);
  42.         dini_IntSet(Lottodatei,"Gewinn",lstartgeld);
  43.     }
  44.     return 1;
  45. }
  46.  
  47. public OnFilterScriptExit()
  48. {
  49.     return 1;
  50. }
  51.  
  52. //////
  53.  
  54. stock Name(playerid)
  55. {
  56.    new name[MAX_PLAYERS];
  57.    GetPlayerName(playerid,name,sizeof(name));
  58.    return name;
  59. }
  60.  
  61. public Lottotimer()
  62. {
  63.     new Lottodatei[64],string[128];
  64.     format(Lottodatei,64,"/Lotto.ini");
  65.    
  66.     SetTimer("Lottotimer2",888*60*lottostart2,false);
  67.     SendClientMessageToAll(DBlau,"---------------> LOTTO <---------------");
  68.     format(string,128,"Die nächste Lottorunde startet in %d Minuten.",lottostart2);
  69.     SendClientMessageToAll(Blau,string);
  70.     SendClientMessageToAll(Blau,"Tippe /lotto [Zahl] um dir ein Lottoticket zu kaufen.");
  71.     format(string,128,"Es sind $%d zu gewinnen!!! Ein Lottoticket kostet $%d.",dini_Int(Lottodatei,"Gewinn"),Lottotk);
  72.     SendClientMessageToAll(Blau,string);
  73.     SendClientMessageToAll(DBlau,"---------------> LOTTO <---------------");
  74.     return 1;
  75. }
  76.  
  77. public Lottotimer2()
  78. {
  79.     new Lottodatei[64],string[128];
  80.     format(Lottodatei,64,"/Lotto.ini");
  81.     new lzahl = random(max_lzahl) +1;
  82.    
  83.     SetTimer("Lottotimer",888*60*lottostart,false);
  84.     SendClientMessageToAll(DBlau,"---------------> LOTTO <---------------");
  85.     format(string,128,"Die Lottozahl ist ... -> %d <- !",lzahl);
  86.     SendClientMessageToAll(Blau,string);
  87.     for(new i = 0; i<PLAYERS; i++)
  88.     {
  89.         if(!IsPlayerConnected(i))continue;
  90.         if(LottoZahl[i] < 1)continue;
  91.         if(LottoZahl[i] != lzahl)
  92.         {
  93.             SendClientMessageToAll(Blau,"Diesmal hat niemand das Lottospiel gewonnen.");
  94.             format(string,128,"Der Lottogewinn steigt auf $%d.",(dini_Int(Lottodatei,"Gewinn") + lpgeld));
  95.             SendClientMessageToAll(Blau,string);
  96.             dini_IntSet(Lottodatei,"Gewinn",dini_Int(Lottodatei,"Gewinn") + lpgeld);
  97.         }
  98.         else if(LottoZahl[i] == lzahl)
  99.         {
  100.             format(string,128,"Spieler %s hat das Lottospiel gewonnen und $%d gewonnen!",Name(i),dini_Int(Lottodatei,"Gewinn"));
  101.             SendClientMessageToAll(Blau,string);
  102.             format(string,128,"Der Lottogewinn sinkt auf $%d.",lstartgeld);
  103.             SendClientMessageToAll(Blau,string);
  104.             GivePlayerMoney(i,dini_Int(Lottodatei,"Gewinn"));
  105.             dini_IntSet(Lottodatei,"Gewinn",lstartgeld);
  106.         }
  107.         LottoZahl[i] = 0;
  108.         lzahl = 1;
  109.     }
  110.     SendClientMessageToAll(DBlau,"---------------> LOTTO <---------------");
  111.     return 1;
  112. }
  113.  
  114. ocmd:lotto(playerid,params[])
  115. {
  116.     new lz,string[128];
  117.    
  118.     if(LottoZahl[playerid] > 0)return SendClientMessage(playerid,Rot,"*Du hast bereits eine Lottozahl gezogen!");
  119.     format(string,128,"*Du hast nicht genug Geld! ($%d)",Lottotk);
  120.     if(GetPlayerMoney(playerid) < Lottotk)return SendClientMessage(playerid,Rot,string);
  121.     format(string,128,"*Benutze: /lotto [Zahl (1-%d)",max_lzahl);
  122.     if(sscanf(params,"d",lz))return SendClientMessage(playerid,Rot,string);
  123.     format(string,128,"*Die Lottozahl muss mindestens 1 und höchstens %d sein!",max_lzahl);
  124.     if(lz > max_lzahl || lz < 1)return SendClientMessage(playerid,Rot,string);
  125.     LottoZahl[playerid] = lz;
  126.     GivePlayerMoney(playerid,-Lottotk);
  127.     format(string,128,"*Du hast dir ein Lottoticket mit der Nummer %d gekauft.",lz);
  128.     SendClientMessage(playerid,Blau,string);
  129.     return 1;
  130. }
  131.  
  132. ocmd:startelotto(playerid)
  133. {
  134.     new string[128];
  135.    
  136.     if(!IsPlayerAdmin(playerid))return 1;
  137.     format(string,128,"Admin %s hat eine extra Lottorunde gestartet!",Name(playerid));
  138.     SendClientMessageToAll(Blau,string);
  139.     Lottotimer();
  140.     return 1;
  141. }
  142.  
  143.  
  144. //sscanf
  145. stock sscanf(string[], format[], {Float,_}:...)
  146. {
  147.     #if defined isnull
  148.         if (isnull(string))
  149.     #else
  150.         if (string[0] == 0 || (string[0] == 1 && string[1] == 0))
  151.     #endif
  152.         {
  153.             return format[0];
  154.         }
  155.     #pragma tabsize 4
  156.     new
  157.         formatPos = 0,
  158.         stringPos = 0,
  159.         paramPos = 2,
  160.         paramCount = numargs(),
  161.         delim = ' ';
  162.     while (string[stringPos] && string[stringPos] <= ' ')
  163.     {
  164.         stringPos++;
  165.     }
  166.     while (paramPos < paramCount && string[stringPos])
  167.     {
  168.         switch (format[formatPos++])
  169.         {
  170.             case '\0':
  171.             {
  172.                 return 0;
  173.             }
  174.             case 'i', 'd':
  175.             {
  176.                 new
  177.                     neg = 1,
  178.                     num = 0,
  179.                     ch = string[stringPos];
  180.                 if (ch == '-')
  181.                 {
  182.                     neg = -1;
  183.                     ch = string[++stringPos];
  184.                 }
  185.                 do
  186.                 {
  187.                     stringPos++;
  188.                     if ('0' <= ch <= '9')
  189.                     {
  190.                         num = (num * 10) + (ch - '0');
  191.                     }
  192.                     else
  193.                     {
  194.                         return -1;
  195.                     }
  196.                 }
  197.                 while ((ch = string[stringPos]) > ' ' && ch != delim);
  198.                 setarg(paramPos, 0, num * neg);
  199.             }
  200.             case 'h', 'x':
  201.             {
  202.                 new
  203.                     num = 0,
  204.                     ch = string[stringPos];
  205.                 do
  206.                 {
  207.                     stringPos++;
  208.                     switch (ch)
  209.                     {
  210.                         case 'x', 'X':
  211.                         {
  212.                             num = 0;
  213.                             continue;
  214.                         }
  215.                         case '0' .. '9':
  216.                         {
  217.                             num = (num << 4) | (ch - '0');
  218.                         }
  219.                         case 'a' .. 'f':
  220.                         {
  221.                             num = (num << 4) | (ch - ('a' - 10));
  222.                         }
  223.                         case 'A' .. 'F':
  224.                         {
  225.                             num = (num << 4) | (ch - ('A' - 10));
  226.                         }
  227.                         default:
  228.                         {
  229.                             return -1;
  230.                         }
  231.                     }
  232.                 }
  233.                 while ((ch = string[stringPos]) > ' ' && ch != delim);
  234.                 setarg(paramPos, 0, num);
  235.             }
  236.             case 'c':
  237.             {
  238.                 setarg(paramPos, 0, string[stringPos++]);
  239.             }
  240.             case 'f':
  241.             {
  242.  
  243.                 new changestr[16], changepos = 0, strpos = stringPos;    
  244.                 while(changepos < 16 && string[strpos] && string[strpos] != delim)
  245.                 {
  246.                     changestr[changepos++] = string[strpos++];
  247.                     }
  248.                 changestr[changepos] = '\0';
  249.                 setarg(paramPos,0,_:floatstr(changestr));
  250.             }
  251.             case 'p':
  252.             {
  253.                 delim = format[formatPos++];
  254.                 continue;
  255.             }
  256.             case '\'':
  257.             {
  258.                 new
  259.                     end = formatPos - 1,
  260.                     ch;
  261.                 while ((ch = format[++end]) && ch != '\'') {}
  262.                 if (!ch)
  263.                 {
  264.                     return -1;
  265.                 }
  266.                 format[end] = '\0';
  267.                 if ((ch = strfind(string, format[formatPos], false, stringPos)) == -1)
  268.                 {
  269.                     if (format[end + 1])
  270.                     {
  271.                         return -1;
  272.                     }
  273.                     return 0;
  274.                 }
  275.                 format[end] = '\'';
  276.                 stringPos = ch + (end - formatPos);
  277.                 formatPos = end + 1;
  278.             }
  279.             case 'u':
  280.             {
  281.                 new
  282.                     end = stringPos - 1,
  283.                     id = 0,
  284.                     bool:num = true,
  285.                     ch;
  286.                 while ((ch = string[++end]) && ch != delim)
  287.                 {
  288.                     if (num)
  289.                     {
  290.                         if ('0' <= ch <= '9')
  291.                         {
  292.                             id = (id * 10) + (ch - '0');
  293.                         }
  294.                         else
  295.                         {
  296.                             num = false;
  297.                         }
  298.                     }
  299.                 }
  300.                 if (num && IsPlayerConnected(id))
  301.                 {
  302.                     setarg(paramPos, 0, id);
  303.                 }
  304.                 else
  305.                 {
  306.                     #if !defined foreach
  307.                         #define foreach(%1,%2) for (new %2 = 0; %2 < MAX_PLAYERS; %2++) if (IsPlayerConnected(%2))
  308.                         #define __SSCANF_FOREACH__
  309.                     #endif
  310.                     string[end] = '\0';
  311.                     num = false;
  312.                     new
  313.                         name[MAX_PLAYER_NAME];
  314.                     id = end - stringPos;
  315.                     foreach (Player, playerid)
  316.                     {
  317.                         GetPlayerName(playerid, name, sizeof (name));
  318.                         if (!strcmp(name, string[stringPos], true, id))
  319.                         {
  320.                             setarg(paramPos, 0, playerid);
  321.                             num = true;
  322.                             break;
  323.                         }
  324.                     }
  325.                     if (!num)
  326.                     {
  327.                         setarg(paramPos, 0, INVALID_PLAYER_ID);
  328.                     }
  329.                     string[end] = ch;
  330.                     #if defined __SSCANF_FOREACH__
  331.                         #undef foreach
  332.                         #undef __SSCANF_FOREACH__
  333.                     #endif
  334.                 }
  335.                 stringPos = end;
  336.             }
  337.             case 's', 'z':
  338.             {
  339.                 new
  340.                     i = 0,
  341.                     ch;
  342.                 if (format[formatPos])
  343.                 {
  344.                     while ((ch = string[stringPos++]) && ch != delim)
  345.                     {
  346.                         setarg(paramPos, i++, ch);
  347.                     }
  348.                     if (!i)
  349.                     {
  350.                         return -1;
  351.                     }
  352.                 }
  353.                 else
  354.                 {
  355.                     while ((ch = string[stringPos++]))
  356.                     {
  357.                         setarg(paramPos, i++, ch);
  358.                     }
  359.                 }
  360.                 stringPos--;
  361.                 setarg(paramPos, i, '\0');
  362.             }
  363.             default:
  364.             {
  365.                 continue;
  366.             }
  367.         }
  368.         while (string[stringPos] && string[stringPos] != delim && string[stringPos] > ' ')
  369.         {
  370.             stringPos++;
  371.         }
  372.         while (string[stringPos] && (string[stringPos] == delim || string[stringPos] <= ' '))
  373.         {
  374.             stringPos++;
  375.         }
  376.         paramPos++;
  377.     }
  378.     do
  379.     {
  380.         if ((delim = format[formatPos++]) > ' ')
  381.         {
  382.             if (delim == '\'')
  383.             {
  384.                 while ((delim = format[formatPos++]) && delim != '\'') {}
  385.             }
  386.             else if (delim != 'z')
  387.             {
  388.                 return delim;
  389.             }
  390.         }
  391.     }
  392.     while (delim > ' ');
  393.     return 0;
  394. }
Advertisement
Add Comment
Please, Sign In to add comment