Advertisement
EnzoMetlc

[FilterScript] Calendario [zTime.inc]

Aug 22nd, 2015
212
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 10.67 KB | None | 0 0
  1. #include <a_samp>
  2. #include <ZCMD>
  3.  
  4.  
  5.  
  6. static Text:BOX[2];
  7. static Text:IMG[2];
  8. static Text:Date[2];
  9. static Text:Days;
  10. static Text:NumberDate[7];
  11. static Text:MiniCalendary[2];
  12.  
  13. static SyncTimer;
  14.  
  15. static const DayName[][] = {"Lunes", "Martes", "Miercoles", "Jueves", "Jueves", "Viernes", "Sabado", "Domingo"};
  16. static const MonthName[][] = {"Enero", "Febrero", "Marzo", "Abril", "Mayo", "Junio", "Julio", "Agosto", "Septiembre", "Octubre", "Noviembre", "Diciembre"};
  17.  
  18.  
  19.  
  20. public OnFilterScriptInit()
  21. {
  22.     print("\n*************************************");
  23.     print("* Sistema de calendario - por EnzoMetlc *");
  24.     print("*************************************\n");
  25.  
  26.  
  27.     /* Imagen del calendario */
  28.     BOX[0] = TextDrawCreate(230.000000, 129.000000, "_");
  29.     TextDrawBackgroundColor(BOX[0], 255);
  30.     TextDrawFont(BOX[0], 1);
  31.     TextDrawLetterSize(BOX[0], 1.301000, 17.100000);
  32.     TextDrawColor(BOX[0], -1);
  33.     TextDrawSetOutline(BOX[0], 0);
  34.     TextDrawSetProportional(BOX[0], 1);
  35.     TextDrawSetShadow(BOX[0], 1);
  36.     TextDrawUseBox(BOX[0], 1);
  37.     TextDrawBoxColor(BOX[0], 100);
  38.     TextDrawTextSize(BOX[0], 31.000000, 0.000000);
  39.  
  40.     BOX[1] = TextDrawCreate(230.000000, 174.000000, "_");
  41.     TextDrawBackgroundColor(BOX[1], 255);
  42.     TextDrawFont(BOX[1], 1);
  43.     TextDrawLetterSize(BOX[1], 0.500000, -0.900000);
  44.     TextDrawColor(BOX[1], -1);
  45.     TextDrawSetOutline(BOX[1], 0);
  46.     TextDrawSetProportional(BOX[1], 1);
  47.     TextDrawSetShadow(BOX[1], 1);
  48.     TextDrawUseBox(BOX[1], 1);
  49.     TextDrawBoxColor(BOX[1], -10092374);
  50.     TextDrawTextSize(BOX[1], 31.000000, 0.000000);
  51.    
  52.     IMG[0] = TextDrawCreate(25.000000, 121.000000, "-");
  53.     TextDrawBackgroundColor(IMG[0], 255);
  54.     TextDrawFont(IMG[0], 1);
  55.     TextDrawLetterSize(IMG[0], 14.890000, 1.000000);
  56.     TextDrawColor(IMG[0], -1);
  57.     TextDrawSetOutline(IMG[0], 1);
  58.     TextDrawSetProportional(IMG[0], 1);
  59.  
  60.     IMG[1] = TextDrawCreate(39.000000, 116.000000, "c c c c c c c c c c c c c c c");
  61.     TextDrawBackgroundColor(IMG[1], 255);
  62.     TextDrawFont(IMG[1], 1);
  63.     TextDrawLetterSize(IMG[1], 0.401000, 1.800000);
  64.     TextDrawColor(IMG[1], -1);
  65.     TextDrawSetOutline(IMG[1], 1);
  66.     TextDrawSetProportional(IMG[1], 1);
  67.    
  68.  
  69.     /* Fecha y hora */
  70.     Date[0] = TextDrawCreate(133.000000, 129.000000, "_");
  71.     TextDrawAlignment(Date[0], 2);
  72.     TextDrawBackgroundColor(Date[0], 255);
  73.     TextDrawFont(Date[0], 2);
  74.     TextDrawLetterSize(Date[0], 0.930000, 2.700000);
  75.     TextDrawColor(Date[0], -1);
  76.     TextDrawSetOutline(Date[0], 1);
  77.     TextDrawSetProportional(Date[0], 1);
  78.  
  79.     Date[1] = TextDrawCreate(133.000000, 152.000000, "_");
  80.     TextDrawAlignment(Date[1], 2);
  81.     TextDrawBackgroundColor(Date[1], 255);
  82.     TextDrawFont(Date[1], 1);
  83.     TextDrawLetterSize(Date[1], 0.390000, 1.400000);
  84.     TextDrawColor(Date[1], -1);
  85.     TextDrawSetOutline(Date[1], 1);
  86.     TextDrawSetProportional(Date[1], 1);
  87.  
  88.  
  89.     /* Días */
  90.     Days = TextDrawCreate(131.000000, 171.000000, "L M M J V ~r~~h~S D");
  91.     TextDrawAlignment(Days, 2);
  92.     TextDrawBackgroundColor(Days, 255);
  93.     TextDrawFont(Days, 2);
  94.     TextDrawLetterSize(Days, 0.469999, 1.799998);
  95.     TextDrawColor(Days, -1);
  96.     TextDrawSetOutline(Days, 1);
  97.     TextDrawSetProportional(Days, 0);
  98.  
  99.  
  100.     /* Número del día de la semana */
  101.     NumberDate[0] = TextDrawCreate(50.000000, 195.000000, "_");
  102.     TextDrawAlignment(NumberDate[0], 2);
  103.     TextDrawBackgroundColor(NumberDate[0], 255);
  104.     TextDrawFont(NumberDate[0], 1);
  105.     TextDrawLetterSize(NumberDate[0], 0.309998, 1.600000);
  106.     TextDrawColor(NumberDate[0], -1);
  107.     TextDrawSetOutline(NumberDate[0], 1);
  108.     TextDrawSetProportional(NumberDate[0], 1);
  109.  
  110.     NumberDate[1] = TextDrawCreate(78.000000, 195.000000, "_");
  111.     TextDrawAlignment(NumberDate[1], 2);
  112.     TextDrawBackgroundColor(NumberDate[1], 255);
  113.     TextDrawFont(NumberDate[1], 1);
  114.     TextDrawLetterSize(NumberDate[1], 0.309998, 1.600000);
  115.     TextDrawColor(NumberDate[1], -1);
  116.     TextDrawSetOutline(NumberDate[1], 1);
  117.     TextDrawSetProportional(NumberDate[1], 1);
  118.  
  119.     NumberDate[2] = TextDrawCreate(105.000000, 195.000000, "_");
  120.     TextDrawAlignment(NumberDate[2], 2);
  121.     TextDrawBackgroundColor(NumberDate[2], 255);
  122.     TextDrawFont(NumberDate[2], 1);
  123.     TextDrawLetterSize(NumberDate[2], 0.309998, 1.600000);
  124.     TextDrawColor(NumberDate[2], -1);
  125.     TextDrawSetOutline(NumberDate[2], 1);
  126.     TextDrawSetProportional(NumberDate[2], 1);
  127.  
  128.     NumberDate[3] = TextDrawCreate(130.000000, 195.000000, "_");
  129.     TextDrawAlignment(NumberDate[3], 2);
  130.     TextDrawBackgroundColor(NumberDate[3], 255);
  131.     TextDrawFont(NumberDate[3], 1);
  132.     TextDrawLetterSize(NumberDate[3], 0.309998, 1.600000);
  133.     TextDrawColor(NumberDate[3], -1);
  134.     TextDrawSetOutline(NumberDate[3], 1);
  135.     TextDrawSetProportional(NumberDate[3], 1);
  136.  
  137.     NumberDate[4] = TextDrawCreate(157.000000, 195.000000, "_");
  138.     TextDrawAlignment(NumberDate[4], 2);
  139.     TextDrawBackgroundColor(NumberDate[4], 255);
  140.     TextDrawFont(NumberDate[4], 1);
  141.     TextDrawLetterSize(NumberDate[4], 0.309998, 1.600000);
  142.     TextDrawColor(NumberDate[4], -1);
  143.     TextDrawSetOutline(NumberDate[4], 1);
  144.     TextDrawSetProportional(NumberDate[4], 1);
  145.  
  146.     NumberDate[5] = TextDrawCreate(183.000000, 195.000000, "_");
  147.     TextDrawAlignment(NumberDate[5], 2);
  148.     TextDrawBackgroundColor(NumberDate[5], 255);
  149.     TextDrawFont(NumberDate[5], 1);
  150.     TextDrawLetterSize(NumberDate[5], 0.309998, 1.600000);
  151.     TextDrawColor(NumberDate[5], -1);
  152.     TextDrawSetOutline(NumberDate[5], 1);
  153.     TextDrawSetProportional(NumberDate[5], 1);
  154.  
  155.     NumberDate[6] = TextDrawCreate(209.000000, 195.000000, "_");
  156.     TextDrawAlignment(NumberDate[6], 2);
  157.     TextDrawBackgroundColor(NumberDate[6], 255);
  158.     TextDrawFont(NumberDate[6], 1);
  159.     TextDrawLetterSize(NumberDate[6], 0.309998, 1.600000);
  160.     TextDrawColor(NumberDate[6], -1);
  161.     TextDrawSetOutline(NumberDate[6], 1);
  162.     TextDrawSetProportional(NumberDate[6], 1);
  163.    
  164.    
  165.     /* Mini-calendario */
  166.     MiniCalendary[0] = TextDrawCreate(163.000000, 132.000000, "_");
  167.     TextDrawBackgroundColor(MiniCalendary[0], 255);
  168.     TextDrawFont(MiniCalendary[0], 1);
  169.     TextDrawLetterSize(MiniCalendary[0], -0.300000, 3.400000);
  170.     TextDrawColor(MiniCalendary[0], -1);
  171.     TextDrawSetOutline(MiniCalendary[0], 0);
  172.     TextDrawSetProportional(MiniCalendary[0], 1);
  173.     TextDrawSetShadow(MiniCalendary[0], 1);
  174.     TextDrawUseBox(MiniCalendary[0], 1);
  175.     TextDrawBoxColor(MiniCalendary[0], 25700);
  176.     TextDrawTextSize(MiniCalendary[0], 32.000000, 0.000000);
  177.  
  178.     MiniCalendary[1] = TextDrawCreate(98.000000, 130.000000, "_");
  179.     TextDrawAlignment(MiniCalendary[1], 2);
  180.     TextDrawBackgroundColor(MiniCalendary[1], 255);
  181.     TextDrawFont(MiniCalendary[1], 2);
  182.     TextDrawLetterSize(MiniCalendary[1], 0.280000, 1.800000);
  183.     TextDrawColor(MiniCalendary[1], -1);
  184.     TextDrawSetOutline(MiniCalendary[1], 1);
  185.     TextDrawSetProportional(MiniCalendary[1], 1);
  186.    
  187.  
  188.     new sec, year, month, day, str[25];
  189.     gettime(sec, sec, sec);
  190.     SyncTimer = SetTimer("UpdateCalendary", (60 - sec) * 1000, true);
  191.  
  192.     getdate(year, month, day);
  193.     format(str, sizeof(str), "%s, %i de %s", DayName[GetDayOfWeek(day, month, year) - 1], day, MonthName[month - 1]);
  194.     TextDrawSetString(Date[1], str);
  195.     UpdateDate();
  196.     return 1;
  197. }
  198.  
  199.  
  200. CMD:calendario(playerid)
  201. {
  202.     TextDrawHideForPlayer(playerid, MiniCalendary[0]);
  203.     TextDrawHideForPlayer(playerid, MiniCalendary[1]);
  204.    
  205.     TextDrawShowForPlayer(playerid, BOX[0]);
  206.     TextDrawShowForPlayer(playerid, BOX[1]);
  207.     TextDrawShowForPlayer(playerid, IMG[0]);
  208.     TextDrawShowForPlayer(playerid, IMG[1]);
  209.     TextDrawShowForPlayer(playerid, Date[0]);
  210.     TextDrawShowForPlayer(playerid, Date[1]);
  211.     TextDrawShowForPlayer(playerid, Days);
  212.    
  213.     for(new i = 0; i < 7; i++) TextDrawShowForPlayer(playerid, NumberDate[i]);
  214.     return 1;
  215. }
  216.  
  217.  
  218. CMD:mini(playerid)
  219. {
  220.     TextDrawHideForPlayer(playerid, BOX[0]);
  221.     TextDrawHideForPlayer(playerid, BOX[1]);
  222.     TextDrawHideForPlayer(playerid, IMG[0]);
  223.     TextDrawHideForPlayer(playerid, IMG[1]);
  224.     TextDrawHideForPlayer(playerid, Date[0]);
  225.     TextDrawHideForPlayer(playerid, Date[1]);
  226.     TextDrawHideForPlayer(playerid, Days);
  227.  
  228.     for(new i = 0; i < 7; i++) TextDrawHideForPlayer(playerid, NumberDate[i]);
  229.    
  230.     TextDrawShowForPlayer(playerid, MiniCalendary[0]);
  231.     TextDrawShowForPlayer(playerid, MiniCalendary[1]);
  232.     return 1;
  233. }
  234.  
  235.  
  236.  
  237.  
  238. /* Funciones */
  239. stock UpdateDate()
  240. {
  241.     new st, month, year, day, max_days[2], str[128], temp[3][10];
  242.    
  243.     getdate(year, month, day);
  244.     st = GetDayOfWeek(1, month, year) - 1; // Primer día del mes.
  245.     max_days[0] = ((month - 1) != 0) ? (GetMaxDaysOfMonth(year, month - 1)) : (GetMaxDaysOfMonth(year, 12));
  246.     max_days[1] = GetMaxDaysOfMonth(year, month);
  247.    
  248.     for(new i = 1; i <= 7; i++)
  249.     {
  250.         new const week1 = (i <= st) ? (max_days[0] - st + i) : (i - st);
  251.         new const week2 = (week1 <= 7) ? (week1 + 7) : ((week1 + 7) - max_days[0]);
  252.         new const week5 = ((week2 + 21) <= max_days[1]) ? (week2 + 21) : ((week2 + 21) - max_days[1]);
  253.         new const week6 = ((week5 + 7) <= max_days[1]) ? (week5 + 7) : ((week5 + 7) - max_days[1]);
  254.        
  255.         if(week1 >= 25) format(temp[0], 10, "~b~~h~%i", week1);
  256.         else format(temp[0], 3, "%i", week1);
  257.        
  258.         if(week5 <= 15) format(temp[1], 10, "~b~~h~%i", week5);
  259.         else format(temp[1], 3, "%i", week5);
  260.        
  261.         if(week6 <= 15) format(temp[2], 10, "~b~~h~%i", week6);
  262.         else format(temp[2], 3, "%i", week6);
  263.        
  264.         format(str, sizeof(str), "%s~w~~n~%i~n~%i~n~%i~n~%s~n~%s", temp[0], week2, week2 + 7, week2 + 14, temp[1], temp[2]);
  265.         TextDrawSetString(NumberDate[i - 1], str);
  266.     }
  267.     return 1;
  268. }
  269.  
  270.  
  271. stock GetMaxDaysOfMonth(year, month)
  272. {
  273.     if(month == 2) return ((year % 4) == 0) ? (29) : (28);
  274.  
  275.     new const MaxDayOfMonth[12] = {31, -1, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
  276.     return MaxDayOfMonth[month - 1];
  277. }
  278.  
  279.  
  280.  
  281. /* GetDayOfWeek (zTime.inc - by _Zume, editado por mí) */
  282. stock GetDayOfWeek(day, month, year)
  283. {
  284.     new d_[4];
  285.  
  286.     d_[0] = (14 - month) / 12;
  287.     d_[2] = year - d_[0];
  288.     d_[1] = month + (12 * d_[0]) - 2;
  289.     d_[3] = (day + d_[2] + (d_[2] / 4) - (d_[2] / 100) + (d_[2] / 400) + (31 * d_[1]) / 12) % 7;
  290.     if(d_[3] == 0) d_[3] = 7;
  291.     return d_[3];
  292. }
  293.  
  294.  
  295.  
  296.  
  297. //-------
  298. forward UpdateCalendary();
  299. public UpdateCalendary()
  300. {
  301.     new hour, minute, second, string[35];
  302.     new year, month, day;
  303.  
  304.     getdate(year, month, day);
  305.     gettime(hour, minute, second);
  306.     format(string, 8, "%i:%02i", hour, minute);
  307.     TextDrawSetString(Date[0], string);
  308.    
  309.     /* Actualizar mini-calendario */
  310.     new dayname[4];
  311.     format(dayname, 4, "%s", DayName[GetDayOfWeek(day, month, year) - 1]);
  312.     format(string, sizeof(string), "~r~%i:%i~n~~w~%02i/%02i/%i - %s", hour, minute, day, month, year, dayname);
  313.     TextDrawSetString(MiniCalendary[1], string);
  314.  
  315.  
  316.     if(second != 0) // Sincronizar el temporizador
  317.     {
  318.         KillTimer(SyncTimer);
  319.         SyncTimer = SetTimer("UpdateCalendary", (60 - second) * 1000, true);
  320.     }
  321.     if(hour == 0) // Actualizar la fecha
  322.     {
  323.         new str[25];
  324.         format(str, sizeof(str), "%s, %i de %s", DayName[GetDayOfWeek(day, month, year) - 1], day, MonthName[month - 1]);
  325.         TextDrawSetString(Date[1], str);
  326.     }
  327.     if(day == 0) UpdateDate(); // Actualizar el calendario
  328.     return 1;
  329. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement