Advertisement
ErikSon_

Lottosystem by ErikSon

Nov 25th, 2014
219
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 11.01 KB | None | 0 0
  1. //Incldues
  2. #include <a_samp>
  3. #include <dini>
  4. #include <ocmd>
  5.  
  6. //Farben
  7. #define Rot     0xFF0000FF
  8. #define Blau    0x0091FFFF
  9. #define DBlau   0x0023FFFF
  10.  
  11. //Sonstiges
  12. forward Lottotimer();
  13. #define lottostart      30              // In wie vielen Minuten Lotto immer starten soll
  14. #define PLAYERS         5               // Slots des Servers
  15. #define Lottotk         50              // Kosten eines Lottotickets
  16. #define lstartgeld      5000            // Wieviel Geld am Anfang in der Lottokasse ist
  17. #define lpgeld          5000            // Wieviel Geld zu dem Jackpot dazu gegeben werden soll, wenn keiner das Lottospiel gewinnt
  18. #define max_lzahl       50              // Maximale Lottozahl die genommen werden kann
  19. new LottoZahl[PLAYERS],
  20.     PlayerText:lTD[PLAYERS];
  21.    
  22. enum EL{
  23.     lJackpot,
  24.     lTeilnehmer,
  25.     lZeit,
  26.     Text:lBox
  27. }
  28. static Lotto[EL];
  29.  
  30. ocmd:geld(playerid)return GivePlayerMoney(playerid,5000);
  31.  
  32. ////////////////////////////////////////////////////////////////////////
  33.  
  34. public OnFilterScriptInit(){
  35.     print("\n--------------------------------------");
  36.     print(" Lottosystem by ErikSon");
  37.     print("--------------------------------------\n");
  38.     SetTimer("Lottotimer",1000,true);
  39.     new Lottodatei[16]; format(Lottodatei,16,"/Lotto.ini");
  40.     if(dini_Exists(Lottodatei))Lotto[lJackpot] = dini_Int(Lottodatei,"Gewinn");
  41.     else if(!dini_Exists(Lottodatei)){
  42.         dini_Create(Lottodatei);
  43.         dini_IntSet(Lottodatei,"Gewinn",lstartgeld);
  44.         Lotto[lJackpot] = lstartgeld;
  45.     }
  46.     Lotto[lBox] = TextDrawCreate(370.000000, 10.000000, "~n~");
  47.     TextDrawBackgroundColor(Lotto[lBox], 255);
  48.     TextDrawFont(Lotto[lBox], 1);
  49.     TextDrawLetterSize(Lotto[lBox], 0.500000, 6.499999);
  50.     TextDrawColor(Lotto[lBox], 35071);
  51.     TextDrawSetOutline(Lotto[lBox], 0);
  52.     TextDrawSetProportional(Lotto[lBox], 1);
  53.     TextDrawSetShadow(Lotto[lBox], 1);
  54.     TextDrawUseBox(Lotto[lBox], 1);
  55.     TextDrawBoxColor(Lotto[lBox], 255);
  56.     TextDrawTextSize(Lotto[lBox], 486.000000, 0.000000);
  57.     TextDrawSetSelectable(Lotto[lBox], 0);
  58.  
  59.     new str[128];
  60.     for(new i = 0; i<PLAYERS; i++){
  61.         format(str,sizeof(str),"Lotto!~n~Start: %i m / %i s~n~Jackpot: %i$~n~Teilnehmer: %i~n~Deine Lottozahl: %i",(lottostart - (Lotto[lZeit] / 60) -1),(lottostart - (Lotto[lZeit] % 60) +30),
  62.         Lotto[lJackpot],Lotto[lTeilnehmer],LottoZahl[i]);
  63.         lTD[i] = CreatePlayerTextDraw(i,374.000000, 14.000000, str);
  64.         PlayerTextDrawBackgroundColor(i,lTD[i], 255);
  65.         PlayerTextDrawFont(i,lTD[i], 1);
  66.         PlayerTextDrawLetterSize(i,lTD[i], 0.300000, 1.000000);
  67.         PlayerTextDrawColor(i,lTD[i], -1);
  68.         PlayerTextDrawSetOutline(i,lTD[i],0);
  69.         PlayerTextDrawSetProportional(i,lTD[i], 1);
  70.         PlayerTextDrawSetShadow(i,lTD[i], 1);
  71.         PlayerTextDrawSetSelectable(i,lTD[i], 0);
  72.         if(IsPlayerConnected(i)){
  73.             LottoZahl[i] = GetPVarInt(i,"LottoZahl");
  74.             if(LottoZahl[i] > 0)Lotto[lTeilnehmer] ++;
  75.             TextDrawShowForPlayer(i,Lotto[lBox]),
  76.             PlayerTextDrawShow(i,lTD[i]);
  77.         }
  78.     }
  79.     return 1;
  80. }
  81. public OnFilterScriptExit(){
  82.     new Lottodatei[16]; format(Lottodatei,16,"/Lotto.ini");
  83.     dini_IntSet(Lottodatei,"Gewinn",Lotto[lJackpot]);
  84.    
  85.     for(new i = 0; i<PLAYERS; i++){
  86.         SetPVarInt(i,"LottoZahl",LottoZahl[i]);
  87.         TextDrawHideForPlayer(i,Lotto[lBox]),
  88.         PlayerTextDrawHide(i,lTD[i]);
  89.     }
  90.     return 1;
  91. }
  92.  
  93. public OnPlayerConnect(playerid){
  94.     LottoZahl[playerid] = GetPVarInt(playerid,"LottoZahl");
  95.     TextDrawShowForPlayer(playerid,Lotto[lBox]),
  96.     PlayerTextDrawShow(playerid,lTD[playerid]);
  97.     if(LottoZahl[playerid] > 0)Lotto[lTeilnehmer] ++;
  98.     return 1;
  99. }
  100. public OnPlayerDisconnect(playerid, reason){
  101.     SetPVarInt(playerid,"LottoZahl",LottoZahl[playerid]);
  102.     if(LottoZahl[playerid] > 0)Lotto[lTeilnehmer] --;
  103.     PlayerTextDrawHide(playerid,lTD[playerid]),
  104.     TextDrawHideForPlayer(playerid,Lotto[lBox]);
  105.     return 1;
  106. }
  107.  
  108. stock Name(playerid){
  109.    new name[MAX_PLAYER_NAME];
  110.    GetPlayerName(playerid,name,sizeof(name));
  111.    return name;
  112. }
  113.  
  114. public Lottotimer(){
  115.     Lotto[lZeit] ++;
  116.     if((Lotto[lZeit] / 60) >= lottostart){
  117.         new lzahl = random(max_lzahl) +1, bool:won, string[128];
  118.         for(new i = 0; i<PLAYERS; i++){
  119.             if(!IsPlayerConnected(i))continue;
  120.             if(LottoZahl[i] < 1)continue;
  121.             if(LottoZahl[i] == lzahl){
  122.                 won = true;
  123.                 format(string,128,"Spieler %s hat das Lottospiel gewonnen und $%d gewonnen! (Lottozahl: %d)",Name(i),Lotto[lJackpot],lzahl);
  124.                 SendClientMessageToAll(Blau,string);
  125.                 GivePlayerMoney(i,Lotto[lJackpot]);
  126.             }
  127.             LottoZahl[i] = 0;
  128.         }
  129.         if(!won){
  130.             format(string,128,"Diesmal hat niemand das Lottospiel gewonnen. (Lottozahl: %d)",lzahl);
  131.             SendClientMessageToAll(Rot,string);
  132.             Lotto[lJackpot] += lpgeld;
  133.             format(string,128,"Der Jackpot steigt auf $%d.",Lotto[lJackpot]);
  134.             SendClientMessageToAll(-1,string);
  135.         }
  136.         else if(won){
  137.             Lotto[lJackpot] = lstartgeld;
  138.             format(string,128,"Der Jackpot steht nun auf $%d.",lstartgeld);
  139.             SendClientMessageToAll(-1,string);
  140.         }
  141.         Lotto[lZeit] = 0;
  142.         Lotto[lTeilnehmer] = 0;
  143.     }
  144.     new str[128];
  145.     for(new i = 0; i<PLAYERS; i++){
  146.         if(!IsPlayerConnected(i))continue;
  147.         format(str,sizeof(str),"Lotto!~n~Start: %i m / %i s~n~Jackpot: %i$~n~Teilnehmer: %i~n~Deine Lottozahl: %i",(lottostart - (Lotto[lZeit] / 60) -1),(lottostart - (Lotto[lZeit] % 60) +30),
  148.         Lotto[lJackpot],Lotto[lTeilnehmer],LottoZahl[i]);
  149.         PlayerTextDrawSetString(i,lTD[i],str);
  150.     }
  151.     return 1;
  152. }
  153.  
  154. ocmd:lotto(playerid,params[]){
  155.     new lz,string[128];
  156.     if(LottoZahl[playerid] > 0)return SendClientMessage(playerid,Rot,"*Du hast bereits ein Lottoticket gekauft!");
  157.     if(GetPlayerMoney(playerid) < Lottotk)return format(string,64,"*Du hast nicht genug Geld! ($%d)",Lottotk),SendClientMessage(playerid,Rot,string);
  158.     if(sscanf(params,"d",lz))return format(string,64,"*Benutze: /lotto [Zahl (1-%d)",max_lzahl),SendClientMessage(playerid,Rot,string);
  159.     if(lz > max_lzahl || lz < 1)return format(string,64,"*Die Lottozahl muss mindestens 1 und höchstens %d sein!",max_lzahl),SendClientMessage(playerid,Rot,string);
  160.     LottoZahl[playerid] = lz;
  161.     Lotto[lTeilnehmer] ++;
  162.     return GivePlayerMoney(playerid,-Lottotk);
  163. }
  164.  
  165. ocmd:startelotto(playerid){
  166.     new string[64];
  167.     if(!IsPlayerAdmin(playerid))return 1;
  168.     format(string,64,"Admin %s hat eine extra Lottorunde gestartet!",Name(playerid));
  169.     SendClientMessageToAll(Blau,string);
  170.     return Lotto[lZeit] = (lottostart*60);
  171. }
  172.  
  173. ocmd:make(playerid){
  174.     return Lotto[lZeit] = 1731;
  175. }
  176. ocmd:makeit(playerid){
  177.     return Lotto[lZeit] = 1790;
  178. }
  179.  
  180. ocmd:clear(){
  181.     for(new i = 0; i<123; i++){
  182.         SendClientMessageToAll(-1,"");
  183.     }
  184.     return 1;
  185. }
  186.      
  187.      
  188. stock sscanf(string[], format[], {Float,_}:...)
  189. {
  190.     #if defined isnull
  191.         if (isnull(string))
  192.     #else
  193.         if (string[0] == 0 || (string[0] == 1 && string[1] == 0))
  194.     #endif
  195.         {
  196.             return format[0];
  197.         }
  198.     #pragma tabsize 4
  199.     new
  200.         formatPos = 0,
  201.         stringPos = 0,
  202.         paramPos = 2,
  203.         paramCount = numargs(),
  204.         delim = ' ';
  205.     while (string[stringPos] && string[stringPos] <= ' ')
  206.     {
  207.         stringPos++;
  208.     }
  209.     while (paramPos < paramCount && string[stringPos])
  210.     {
  211.         switch (format[formatPos++])
  212.         {
  213.             case '\0':
  214.             {
  215.                 return 0;
  216.             }
  217.             case 'i', 'd':
  218.             {
  219.                 new
  220.                     neg = 1,
  221.                     num = 0,
  222.                     ch = string[stringPos];
  223.                 if (ch == '-')
  224.                 {
  225.                     neg = -1;
  226.                     ch = string[++stringPos];
  227.                 }
  228.                 do
  229.                 {
  230.                     stringPos++;
  231.                     if ('0' <= ch <= '9')
  232.                     {
  233.                         num = (num * 10) + (ch - '0');
  234.                     }
  235.                     else
  236.                     {
  237.                         return -1;
  238.                     }
  239.                 }
  240.                 while ((ch = string[stringPos]) > ' ' && ch != delim);
  241.                 setarg(paramPos, 0, num * neg);
  242.             }
  243.             case 'h', 'x':
  244.             {
  245.                 new
  246.                     num = 0,
  247.                     ch = string[stringPos];
  248.                 do
  249.                 {
  250.                     stringPos++;
  251.                     switch (ch)
  252.                     {
  253.                         case 'x', 'X':
  254.                         {
  255.                             num = 0;
  256.                             continue;
  257.                         }
  258.                         case '0' .. '9':
  259.                         {
  260.                             num = (num << 4) | (ch - '0');
  261.                         }
  262.                         case 'a' .. 'f':
  263.                         {
  264.                             num = (num << 4) | (ch - ('a' - 10));
  265.                         }
  266.                         case 'A' .. 'F':
  267.                         {
  268.                             num = (num << 4) | (ch - ('A' - 10));
  269.                         }
  270.                         default:
  271.                         {
  272.                             return -1;
  273.                         }
  274.                     }
  275.                 }
  276.                 while ((ch = string[stringPos]) > ' ' && ch != delim);
  277.                 setarg(paramPos, 0, num);
  278.             }
  279.             case 'c':
  280.             {
  281.                 setarg(paramPos, 0, string[stringPos++]);
  282.             }
  283.             case 'f':
  284.             {
  285.  
  286.                 new changestr[16], changepos = 0, strpos = stringPos;    
  287.                 while(changepos < 16 && string[strpos] && string[strpos] != delim)
  288.                 {
  289.                     changestr[changepos++] = string[strpos++];
  290.                     }
  291.                 changestr[changepos] = '\0';
  292.                 setarg(paramPos,0,_:floatstr(changestr));
  293.             }
  294.             case 'p':
  295.             {
  296.                 delim = format[formatPos++];
  297.                 continue;
  298.             }
  299.             case '\'':
  300.             {
  301.                 new
  302.                     end = formatPos - 1,
  303.                     ch;
  304.                 while ((ch = format[++end]) && ch != '\'') {}
  305.                 if (!ch)
  306.                 {
  307.                     return -1;
  308.                 }
  309.                 format[end] = '\0';
  310.                 if ((ch = strfind(string, format[formatPos], false, stringPos)) == -1)
  311.                 {
  312.                     if (format[end + 1])
  313.                     {
  314.                         return -1;
  315.                     }
  316.                     return 0;
  317.                 }
  318.                 format[end] = '\'';
  319.                 stringPos = ch + (end - formatPos);
  320.                 formatPos = end + 1;
  321.             }
  322.             case 'u':
  323.             {
  324.                 new
  325.                     end = stringPos - 1,
  326.                     id = 0,
  327.                     bool:num = true,
  328.                     ch;
  329.                 while ((ch = string[++end]) && ch != delim)
  330.                 {
  331.                     if (num)
  332.                     {
  333.                         if ('0' <= ch <= '9')
  334.                         {
  335.                             id = (id * 10) + (ch - '0');
  336.                         }
  337.                         else
  338.                         {
  339.                             num = false;
  340.                         }
  341.                     }
  342.                 }
  343.                 if (num && IsPlayerConnected(id))
  344.                 {
  345.                     setarg(paramPos, 0, id);
  346.                 }
  347.                 else
  348.                 {
  349.                     #if !defined foreach
  350.                         #define foreach(%1,%2) for (new %2 = 0; %2 < MAX_PLAYERS; %2++) if (IsPlayerConnected(%2))
  351.                         #define __SSCANF_FOREACH__
  352.                     #endif
  353.                     string[end] = '\0';
  354.                     num = false;
  355.                     new
  356.                         name[MAX_PLAYER_NAME];
  357.                     id = end - stringPos;
  358.                     foreach (Player, playerid)
  359.                     {
  360.                         GetPlayerName(playerid, name, sizeof (name));
  361.                         if (!strcmp(name, string[stringPos], true, id))
  362.                         {
  363.                             setarg(paramPos, 0, playerid);
  364.                             num = true;
  365.                             break;
  366.                         }
  367.                     }
  368.                     if (!num)
  369.                     {
  370.                         setarg(paramPos, 0, INVALID_PLAYER_ID);
  371.                     }
  372.                     string[end] = ch;
  373.                     #if defined __SSCANF_FOREACH__
  374.                         #undef foreach
  375.                         #undef __SSCANF_FOREACH__
  376.                     #endif
  377.                 }
  378.                 stringPos = end;
  379.             }
  380.             case 's', 'z':
  381.             {
  382.                 new
  383.                     i = 0,
  384.                     ch;
  385.                 if (format[formatPos])
  386.                 {
  387.                     while ((ch = string[stringPos++]) && ch != delim)
  388.                     {
  389.                         setarg(paramPos, i++, ch);
  390.                     }
  391.                     if (!i)
  392.                     {
  393.                         return -1;
  394.                     }
  395.                 }
  396.                 else
  397.                 {
  398.                     while ((ch = string[stringPos++]))
  399.                     {
  400.                         setarg(paramPos, i++, ch);
  401.                     }
  402.                 }
  403.                 stringPos--;
  404.                 setarg(paramPos, i, '\0');
  405.             }
  406.             default:
  407.             {
  408.                 continue;
  409.             }
  410.         }
  411.         while (string[stringPos] && string[stringPos] != delim && string[stringPos] > ' ')
  412.         {
  413.             stringPos++;
  414.         }
  415.         while (string[stringPos] && (string[stringPos] == delim || string[stringPos] <= ' '))
  416.         {
  417.             stringPos++;
  418.         }
  419.         paramPos++;
  420.     }
  421.     do
  422.     {
  423.         if ((delim = format[formatPos++]) > ' ')
  424.         {
  425.             if (delim == '\'')
  426.             {
  427.                 while ((delim = format[formatPos++]) && delim != '\'') {}
  428.             }
  429.             else if (delim != 'z')
  430.             {
  431.                 return delim;
  432.             }
  433.         }
  434.     }
  435.     while (delim > ' ');
  436.     return 0;
  437. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement