Advertisement
Guest User

mascii

a guest
Mar 16th, 2009
491
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 11.97 KB | None | 0 0
  1. //==============================================================================
  2. //==============================================================================
  3. //
  4. //                      mascii's countdown &
  5. //                      countup timers v3(UPDATED)
  6. //
  7. //==============================================================================
  8. //==============================================================================
  9.  
  10.  
  11. //==============================================================================
  12. //  Includes
  13. //==============================================================================
  14. #include "a_samp"
  15.  
  16. //==============================================================================
  17. //  Defines
  18. //==============================================================================
  19. #define FILTERSCRIPT
  20. #define COLOR_GREY 0xAFAFAFAA
  21.  
  22. //==============================================================================
  23. //  New
  24. //==============================================================================
  25. new Menu:MainMenu;
  26. new Menu:CountUp;
  27. new Menu:CountDownPos;
  28. new Menu:CountDownTime;
  29.  
  30. new CountDownMinutes;
  31. new CountDownSeconds;
  32. new CountUpSeconds;
  33. new CountUpMinutes;
  34. new Counting;
  35. // 0=false
  36. // 1=true
  37. new Text:Pos1;// bottom
  38. new Text:Pos2;// top
  39. new Pos;
  40. // 0=bottom
  41. // 1=top
  42.  
  43. //==============================================================================
  44. //  Forwards
  45. //==============================================================================
  46. forward CountUpTimer();
  47. forward CountDownTimer();
  48. forward CountDownFinish();
  49.  
  50. //==============================================================================
  51. //  OnFilterScriptInit()
  52. //==============================================================================
  53. public OnFilterScriptInit()
  54. {
  55.     MainMenu = CreateMenu("Main Menu", 1, 200, 150, 240, 0.0);
  56.     AddMenuItem(MainMenu, 0, "Count Up");
  57.     AddMenuItem(MainMenu, 0, "Count Down");
  58.     AddMenuItem(MainMenu, 0, "Stop Count");
  59.     AddMenuItem(MainMenu, 0, "Exit");
  60.    
  61.     CountUp = CreateMenu("Count Up", 1, 200, 150, 240, 0.0);
  62.     AddMenuItem(CountUp, 0, "Position 1");
  63.     AddMenuItem(CountUp, 0, "Position 2");
  64.     AddMenuItem(CountUp, 0, "Main Menu");
  65.  
  66.     CountDownPos = CreateMenu("Count Down Pos", 1, 200, 150, 240, 0.0);
  67.     AddMenuItem(CountDownPos, 0, "Position 1");
  68.     AddMenuItem(CountDownPos, 0, "Position 2");
  69.     AddMenuItem(CountDownPos, 0, "Main Menu");
  70.  
  71.     CountDownTime = CreateMenu("Count Down Time", 1, 200, 150, 240, 0.0);
  72.     AddMenuItem(CountDownTime, 0, "5 min");
  73.     AddMenuItem(CountDownTime, 0, "10 min");
  74.     AddMenuItem(CountDownTime, 0, "20 min");
  75.     AddMenuItem(CountDownTime, 0, "30 min");
  76.     AddMenuItem(CountDownTime, 0, "60 min");
  77.     AddMenuItem(CountDownTime, 0, "Main Menu");
  78.  
  79.     Pos1 = TextDrawCreate(324.000000,412.000000,"  "); //bottom
  80.     Pos2 = TextDrawCreate(324.000000,23.000000,"  "); //top
  81.     TextDrawAlignment(Pos1,2);
  82.     TextDrawAlignment(Pos2,2);
  83.     TextDrawBackgroundColor(Pos1,0x000000ff);
  84.     TextDrawBackgroundColor(Pos2,0x000000ff);
  85.     TextDrawFont(Pos1,3);
  86.     TextDrawLetterSize(Pos1,0.399999,1.400000);
  87.     TextDrawFont(Pos2,3);
  88.     TextDrawLetterSize(Pos2,0.399999,1.400000);
  89.     TextDrawColor(Pos1,0xffffffff);
  90.     TextDrawColor(Pos2,0xffffffff);
  91.     TextDrawSetOutline(Pos1,1);
  92.     TextDrawSetOutline(Pos2,1);
  93.     TextDrawSetProportional(Pos1,1);
  94.     TextDrawSetProportional(Pos2,1);
  95.     TextDrawSetShadow(Pos1,1);
  96.     TextDrawSetShadow(Pos2,1);
  97.  
  98.     CountDownMinutes = 0; //in minutes
  99.     CountDownSeconds = 0; //in seconds
  100.     CountUpSeconds = 0;
  101.     CountUpMinutes = 0;
  102.     Counting = 0;
  103.     Pos = 0;
  104.     return 1;
  105. }
  106.  
  107. //==============================================================================
  108. //  OnFilterScriptExit()
  109. //==============================================================================
  110. public OnFilterScriptExit()
  111. {
  112.     TextDrawDestroy(Pos1);
  113.     TextDrawDestroy(Pos2);
  114.     DestroyMenu(MainMenu);
  115.     DestroyMenu(CountUp);
  116.     DestroyMenu(CountDownPos);
  117.     DestroyMenu(CountDownTime);
  118.     return 1;
  119. }
  120.  
  121. //==============================================================================
  122. //  CountUpTimer()
  123. //==============================================================================
  124. public CountUpTimer()
  125. {
  126.     if (Pos == 0)
  127.     {
  128.         if (Counting == 1)
  129.         {
  130.             CountUpSeconds++;
  131.             if (CountUpSeconds == 60)
  132.             {
  133.                 CountUpSeconds = 0;
  134.                 CountUpMinutes++;
  135.             }
  136.             new string[256];
  137.             format(string, sizeof(string), "%d:%d", CountUpMinutes, CountUpSeconds);
  138.             TextDrawSetString(Text:Pos1, string);
  139.             SetTimer("CountUpTimer", 1000, 0);
  140.         }
  141.     }
  142.     if (Pos == 1)
  143.     {
  144.         if (Counting == 1)
  145.         {
  146.             CountUpSeconds++;
  147.             if (CountUpSeconds == 60)
  148.             {
  149.                 CountUpSeconds = 0;
  150.                 CountUpMinutes++;
  151.             }
  152.             new string2[256];
  153.             format(string2, sizeof(string2), "%d:%d", CountUpMinutes, CountUpSeconds);
  154.             TextDrawSetString(Text:Pos2, string2);
  155.             SetTimer("CountUpTimer", 1000, 0);
  156.         }
  157.     }
  158.     return 1;
  159. }
  160.  
  161. //==============================================================================
  162. //  CountDownTimer()
  163. //==============================================================================
  164. public CountDownTimer()
  165. {
  166.     if (Pos == 0)
  167.     {
  168.         if (Counting == 1)
  169.         {
  170.             CountDownSeconds--;
  171.             if (CountDownSeconds == 0)
  172.             {
  173.                 CountDownSeconds = 60;
  174.                 if (CountDownMinutes == 0)
  175.                 {
  176.                     Counting = 0;
  177.                     TextDrawHideForAll(Pos1);
  178.                     SetTimer("CountDownFinish", 500, 0);
  179.                 }
  180.                 CountDownMinutes--;
  181.             }
  182.             new string[256];
  183.             format(string, sizeof(string), "%d:%d", CountDownMinutes, CountDownSeconds);
  184.             TextDrawSetString(Text:Pos1, string);
  185.             SetTimer("CountDownTimer", 1000, 0);
  186.         }
  187.     }
  188.    
  189.     if (Pos == 1)
  190.     {
  191.         if (Counting == 1)
  192.         {
  193.             CountDownSeconds--;
  194.             if (CountDownSeconds == 0)
  195.             {
  196.                 CountDownSeconds = 60;
  197.                 if (CountDownMinutes == 0)
  198.                 {
  199.                     Counting = 0;
  200.                     TextDrawHideForAll(Pos2);
  201.                     SetTimer("CountDownFinish", 500, 0);
  202.                 }
  203.                 CountDownMinutes--;
  204.             }
  205.             new string2[256];
  206.             format(string2, sizeof(string2), "%d:%d", CountDownMinutes, CountDownSeconds);
  207.             TextDrawSetString(Text:Pos2, string2);
  208.             SetTimer("CountDownTimer", 1000, 0);
  209.         }
  210.     }
  211.     return 1;
  212. }
  213.  
  214. //==============================================================================
  215. //  CountDownFinish()
  216. //==============================================================================
  217. public CountDownFinish()
  218. {
  219.     // do somthing here if you want
  220.     // eg
  221.     // SetGravity(0.008)
  222.     SendClientMessageToAll(COLOR_GREY, "Times up!");
  223.     return 1;
  224. }
  225.  
  226. //==============================================================================
  227. //  OnPlayerSelectedMenuRow(playerid, row)
  228. //==============================================================================
  229. public OnPlayerSelectedMenuRow(playerid, row)
  230. {
  231.     new Menu:Current;
  232.     Current = GetPlayerMenu(playerid);
  233.    
  234.     if(Current == MainMenu)
  235.     {
  236.         switch(row)
  237.         {
  238.             case 0:
  239.             {
  240.                 if (Counting == 1)
  241.                 {
  242.                     SendClientMessage(playerid, COLOR_GREY, "A count is already in progress.");
  243.                     ShowMenuForPlayer(MainMenu, playerid);
  244.                 }
  245.                 if (Counting == 0)
  246.                 {
  247.                     ShowMenuForPlayer(CountUp, playerid);
  248.                 }
  249.             }
  250.             case 1:
  251.             {
  252.                 if (Counting == 1)
  253.                 {
  254.                     SendClientMessage(playerid, COLOR_GREY, "A count is already in progress.");
  255.                     ShowMenuForPlayer(MainMenu, playerid);
  256.                 }
  257.                 if (Counting == 0)
  258.                 {
  259.                     ShowMenuForPlayer(CountDownPos, playerid);
  260.                 }
  261.             }
  262.             case 2:
  263.             {
  264.                 if (Counting == 0)
  265.                 {
  266.                     SendClientMessage(playerid, COLOR_GREY, "No count in progress.");
  267.                     ShowMenuForPlayer(MainMenu, playerid);
  268.                 }
  269.                 if (Counting == 1)
  270.                 {
  271.                     CountDownMinutes = 0; //in minutes
  272.                     CountDownSeconds = 0; //in seconds
  273.                     CountUpSeconds = 0;
  274.                     CountUpMinutes = 0;
  275.                     Counting = 0;
  276.                     TextDrawHideForAll(Pos1);
  277.                     TextDrawHideForAll(Pos2);
  278.                     SendClientMessageToAll(COLOR_GREY, "Admin: Count Cancelled!");
  279.                     new string[256];
  280.                     format(string, sizeof(string), "  ");
  281.                     TextDrawSetString(Text:Pos1, string);
  282.                     new string2[256];
  283.                     format(string2, sizeof(string2), "  ");
  284.                     TextDrawSetString(Text:Pos2, string2);
  285.                     ShowMenuForPlayer(MainMenu, playerid);
  286.                 }
  287.             }
  288.             case 3:
  289.             {
  290.                 TogglePlayerControllable(playerid, 1);
  291.             }
  292.         }
  293.     }
  294.     if(Current == CountUp)
  295.     {
  296.         switch(row)
  297.         {
  298.             case 0:
  299.             {
  300.                 Counting = 1;
  301.                 CountUpSeconds = 0;
  302.                 CountUpMinutes = 0;
  303.                 Pos = 0; // bottom
  304.                 TextDrawShowForAll(Pos1); // bottom
  305.                 SetTimer("CountUpTimer", 1000, 0);
  306.                 SendClientMessageToAll(COLOR_GREY, "Admin: Count Started!");
  307.                 ShowMenuForPlayer(MainMenu, playerid);
  308.             }
  309.             case 1:
  310.             {
  311.                 Counting = 1;
  312.                 CountUpSeconds = 0;
  313.                 CountUpMinutes = 0;
  314.                 Pos = 1; // top
  315.                 TextDrawShowForAll(Pos2); // top
  316.                 SetTimer("CountUpTimer", 1000, 0);
  317.                 SendClientMessageToAll(COLOR_GREY, "Admin: Count Started!");
  318.                 ShowMenuForPlayer(MainMenu, playerid);
  319.             }
  320.             case 2:
  321.             {
  322.                 ShowMenuForPlayer(MainMenu, playerid);
  323.             }
  324.         }
  325.     }
  326.     if(Current == CountDownPos)
  327.     {
  328.         switch(row)
  329.         {
  330.             case 0:
  331.             {
  332.                 Pos = 0; // bottom
  333.                 new string[256];
  334.                 format(string, sizeof(string), "  ");
  335.                 TextDrawSetString(Text:Pos1, string);
  336.                 TextDrawShowForAll(Pos1); // bottom
  337.                 ShowMenuForPlayer(CountDownTime, playerid);
  338.             }
  339.             case 1:
  340.             {
  341.                 Pos = 1; // top
  342.                 new string2[256];
  343.                 format(string2, sizeof(string2), "  ");
  344.                 TextDrawSetString(Text:Pos2, string2);
  345.                 TextDrawShowForAll(Pos2); // top
  346.                 ShowMenuForPlayer(CountDownTime, playerid);
  347.             }
  348.             case 2:
  349.             {
  350.                 ShowMenuForPlayer(MainMenu, playerid);
  351.             }
  352.         }
  353.     }
  354.     if(Current == CountDownTime)
  355.     {
  356.         switch(row)
  357.         {
  358.             case 0:
  359.             {
  360.                 Counting = 1;
  361.                 CountDownMinutes = 5; //in minutes
  362.                 CountDownSeconds = 1; //in seconds
  363.                 SetTimer("CountDownTimer", 1000, 0);
  364.                 SendClientMessageToAll(COLOR_GREY, "Admin: Count Started!");
  365.                 ShowMenuForPlayer(MainMenu, playerid);
  366.             }
  367.             case 1:
  368.             {
  369.                 Counting = 1;
  370.                 CountDownMinutes = 10; //in minutes
  371.                 CountDownSeconds = 1; //in seconds
  372.                 SetTimer("CountDownTimer", 1000, 0);
  373.                 SendClientMessageToAll(COLOR_GREY, "Admin: Count Started!");
  374.                 ShowMenuForPlayer(MainMenu, playerid);
  375.             }
  376.             case 2:
  377.             {
  378.  
  379.                 Counting = 1;
  380.                 CountDownMinutes = 20; //in minutes
  381.                 CountDownSeconds = 1; //in seconds
  382.                 SetTimer("CountDownTimer", 1000, 0);
  383.                 SendClientMessageToAll(COLOR_GREY, "Admin: Count Started!");
  384.                 ShowMenuForPlayer(MainMenu, playerid);
  385.             }
  386.             case 3:
  387.             {
  388.                 Counting = 1;
  389.                 CountDownMinutes = 30; //in minutes
  390.                 CountDownSeconds = 1; //in seconds
  391.                 SetTimer("CountDownTimer", 1000, 0);
  392.                 SendClientMessageToAll(COLOR_GREY, "Admin: Count Started!");
  393.                 ShowMenuForPlayer(MainMenu, playerid);
  394.             }
  395.             case 4:
  396.             {
  397.                 Counting = 1;
  398.                 CountDownMinutes = 60; //in minutes
  399.                 CountDownSeconds = 1; //in seconds
  400.                 SetTimer("CountDownTimer", 1000, 0);
  401.                 SendClientMessageToAll(COLOR_GREY, "Admin: Count Started!");
  402.                 ShowMenuForPlayer(MainMenu, playerid);
  403.             }
  404.             case 5:
  405.             {
  406.                 TextDrawHideForAll(Pos1);
  407.                 TextDrawHideForAll(Pos2);
  408.                 ShowMenuForPlayer(MainMenu, playerid);
  409.             }
  410.         }
  411.     }
  412.     return 1;
  413. }
  414.  
  415. //==============================================================================
  416. //  OnPlayerCommandText(playerid, cmdtext[])
  417. //==============================================================================
  418. public OnPlayerCommandText(playerid, cmdtext[])
  419. {
  420.     if (strcmp("/count", cmdtext, true, 10) == 0)
  421.     {
  422.         if (IsPlayerAdmin(playerid) == 1)
  423.         {
  424.             TogglePlayerControllable(playerid, 0);
  425.             ShowMenuForPlayer(MainMenu, playerid);
  426.         }
  427.         return 1;
  428.     }
  429.     return 0;
  430. }
  431.  
  432. //==============================================================================
  433. //  OnPlayerExitedMenu(playerid)
  434. //==============================================================================
  435. public OnPlayerExitedMenu(playerid)
  436. {
  437.     TogglePlayerControllable(playerid, 1);
  438.     return 1;
  439. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement