Guest User

Remi-X

a guest
May 11th, 2009
480
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 18.20 KB | None | 0 0
  1. /*---------------------------------------------------------------------------------------------*\
  2. |   (C)Remi-X                                                                                   |
  3. |    _________       _______    ______           ______    ____          ____      ____         |
  4. |   |    _    \     |       |  |      \         /      |  |    |         \   \    /   /         |
  5. |   |   | |   |     |   ____|  |       \       /       |  |    |          \   \  /   /          |
  6. |   |   |_|   |     |  |____   |   |\   \     /   /|   |  |    |  ______   \   \/   /           |
  7. |   |    _    \     |       |  |   | \   \   /   / |   |  |    | |      |   \      /            |
  8. |   |   | \    \    |   ____|  |   |  \   \_/   /  |   |  |    | |______|   /      \            |
  9. |   |   |  \    \   |  |____   |   |   \       /   |   |  |    |           /   /\   \           |
  10. |   |   |   \    \  |       |  |   |    \     /    |   |  |    |          /   /  \   \          |
  11. |   |___|    \____\ |_______|  |___|     \___/     |___|  |____|         /___/    \___\         |
  12. |                                                                                               |
  13. |   The Remi-X Time Tools V1.3                                                                  |
  14. |   Please, do not remove any credits.                                                          |
  15. \*---------------------------------------------------------------------------------------------*/
  16.  
  17. /*---------------------------------------------------------------------------------------------*\
  18. | Changelog V1.3:                                                                               |
  19. | -You can coose if players must see their time, or the servertime.                             |
  20. |   -Edit line: 239, and set it to true if you want the servertime, or false for the playertime.|
  21. | -Commands (RCON):                                                                             |
  22. |   -/rw : Sets a random weather.                                                               |
  23. |   -/w [weatherid] to choose a weather.                                                        |
  24. |   -/settime [hour] to set the Server World Time.                                              |
  25. \*---------------------------------------------------------------------------------------------*/
  26.  
  27. /*---------------------------------------------------------------------------------------------*\
  28. | Changelog V1.2:                                                                               |
  29. | -Stupid red weather hopefully deleted...                                                      |
  30. \*---------------------------------------------------------------------------------------------*/
  31.  
  32. /*---------------------------------------------------------------------------------------------*\
  33. | Changelog V1.1:                                                                               |
  34. | -Some Dutch text translated, that I was forgotten.                                            |
  35. | -If you startup the FilterScript, a random weather will be choosen.                           |
  36. | -If you startup the FilterScript, the worldtime will also set directly.                       |
  37. | -The weather, changed at the older version just one time (Bug). Now always.                   |
  38. \*---------------------------------------------------------------------------------------------*/
  39.  
  40. /*---------------------------------------------------------------------------------------------*\
  41. | The Remi-X Time Tools V1.0:                                                                   |
  42. | -Ingame clock, working on servertime, in seconds.                                             |
  43. | -If it is night in your server time, than will it be also ingame night.                       |
  44. | -A random weather script, that will change the weather every hour.                            |
  45. | -The weather is based on the seasons, so if it's summer, you don't get winter weather.        |
  46. | -There are no bullshit weathers, like the darkest weather ever.                               |
  47. | -The clock works on servertime, with seconds.                                                 |
  48. | -The clock has the same place as the original clock of San Andreas.                           |
  49. | -There is also a simple date, only without the year.                                          |
  50. | -If it's month 4, the game says April.                                                        |
  51. | -The WorldTime change also, so if someone check your server values, he see also the hour.     |
  52. | -There is a SetPlayerTime, so every minute will the daytime changed.                          |
  53. \*---------------------------------------------------------------------------------------------*/
  54.  
  55. ///////////Includes//////////
  56. #include <a_samp>
  57.  
  58. ///////////Defines//////////
  59. //Colors
  60. #define BLACK           0x000000FF
  61. #define WHITE           0xFFFFFFFF
  62. #define YELLOW          0xFFFF00FF
  63. #define RED             0xE60000FF
  64.  
  65. //FilterScript
  66. #define FILTERSCRIPT
  67.  
  68. ///////////News//////////
  69. //TextDraw
  70. new Text:TextdrawHour;
  71. new Text:TextdrawMinute;
  72. new Text:TextdrawSeconds;
  73. new Text:TextdrawDay;
  74. new Text:TextdrawMonth;
  75.  
  76. //Bools
  77. new bool:ServerTimeWanted;
  78.  
  79. //Weather
  80. new SpringWeather[8]  =  {1,10,11,14,17,23,29,33};
  81. new SummerWeather[5]  =  {0,1,10,11,19};
  82. new AutumnWeather[10] =  {7,8,9,12,15,16,17,25,30,32};
  83. new WinterWeather[13] =  {1,4,5,7,8,9,12,15,17,20,25,27,30};
  84.  
  85.  
  86. ///////////Forwards//////////
  87. forward RemiX_Time_Tools(playerid);
  88.  
  89. ///////////Callbacks//////////
  90. #if defined FILTERSCRIPT
  91.  
  92. public OnFilterScriptInit()
  93. {
  94.     //Print
  95.     print("\n--------------------------------------");
  96.     print(" Remi-X Time-Tools V 1.3 started up.");
  97.     print("--------------------------------------\n");
  98.    
  99.     //News
  100.     new Year, Month, Day;
  101.     new ServerHour, ServerMinute, ServerSecond;
  102.     new summerrand = random(sizeof(SummerWeather));
  103.     new winterrand = random(sizeof(WinterWeather));
  104.     new springrand = random(sizeof(SpringWeather));
  105.     new autumnrand = random(sizeof(AutumnWeather));
  106.    
  107.     //Gets
  108.     getdate(Year, Month, Day);
  109.     gettime(ServerHour, ServerMinute, ServerSecond);
  110.    
  111.     //Time hours Textdraw
  112.     TextdrawHour = TextDrawCreate(546.000000,22.000000,"--");
  113.     TextDrawAlignment(TextdrawHour,0);
  114.     TextDrawBackgroundColor(TextdrawHour,BLACK);
  115.     TextDrawFont(TextdrawHour,3);
  116.     TextDrawLetterSize(TextdrawHour,0.634,2.4);
  117.     TextDrawColor(TextdrawHour,WHITE);
  118.     TextDrawSetOutline(TextdrawHour,1);
  119.     TextDrawSetProportional(TextdrawHour,1);
  120.     TextDrawSetShadow(TextdrawHour,1);
  121.  
  122.     //Time minutes Textdraw
  123.     TextdrawMinute = TextDrawCreate(570.200000,22.000000,"--");
  124.     TextDrawAlignment(TextdrawMinute,0);
  125.     TextDrawBackgroundColor(TextdrawMinute,BLACK);
  126.     TextDrawFont(TextdrawMinute,3);
  127.     TextDrawLetterSize(TextdrawMinute,0.634,2.4);
  128.     TextDrawColor(TextdrawMinute,WHITE);
  129.     TextDrawSetOutline(TextdrawMinute,1);
  130.     TextDrawSetProportional(TextdrawMinute,1);
  131.     TextDrawSetShadow(TextdrawMinute,1);
  132.  
  133.     //Time Seconds Textdraw
  134.     TextdrawSeconds = TextDrawCreate(606.500000,33.000000,"--");
  135.     TextDrawAlignment(TextdrawSeconds,0);
  136.     TextDrawBackgroundColor(TextdrawSeconds,BLACK);
  137.     TextDrawFont(TextdrawSeconds,3);
  138.     TextDrawLetterSize(TextdrawSeconds,0.3,1.0);
  139.     TextDrawColor(TextdrawSeconds,WHITE);
  140.     TextDrawSetOutline(TextdrawSeconds,1);
  141.     TextDrawSetProportional(TextdrawSeconds,1);
  142.     TextDrawSetShadow(TextdrawSeconds,1);
  143.  
  144.     //Day
  145.     TextdrawDay = TextDrawCreate(500.000000,10.000000,"--");
  146.     TextDrawAlignment(TextdrawDay,0);
  147.     TextDrawBackgroundColor(TextdrawDay,BLACK);
  148.     TextDrawFont(TextdrawDay,3);
  149.     TextDrawLetterSize(TextdrawDay,0.44,1.2);
  150.     TextDrawColor(TextdrawDay,WHITE);
  151.     TextDrawSetOutline(TextdrawDay,1);
  152.     TextDrawSetProportional(TextdrawDay,1);
  153.     TextDrawSetShadow(TextdrawDay,1);
  154.  
  155.     //Month
  156.     TextdrawMonth = TextDrawCreate(515.000000,10.000000,"---------");
  157.     TextDrawAlignment(TextdrawMonth,0);
  158.     TextDrawBackgroundColor(TextdrawMonth,BLACK);
  159.     TextDrawFont(TextdrawMonth,3);
  160.     TextDrawLetterSize(TextdrawMonth,0.44,1.2);
  161.     TextDrawColor(TextdrawMonth,WHITE);
  162.     TextDrawSetOutline(TextdrawMonth,1);
  163.     TextDrawSetProportional(TextdrawMonth,1);
  164.     TextDrawSetShadow(TextdrawMonth,1);
  165.    
  166.     //Random weather
  167.     //Autumn
  168.     if(Month == 12)
  169.     {
  170.         if(Day <21){SetWeather(AutumnWeather[autumnrand]);}
  171.    
  172.         //Winter
  173.         else
  174.         {
  175.             SetWeather(WinterWeather[winterrand]);
  176.         }
  177.     }
  178.     else if(Month == 1 || Month == 2)
  179.     {
  180.         SetWeather(winterrand);
  181.     }
  182.     else if(Month == 3)
  183.     {
  184.         if(Day <21)
  185.         {
  186.             SetWeather(WinterWeather[winterrand]);
  187.         }
  188.    
  189.         //Spring
  190.         else
  191.         {
  192.             SetWeather(SpringWeather[springrand]);
  193.         }
  194.     }
  195.     else if (Month == 4 || Month == 5)
  196.     {
  197.         SetWeather(SpringWeather[springrand]);
  198.     }
  199.     else if(Month == 6)
  200.     {
  201.         if(Day <21)
  202.         {
  203.             SetWeather(SpringWeather[springrand]);
  204.         }
  205.    
  206.         //Summer
  207.         else
  208.         {
  209.             SetWeather(SummerWeather[summerrand]);
  210.         }
  211.     }
  212.     else if(Month == 7 || Month == 8)
  213.     {
  214.         SetWeather(SummerWeather[summerrand]);
  215.     }
  216.     else if(Month == 9)
  217.     {
  218.         if(Day <21)
  219.         {
  220.             SetWeather(SummerWeather[summerrand]);
  221.         }
  222.    
  223.         //Autumn
  224.         else
  225.         {
  226.             SetWeather(AutumnWeather[autumnrand]);
  227.         }
  228.     }
  229.     else if(Month == 10 || Month == 11)
  230.     {
  231.         SetWeather(AutumnWeather[autumnrand]);
  232.     }
  233.     SetWorldTime(ServerHour);
  234.    
  235.     //Timers
  236.     SetTimer("RemiX_Time_Tools", 1000, true);
  237.    
  238.     //Bool
  239.     ServerTimeWanted = false; //Edit this line to show the ServerTime (true) or PlayerTime (false).
  240.     return 1;
  241. }
  242.  
  243. public OnFilterScriptExit()
  244. {
  245.     TextDrawDestroy(TextdrawHour);
  246.     TextDrawDestroy(TextdrawMinute);
  247.     TextDrawDestroy(TextdrawSeconds);
  248.     TextDrawDestroy(TextdrawDay);
  249.     TextDrawDestroy(TextdrawMonth);
  250.     return 1;
  251. }
  252.  
  253. #endif
  254.  
  255. public OnPlayerConnect(playerid)
  256. {
  257.     TextDrawHideForPlayer(playerid,TextdrawHour);
  258.     TextDrawHideForPlayer(playerid,TextdrawMinute);
  259.     TextDrawHideForPlayer(playerid,TextdrawSeconds);
  260.     TextDrawHideForPlayer(playerid,TextdrawDay);
  261.     TextDrawHideForPlayer(playerid,TextdrawMonth);
  262.     SendClientMessage(playerid, YELLOW, "This server uses the Remi-X Time Tools V1.3.");
  263.     return 1;
  264. }
  265.  
  266. public OnPlayerRequestClass(playerid, classid)
  267. {
  268.     TextDrawHideForPlayer(playerid,TextdrawHour);
  269.     TextDrawHideForPlayer(playerid,TextdrawMinute);
  270.     TextDrawHideForPlayer(playerid,TextdrawSeconds);
  271.     TextDrawHideForPlayer(playerid,TextdrawDay);
  272.     TextDrawHideForPlayer(playerid,TextdrawMonth);
  273.     return 1;
  274. }
  275.  
  276. public OnPlayerSpawn(playerid)
  277. {
  278.     TextDrawShowForPlayer(playerid,TextdrawHour);
  279.     TextDrawShowForPlayer(playerid,TextdrawMinute);
  280.     TextDrawShowForPlayer(playerid,TextdrawSeconds);
  281.     TextDrawShowForPlayer(playerid,TextdrawDay);
  282.     TextDrawShowForPlayer(playerid,TextdrawMonth);
  283.     return 1;
  284. }
  285.  
  286. public OnPlayerDisconnect(playerid, reason)
  287. {
  288.     TextDrawHideForPlayer(playerid,TextdrawHour);
  289.     TextDrawHideForPlayer(playerid,TextdrawMinute);
  290.     TextDrawHideForPlayer(playerid,TextdrawSeconds);
  291.     TextDrawHideForPlayer(playerid,TextdrawDay);
  292.     TextDrawHideForPlayer(playerid,TextdrawMonth);
  293.     return 1;
  294. }
  295.  
  296. public OnPlayerCommandText(playerid, cmdtext[])
  297. {
  298.     new cmd[256],tmp[256];
  299.     new idx;
  300.  
  301.     //gets
  302.     cmd = strtok(cmdtext, idx);
  303.    
  304.     if(strcmp("/w", cmd, true, 10) == 0)
  305.     {
  306.         if(IsPlayerAdmin(playerid))
  307.         {
  308.             new WID;
  309.             if(!strlen(tmp))
  310.             {
  311.                 SendClientMessage(playerid, RED,"USAGE: /w [weatherid]");
  312.                 return 1;
  313.             }
  314.             WID = strval(tmp)
  315.             SetWeather(WID);
  316.             SendClientMessage(playerid, YELLOW, "Weather succesfull changed.");
  317.             return 1;
  318.         }
  319.         else
  320.         {
  321.             SendClientMessage(playerid, RED, "You're not allowed to use RXTT commands!");
  322.             return 1;
  323.         }
  324.     }
  325.     if (strcmp("/rw", cmdtext, true) == 0)
  326.     {
  327.         if(IsPlayerAdmin(playerid))
  328.         {
  329.             new Year, Month, Day;
  330.             new summerrand = random(sizeof(SummerWeather));
  331.             new winterrand = random(sizeof(WinterWeather));
  332.             new springrand = random(sizeof(SpringWeather));
  333.             new autumnrand = random(sizeof(AutumnWeather));
  334.             getdate(Year, Month, Day);
  335.             if(Month == 12)
  336.             {
  337.                 if(Day <21){SetWeather(AutumnWeather[autumnrand]);}
  338.                 else {SetWeather(WinterWeather[winterrand]);}
  339.             }
  340.             else if(Month == 1 || Month == 2){SetWeather(winterrand);}
  341.             else if(Month == 3)
  342.             {
  343.                 if(Day <21){SetWeather(WinterWeather[winterrand]);}
  344.                 else{SetWeather(SpringWeather[springrand]);}
  345.             }
  346.             else if (Month == 4 || Month == 5){SetWeather(SpringWeather[springrand]);}
  347.             else if(Month == 6)
  348.             {
  349.                 if(Day <21){SetWeather(SpringWeather[springrand]);}
  350.                 else{SetWeather(SummerWeather[summerrand]);}
  351.             }
  352.             else if(Month == 7 || Month == 8){SetWeather(SummerWeather[summerrand]);}
  353.             else if(Month == 9)
  354.             {
  355.                 if(Day <21){SetWeather(SummerWeather[summerrand]);}
  356.                 else{SetWeather(AutumnWeather[autumnrand]);}
  357.             }
  358.             else if(Month == 10 || Month == 11){SetWeather(AutumnWeather[autumnrand]);}
  359.             SendClientMessage(playerid, YELLOW, "Weather succesfull changed.");
  360.             return 1;
  361.         }
  362.         else
  363.         {
  364.             SendClientMessage(playerid, RED, "You're not allowed to use RXTT commands!");
  365.             return 1;
  366.         }
  367.     }
  368.     if(strcmp("/settime", cmd, true, 10) == 0)
  369.     {
  370.         if(IsPlayerAdmin(playerid))
  371.         {
  372.             new TimeHour;
  373.             if(!strlen(tmp))
  374.             {
  375.                 SendClientMessage(playerid, RED,"USAGE: /settime [hour]");
  376.                 return 1;
  377.             }
  378.             TimeHour = strval(tmp)
  379.             SetWorldTime(TimeHour);
  380.             SendClientMessage(playerid, YELLOW, "Weather succesfull changed.");
  381.             return 1;
  382.         }
  383.         else
  384.         {
  385.             SendClientMessage(playerid, RED, "You're not allowed to use RXTT commands!");
  386.             return 1;
  387.         }
  388.     }
  389.     return 1;
  390. }
  391.    
  392.  
  393. public RemiX_Time_Tools(playerid)
  394. {
  395.     //News
  396.     new string[256];
  397.     new ServerHour, ServerMinute, ServerSecond;
  398.     new PlayerHour, PlayerMinute;
  399.     new Year, Month, Day;
  400.     new summerrand = random(sizeof(SummerWeather));
  401.     new winterrand = random(sizeof(WinterWeather));
  402.     new springrand = random(sizeof(SpringWeather));
  403.     new autumnrand = random(sizeof(AutumnWeather));
  404.  
  405.     //Gets
  406.     gettime(ServerHour,ServerMinute,ServerSecond);
  407.     getdate(Year, Month, Day);
  408.     GetPlayerTime(playerid, PlayerHour, PlayerMinute);
  409.            
  410.     //TextDraw Clock
  411.     if(ServerTimeWanted == true)
  412.     {
  413.         format(string, sizeof(string), "%02d", ServerHour);
  414.         TextDrawSetString(TextdrawHour, string);
  415.    
  416.         format(string, sizeof(string), ":%02d", ServerMinute);
  417.         TextDrawSetString(TextdrawMinute, string);
  418.    
  419.         format(string, sizeof(string), ":%02d", ServerSecond);
  420.         TextDrawSetString(TextdrawSeconds, string);
  421.     }
  422.     else
  423.     {
  424.         format(string, sizeof(string), "%02d", PlayerHour);
  425.         TextDrawSetString(TextdrawHour, string);
  426.    
  427.         format(string, sizeof(string), ":%02d", PlayerMinute);
  428.         TextDrawSetString(TextdrawMinute, string);
  429.    
  430.         format(string, sizeof(string), ":%02d", ServerSecond);
  431.         TextDrawSetString(TextdrawSeconds, string);
  432.     }
  433.  
  434.     //DayTime set
  435.     if(ServerTimeWanted == true){SetPlayerTime(playerid, ServerHour, ServerMinute);}
  436.     else{SetPlayerTime(playerid, PlayerHour, PlayerMinute);}
  437.  
  438.     //TextDraw Day
  439.     format(string, sizeof(string), "%02d", Day);
  440.     TextDrawSetString(TextdrawDay, string);
  441.  
  442.  
  443.     //TextDraw Month
  444.     if(Month == 1)
  445.         {
  446.             format(string, sizeof(string), " January");
  447.             TextDrawSetString(TextdrawMonth, string);
  448.         }
  449.     else if(Month == 2)
  450.         {
  451.             format(string, sizeof(string), " February");
  452.             TextDrawSetString(TextdrawMonth, string);
  453.         }
  454.     else if(Month == 3)
  455.         {
  456.             format(string, sizeof(string), " March");
  457.             TextDrawSetString(TextdrawMonth, string);
  458.         }
  459.     else if(Month == 4)
  460.         {
  461.             format(string, sizeof(string), " April");
  462.             TextDrawSetString(TextdrawMonth, string);
  463.         }
  464.     else if(Month == 5)
  465.         {
  466.             format(string, sizeof(string), " May");
  467.             TextDrawSetString(TextdrawMonth, string);
  468.         }
  469.     else if(Month == 6)
  470.         {
  471.             format(string, sizeof(string), " June");
  472.             TextDrawSetString(TextdrawMonth, string);
  473.         }
  474.     else if(Month == 7)
  475.         {
  476.             format(string, sizeof(string), " July");
  477.             TextDrawSetString(TextdrawMonth, string);
  478.         }
  479.     else if(Month == 8)
  480.         {
  481.             format(string, sizeof(string), " August");
  482.             TextDrawSetString(TextdrawMonth, string);
  483.         }
  484.     else if(Month == 9)
  485.         {
  486.             format(string, sizeof(string), " September");
  487.             TextDrawSetString(TextdrawMonth, string);
  488.         }
  489.     else if(Month == 10)
  490.         {
  491.             format(string, sizeof(string), " Oktober");
  492.             TextDrawSetString(TextdrawMonth, string);
  493.         }
  494.     else if(Month == 11)
  495.         {
  496.             format(string, sizeof(string), " November");
  497.             TextDrawSetString(TextdrawMonth, string);
  498.         }
  499.     else if(Month == 12)
  500.         {
  501.             format(string, sizeof(string), " December");
  502.             TextDrawSetString(TextdrawMonth, string);
  503.         }
  504.  
  505.     //Weather Changer
  506.     if(ServerMinute == 0 && ServerSecond == 0)
  507.     {
  508.         if(ServerTimeWanted == true){format(string, sizeof(string), "It's %02d o' clock. The weather is changed.",ServerHour);}
  509.         else{format(string, sizeof(string), "It's %02d o' clock. The weather is changed.",PlayerHour);}
  510.         SendClientMessageToAll(YELLOW, string);
  511.         format(string, sizeof(string), "The weather is changed.  [%02d:%02d:%02d]",ServerHour, ServerMinute, ServerSecond);
  512.         print(string);
  513.        
  514.         if(Month == 12)
  515.         {
  516.             if(Day <21)
  517.             {
  518.                 SetWeather(AutumnWeather[autumnrand]);
  519.             }
  520.        
  521.             //Winter
  522.             else
  523.             {
  524.                 SetWeather(WinterWeather[winterrand]);
  525.             }
  526.         }
  527.         else if(Month == 1 || Month == 2)
  528.         {
  529.             SetWeather(winterrand);
  530.         }
  531.         else if(Month == 3)
  532.         {
  533.             if(Day <21)
  534.             {
  535.                 SetWeather(WinterWeather[winterrand]);
  536.             }
  537.        
  538.             //Spring
  539.             else
  540.             {
  541.                 SetWeather(SpringWeather[springrand]);
  542.             }
  543.         }
  544.         else if (Month == 4 || Month == 5)
  545.         {
  546.             SetWeather(SpringWeather[springrand]);
  547.         }
  548.         else if(Month == 6)
  549.         {
  550.             if(Day <21)
  551.             {
  552.                 SetWeather(SpringWeather[springrand]);
  553.             }
  554.        
  555.             //Summer
  556.             else
  557.             {
  558.                 SetWeather(SummerWeather[summerrand]);
  559.             }
  560.         }
  561.         else if(Month == 7 || Month == 8)
  562.         {
  563.             SetWeather(SummerWeather[summerrand]);
  564.         }
  565.         else if(Month == 9)
  566.         {
  567.             if(Day <21)
  568.             {
  569.                 SetWeather(SummerWeather[summerrand]);
  570.             }
  571.        
  572.             //Autumn
  573.             else
  574.             {
  575.                 SetWeather(AutumnWeather[autumnrand]);
  576.             }
  577.         }
  578.         else if(Month == 10 || Month == 11)
  579.         {
  580.             SetWeather(AutumnWeather[autumnrand]);
  581.         }
  582.         SetWorldTime(ServerHour);
  583.     }
  584.     return 1;
  585. }
  586.  
  587. strtok(const string[], &index)
  588. {
  589.     new length = strlen(string);
  590.     while ((index < length) && (string[index] <= ' '))
  591.     {
  592.         index++;
  593.     }
  594.  
  595.     new offset = index;
  596.     new result[20];
  597.     while ((index < length) && (string[index] > ' ') && ((index - offset) < (sizeof(result) - 1)))
  598.     {
  599.         result[index - offset] = string[index];
  600.         index++;
  601.     }
  602.     result[index - offset] = EOS;
  603.     return result;
  604. }
Advertisement
Add Comment
Please, Sign In to add comment