Guest User

Zinglish

a guest
Nov 10th, 2009
162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 9.33 KB | None | 0 0
  1. /*
  2. *  ________                       ___                 __
  3. * /\_____  \  __                 /\_ \    __         /\ \
  4. * \/____//'/'/\_\    ___      __ \//\ \  /\_\    ____\ \ \___
  5. *      //'/' \/\ \ /' _ `\  /'_ `\ \ \ \ \/\ \  /',__\\ \  _ `\
  6. *     //'/'___\ \ \/\ \/\ \/\ \Z\ \ \_\ \_\ \ \/\__, `\\ \ \ \ \
  7. *     /\_______\ \_\ \_\ \_\ \____ \/\____\\ \_\/\____/ \ \_\ \_\
  8. *     \/_______/\/_/\/_/\/_/\/___Z\ \/____/ \/_/\/___/   \/_/\/_/
  9. *                             /\____/
  10. *                             \_/__/
  11. */
  12.  
  13. /*
  14. *        ________  ______      ______          __        _____
  15. *       |  __   _||_   _ \   .' ___  |        /  |      / ___ `.
  16. *       |_/  / /    | |_) | / .'   \_|  _   __`| |     |_/___) |
  17. *          .'.' _   |  __'. | |        [ \ [  ]| |      .'____.'
  18. *        _/ /__/ | _| |__) |\ `.___.'\  \ \/ /_| |_  _ / /_____
  19. *       |________||_______/  `.____ .'   \__/|_____|(_)|_______|
  20. *
  21. */
  22.  
  23. #define BLACK 0x000000FF
  24. #define WHITE 0xFFFFFFFF
  25. #define COLOR_RED 0xE21F1FFF
  26.  
  27. #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
  28.  
  29. #include <a_samp>
  30.  
  31. new Text:TextZBC;
  32. new TextZBCHours, TextZBCHoursString[56];
  33. new TextZBCMinutes, TextZBCMinutesString[56];
  34. stock InitializeZBC()
  35. {
  36.     TextZBC = TextDrawCreate(546.000000,22.000000,"--:--");
  37.     TextDrawAlignment(TextZBC,0);
  38.     TextDrawBackgroundColor(TextZBC,BLACK);
  39.     TextDrawFont(TextZBC,3);
  40.     TextDrawLetterSize(TextZBC,0.635,2.4);
  41.     TextDrawColor(TextZBC,WHITE);
  42.     TextDrawSetOutline(TextZBC,1);
  43.     TextDrawSetProportional(TextZBC,1);
  44.     TextDrawSetShadow(TextZBC,1);
  45. }
  46. //------------------------------------------------
  47.  
  48. public OnFilterScriptInit()
  49. {
  50.     print("\n--Zinglish's Basic Clock loaded.\n");
  51.     InitializeZBC();
  52.     TextZBCMinutes = 00;
  53.     TextZBCHours = 00;
  54.     SetTimer("UpdateTime", 1000, 1);
  55.     SetWorldTime(TextZBCHours);
  56.     return 1;
  57. }
  58.  
  59. public OnPlayerSpawn(playerid)
  60. {
  61.     TextDrawShowForPlayer(playerid, TextZBC);
  62.     return 1;
  63. }
  64.  
  65. //Timer for time (lol)
  66. forward UpdateTime(playerid);
  67. public UpdateTime(playerid)
  68. {
  69.     new string[126];
  70.     TextZBCMinutes++;
  71.     // Checks for clock 'defining' minutes limit as 60 and hours limit as 24
  72.     if(TextZBCMinutes == 60)
  73.     {
  74.         TextZBCMinutes = 00;
  75.         if(TextZBCHours == 24)
  76.         {
  77.             TextZBCHours = 00;
  78.         }
  79.         TextZBCHours++;
  80.     }
  81.     if(TextZBCMinutes < 10)
  82.     {
  83.         format(TextZBCMinutesString, sizeof(TextZBCMinutesString), "0%i", TextZBCMinutes);
  84.     }
  85.     if(TextZBCMinutes > 10)
  86.     {
  87.         format(TextZBCMinutesString, sizeof(TextZBCMinutesString), "%i", TextZBCMinutes);
  88.     }
  89.     if(TextZBCHours < 10)
  90.     {
  91.         format(TextZBCHoursString, sizeof(TextZBCHoursString), "0%i", TextZBCHours);
  92.     }
  93.     if(TextZBCHours > 10)
  94.     {
  95.         format(TextZBCHoursString, sizeof(TextZBCHoursString), "%i", TextZBCHours);
  96.     }
  97.     format(string, sizeof(string), "%s:%s", TextZBCHoursString, TextZBCMinutesString);
  98.     for(new i  =0; i<MAX_PLAYERS; i++)
  99.     {
  100.         if(IsPlayerConnected(i))
  101.         {
  102.             SetPlayerTime(i, TextZBCHours, TextZBCMinutes);
  103.         }
  104.     }
  105.     TextDrawSetString(TextZBC, string);
  106. }
  107.  
  108. public OnPlayerCommandText(playerid, cmdtext[])
  109. {
  110.     dcmd(time,4,cmdtext);
  111.    
  112.     return 0;
  113. }
  114.  
  115. dcmd_time(playerid, params[])
  116. {
  117.     new time;
  118.     if(sscanf(params, "i", time))
  119.     {
  120.         if(IsPlayerAdmin(playerid))
  121.         {
  122.             SendClientMessage(playerid, COLOR_RED, "Usage: /time <0-24>");
  123.             SendClientMessage(playerid, COLOR_RED, "Sets global time");
  124.         }
  125.     }
  126.     else if(IsPlayerAdmin(playerid))
  127.     {
  128.         if(time < 0 || time >24)
  129.         {
  130.             SendClientMessage(playerid, COLOR_RED, "Time must be between 0 and 24 hours");
  131.         }
  132.         else if(time <= 24 && time >= 0)
  133.         {
  134.             TextZBCHours = time;
  135.         }
  136.     }
  137.     else if(!IsPlayerAdmin(playerid))
  138.     {
  139.         SendClientMessage(playerid, COLOR_RED, "You must be admin for this command to work");
  140.     }
  141.  
  142.     return 1;
  143. }
  144.  
  145.  
  146. // -------------------------------------------------------------------------------------------------------------------------------------------------------------
  147. // -------------------------------------------------------------------------------------------------------------------------------------------------------------
  148. // -------------------------------------------------------------------------------------------------------------------------------------------------------------
  149. // -------------------------------------------------------------------------------------------------------------------------------------------------------------
  150. // -------------------------------------------------------------------------------------------------------------------------------------------------------------
  151. // -------------------------------------------------------------------------------------------------------------------------------------------------------------
  152. // -------------------------------------------------------------------------------------------------------------------------------------------------------------
  153.  
  154. stock sscanf(string[], format[], {Float,_}:...)
  155. {
  156.     #if defined isnull
  157.         if (isnull(string))
  158.     #else
  159.         if (string[0] == 0 || (string[0] == 1 && string[1] == 0))
  160.     #endif
  161.         {
  162.             return format[0];
  163.         }
  164.     #pragma tabsize 4
  165.     new
  166.         formatPos = 0,
  167.         stringPos = 0,
  168.         paramPos = 2,
  169.         paramCount = numargs(),
  170.         delim = ' ';
  171.     while (string[stringPos] && string[stringPos] <= ' ')
  172.     {
  173.         stringPos++;
  174.     }
  175.     while (paramPos < paramCount && string[stringPos])
  176.     {
  177.         switch (format[formatPos++])
  178.         {
  179.             case '\0':
  180.             {
  181.                 return 0;
  182.             }
  183.             case 'i', 'd':
  184.             {
  185.                 new
  186.                     neg = 1,
  187.                     num = 0,
  188.                     ch = string[stringPos];
  189.                 if (ch == '-')
  190.                 {
  191.                     neg = -1;
  192.                     ch = string[++stringPos];
  193.                 }
  194.                 do
  195.                 {
  196.                     stringPos++;
  197.                     if ('0' <= ch <= '9')
  198.                     {
  199.                         num = (num * 10) + (ch - '0');
  200.                     }
  201.                     else
  202.                     {
  203.                         return -1;
  204.                     }
  205.                 }
  206.                 while ((ch = string[stringPos]) > ' ' && ch != delim);
  207.                 setarg(paramPos, 0, num * neg);
  208.             }
  209.             case 'h', 'x':
  210.             {
  211.                 new
  212.                     ch,
  213.                     num = 0;
  214.                 while ((ch = string[stringPos]) > ' ' && ch != delim)
  215.                 {
  216.                     switch (ch)
  217.                     {
  218.                         case 'x', 'X':
  219.                         {
  220.                             num = 0;
  221.                             continue;
  222.                         }
  223.                         case '0' .. '9':
  224.                         {
  225.                             num = (num << 4) | (ch - '0');
  226.                         }
  227.                         case 'a' .. 'f':
  228.                         {
  229.                             num = (num << 4) | (ch - ('a' - 10));
  230.                         }
  231.                         case 'A' .. 'F':
  232.                         {
  233.                             num = (num << 4) | (ch - ('A' - 10));
  234.                         }
  235.                         default:
  236.                         {
  237.                             return -1;
  238.                         }
  239.                     }
  240.                 }
  241.                 setarg(paramPos, 0, num);
  242.             }
  243.             case 'c':
  244.             {
  245.                 setarg(paramPos, 0, string[stringPos++]);
  246.             }
  247.             case 'f':
  248.             {
  249.                 setarg(paramPos, 0, _:floatstr(string[stringPos]));
  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