Guest User

Zinglish

a guest
Feb 18th, 2010
565
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 9.51 KB | None | 0 0
  1. /*
  2. *  ________                       ___                 __
  3. * /\_____  \  __                 /\_ \    __         /\ \
  4. * \/____//'/'/\_\    ___      __ \//\ \  /\_\    ____\ \ \___
  5. *      //'/' \/\ \ /' _ `\  /'_ `\ \ \ \ \/\ \  /',__\\ \  _ `\
  6. *     //'/'___\ \ \/\ \/\ \/\ \Z\ \ \_\ \_\ \ \/\__, `\\ \ \ \ \
  7. *     /\_______\ \_\ \_\ \_\ \____ \/\____\\ \_\/\____/ \ \_\ \_\
  8. *     \/_______/\/_/\/_/\/_/\/___Z\ \/____/ \/_/\/___/   \/_/\/_/
  9. *                             /\____/
  10. *                             \_/__/
  11. */
  12.  
  13. /*
  14. *                    ________   ____     ____           _         __
  15. *                   /\_____  \ /\  _`\  /\  _`\       /' \      /'__`\
  16. *                   \/____//'/'\ \ \B\ \\ \ \/\_\    /\_, \    /\_\3\ \
  17. *                        //'/'  \ \  _ <'\ \ \/_/_   \/_/\ \   \/_/_\_<_
  18. *                       //'/'___ \ \ \B\ \\ \ \C\ \     \ \ \  __/\ \3\ \
  19. *                      /\_______\ \ \____/ \ \____/      \ \_\/\_\ \____/
  20. *                      \/_______/  \/___/   \/___/        \/_/\/_/\/___/
  21. *                      
  22. *                                               Zinglish
  23. *                                                  Basic Clock version 1.3
  24. *
  25. */
  26.  
  27. #define BLACK 0x000000FF
  28. #define WHITE 0xFFFFFFFF
  29. #define COLOR_RED 0xE21F1FFF
  30.  
  31. #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
  32.  
  33. #include <a_samp>
  34.  
  35. new Text:TextZBC;
  36. new TextZBCHours, TextZBCHoursString[56];
  37. new TextZBCMinutes, TextZBCMinutesString[56];
  38. stock InitializeZBC()
  39. {
  40.     TextZBC = TextDrawCreate(546.000000,22.000000,"--:--");
  41.     TextDrawAlignment(TextZBC,0);
  42.     TextDrawBackgroundColor(TextZBC,BLACK);
  43.     TextDrawFont(TextZBC,3);
  44.     TextDrawLetterSize(TextZBC,0.635,2.4);
  45.     TextDrawColor(TextZBC,WHITE);
  46.     TextDrawSetOutline(TextZBC,1);
  47.     TextDrawSetProportional(TextZBC,1);
  48.     TextDrawSetShadow(TextZBC,1);
  49. }
  50. //------------------------------------------------
  51.  
  52. public OnFilterScriptInit()
  53. {
  54.     print("\n--Zinglish's Basic Clock loaded v1.3.\n");
  55.     InitializeZBC();
  56.     TextZBCMinutes = 00;
  57.     TextZBCHours = 00;
  58.     SetTimer("UpdateTime", 1000, 1);
  59.     SetWorldTime(TextZBCHours);
  60.     return 1;
  61. }
  62.  
  63. public OnPlayerSpawn(playerid)
  64. {
  65.     TextDrawShowForPlayer(playerid, TextZBC);
  66.     return 1;
  67. }
  68.  
  69. //Timer for time (lol)
  70. forward UpdateTime(playerid);
  71. public UpdateTime(playerid)
  72. {
  73.     new ClockString[126];
  74.     TextZBCMinutes++;
  75.     // Checks for clock 'defining' minutes limit as 60 and hours limit as 24
  76.     if(TextZBCMinutes == 60)
  77.     {
  78.         TextZBCMinutes = 00;
  79.         if(TextZBCHours == 24)
  80.         {
  81.             TextZBCHours = 00;
  82.         }
  83.         TextZBCHours++;
  84.     }
  85.     if(TextZBCMinutes < 10)
  86.     {
  87.         format(TextZBCMinutesString, sizeof(TextZBCMinutesString), "0%i", TextZBCMinutes);
  88.     }
  89.     if(TextZBCMinutes > 10)
  90.     {
  91.         format(TextZBCMinutesString, sizeof(TextZBCMinutesString), "%i", TextZBCMinutes);
  92.     }
  93.     if(TextZBCHours < 10)
  94.     {
  95.         format(TextZBCHoursString, sizeof(TextZBCHoursString), "0%i", TextZBCHours);
  96.     }
  97.     if(TextZBCHours > 10)
  98.     {
  99.         format(TextZBCHoursString, sizeof(TextZBCHoursString), "%i", TextZBCHours);
  100.     }
  101.     format(ClockString, sizeof(ClockString), "%s:%s", TextZBCHoursString, TextZBCMinutesString);
  102.     for(new i=0; i<MAX_PLAYERS; i++)
  103.     {
  104.         if(IsPlayerConnected(i))
  105.         {
  106.             SetPlayerTime(i, TextZBCHours, TextZBCMinutes);
  107.         }
  108.     }
  109.     TextDrawSetString(TextZBC, ClockString);
  110. }
  111.  
  112. public OnPlayerCommandText(playerid, cmdtext[])
  113. {
  114.     dcmd(time,4,cmdtext);
  115.    
  116.     return 0;
  117. }
  118.  
  119. dcmd_time(playerid, params[])
  120. {
  121.     new time;
  122.     if(sscanf(params, "i", time))
  123.     {
  124.         if(IsPlayerAdmin(playerid))
  125.         {
  126.             SendClientMessage(playerid, COLOR_RED, "Usage: /time <0-24>");
  127.             SendClientMessage(playerid, COLOR_RED, "Sets global time");
  128.         }
  129.     }
  130.     else if(IsPlayerAdmin(playerid))
  131.     {
  132.         if(time < 0 || time >24)
  133.         {
  134.             SendClientMessage(playerid, COLOR_RED, "Time must be between 0 and 24 hours");
  135.         }
  136.         else if(time <= 24 && time >= 0)
  137.         {
  138.             TextZBCHours = time;
  139.         }
  140.     }
  141.     else if(!IsPlayerAdmin(playerid))
  142.     {
  143.         SendClientMessage(playerid, COLOR_RED, "You must be admin for this command to work");
  144.     }
  145.  
  146.     return 1;
  147. }
  148.  
  149.  
  150. // -------------------------------------------------------------------------------------------------------------------------------------------------------------
  151. // -------------------------------------------------------------------------------------------------------------------------------------------------------------
  152. // -------------------------------------------------------------------------------------------------------------------------------------------------------------
  153. // -------------------------------------------------------------------------------------------------------------------------------------------------------------
  154. // -------------------------------------------------------------------------------------------------------------------------------------------------------------
  155. // -------------------------------------------------------------------------------------------------------------------------------------------------------------
  156. // -------------------------------------------------------------------------------------------------------------------------------------------------------------
  157.  
  158. stock sscanf(string[], format[], {Float,_}:...)
  159. {
  160.     #if defined isnull
  161.         if (isnull(string))
  162.     #else
  163.         if (string[0] == 0 || (string[0] == 1 && string[1] == 0))
  164.     #endif
  165.         {
  166.             return format[0];
  167.         }
  168.     #pragma tabsize 4
  169.     new
  170.         formatPos = 0,
  171.         stringPos = 0,
  172.         paramPos = 2,
  173.         paramCount = numargs(),
  174.         delim = ' ';
  175.     while (string[stringPos] && string[stringPos] <= ' ')
  176.     {
  177.         stringPos++;
  178.     }
  179.     while (paramPos < paramCount && string[stringPos])
  180.     {
  181.         switch (format[formatPos++])
  182.         {
  183.             case '\0':
  184.             {
  185.                 return 0;
  186.             }
  187.             case 'i', 'd':
  188.             {
  189.                 new
  190.                     neg = 1,
  191.                     num = 0,
  192.                     ch = string[stringPos];
  193.                 if (ch == '-')
  194.                 {
  195.                     neg = -1;
  196.                     ch = string[++stringPos];
  197.                 }
  198.                 do
  199.                 {
  200.                     stringPos++;
  201.                     if ('0' <= ch <= '9')
  202.                     {
  203.                         num = (num * 10) + (ch - '0');
  204.                     }
  205.                     else
  206.                     {
  207.                         return -1;
  208.                     }
  209.                 }
  210.                 while ((ch = string[stringPos]) > ' ' && ch != delim);
  211.                 setarg(paramPos, 0, num * neg);
  212.             }
  213.             case 'h', 'x':
  214.             {
  215.                 new
  216.                     ch,
  217.                     num = 0;
  218.                 while ((ch = string[stringPos]) > ' ' && ch != delim)
  219.                 {
  220.                     switch (ch)
  221.                     {
  222.                         case 'x', 'X':
  223.                         {
  224.                             num = 0;
  225.                             continue;
  226.                         }
  227.                         case '0' .. '9':
  228.                         {
  229.                             num = (num << 4) | (ch - '0');
  230.                         }
  231.                         case 'a' .. 'f':
  232.                         {
  233.                             num = (num << 4) | (ch - ('a' - 10));
  234.                         }
  235.                         case 'A' .. 'F':
  236.                         {
  237.                             num = (num << 4) | (ch - ('A' - 10));
  238.                         }
  239.                         default:
  240.                         {
  241.                             return -1;
  242.                         }
  243.                     }
  244.                 }
  245.                 setarg(paramPos, 0, num);
  246.             }
  247.             case 'c':
  248.             {
  249.                 setarg(paramPos, 0, string[stringPos++]);
  250.             }
  251.             case 'f':
  252.             {
  253.                 setarg(paramPos, 0, _:floatstr(string[stringPos]));
  254.             }
  255.             case 'p':
  256.             {
  257.                 delim = format[formatPos++];
  258.                 continue;
  259.             }
  260.             case '\'':
  261.             {
  262.                 new
  263.                     end = formatPos - 1,
  264.                     ch;
  265.                 while ((ch = format[++end]) && ch != '\'') {}
  266.                 if (!ch)
  267.                 {
  268.                     return -1;
  269.                 }
  270.                 format[end] = '\0';
  271.                 if ((ch = strfind(string, format[formatPos], false, stringPos)) == -1)
  272.                 {
  273.                     if (format[end + 1])
  274.                     {
  275.                         return -1;
  276.                     }
  277.                     return 0;
  278.                 }
  279.                 format[end] = '\'';
  280.                 stringPos = ch + (end - formatPos);
  281.                 formatPos = end + 1;
  282.             }
  283.             case 'u':
  284.             {
  285.                 new
  286.                     end = stringPos - 1,
  287.                     id = 0,
  288.                     bool:num = true,
  289.                     ch;
  290.                 while ((ch = string[++end]) && ch != delim)
  291.                 {
  292.                     if (num)
  293.                     {
  294.                         if ('0' <= ch <= '9')
  295.                         {
  296.                             id = (id * 10) + (ch - '0');
  297.                         }
  298.                         else
  299.                         {
  300.                             num = false;
  301.                         }
  302.                     }
  303.                 }
  304.                 if (num && IsPlayerConnected(id))
  305.                 {
  306.                     setarg(paramPos, 0, id);
  307.                 }
  308.                 else
  309.                 {
  310.                     #if !defined foreach
  311.                         #define foreach(%1,%2) for (new %2 = 0; %2 < MAX_PLAYERS; %2++) if (IsPlayerConnected(%2))
  312.                         #define __SSCANF_FOREACH__
  313.                     #endif
  314.                     string[end] = '\0';
  315.                     num = false;
  316.                     new
  317.                         name[MAX_PLAYER_NAME];
  318.                     id = end - stringPos;
  319.                     foreach (Player, playerid)
  320.                     {
  321.                         GetPlayerName(playerid, name, sizeof (name));
  322.                         if (!strcmp(name, string[stringPos], true, id))
  323.                         {
  324.                             setarg(paramPos, 0, playerid);
  325.                             num = true;
  326.                             break;
  327.                         }
  328.                     }
  329.                     if (!num)
  330.                     {
  331.                         setarg(paramPos, 0, INVALID_PLAYER_ID);
  332.                     }
  333.                     string[end] = ch;
  334.                     #if defined __SSCANF_FOREACH__
  335.                         #undef foreach
  336.                         #undef __SSCANF_FOREACH__
  337.                     #endif
  338.                 }
  339.                 stringPos = end;
  340.             }
  341.             case 's', 'z':
  342.             {
  343.                 new
  344.                     i = 0,
  345.                     ch;
  346.                 if (format[formatPos])
  347.                 {
  348.                     while ((ch = string[stringPos++]) && ch != delim)
  349.                     {
  350.                         setarg(paramPos, i++, ch);
  351.                     }
  352.                     if (!i)
  353.                     {
  354.                         return -1;
  355.                     }
  356.                 }
  357.                 else
  358.                 {
  359.                     while ((ch = string[stringPos++]))
  360.                     {
  361.                         setarg(paramPos, i++, ch);
  362.                     }
  363.                 }
  364.                 stringPos--;
  365.                 setarg(paramPos, i, '\0');
  366.             }
  367.             default:
  368.             {
  369.                 continue;
  370.             }
  371.         }
  372.         while (string[stringPos] && string[stringPos] != delim && string[stringPos] > ' ')
  373.         {
  374.             stringPos++;
  375.         }
  376.         while (string[stringPos] && (string[stringPos] == delim || string[stringPos] <= ' '))
  377.         {
  378.             stringPos++;
  379.         }
  380.         paramPos++;
  381.     }
  382.     do
  383.     {
  384.         if ((delim = format[formatPos++]) > ' ')
  385.         {
  386.             if (delim == '\'')
  387.             {
  388.                 while ((delim = format[formatPos++]) && delim != '\'') {}
  389.             }
  390.             else if (delim != 'z')
  391.             {
  392.                 return delim;
  393.             }
  394.         }
  395.     }
  396.     while (delim > ' ');
  397.     return 0;
  398. }
Advertisement
Add Comment
Please, Sign In to add comment