Advertisement
Guest User

Weather.as

a guest
Aug 29th, 2014
193
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.23 KB | None | 0 0
  1. //Weather system serverside
  2.  
  3. //#define SERVER_ONLY
  4.  
  5. enum Weather
  6. {
  7.     Sunny,
  8.     Rainy,
  9.     Snowy,
  10.     Cloudy,
  11.     Stormy
  12. }
  13.  
  14. void onInit( CRules@ this )
  15. {
  16.     this.set_u8("weather", Weather::Rainy);
  17.     this.set_u16("weather stable time", 8);
  18.     this.Sync("weather", false);
  19. }
  20.  
  21. void onTick( CRules@ this )
  22. {
  23.     int weather = this.get_u8("weather");
  24.  
  25.     if(getNet().isServer())
  26.     {
  27.         int timer = this.get_u16("weather stable time");
  28.         if(timer > 0)
  29.         {
  30.             print("not yet");
  31.             timer--;
  32.             this.set_u16("weather stable time", timer);
  33.  
  34.             return;
  35.         }
  36.  
  37.         this.set_u16("weather stable time", 128 + XORRandom(32));
  38.  
  39.         //int weather = this.get_u8("weather");
  40.  
  41.         weather = 1 - weather;
  42.    
  43.         print("weather is " + weather);
  44.  
  45.         this.set_u8("weather", weather);
  46.         this.Sync("weather", false);
  47.     }//isServer
  48.     else
  49.     {
  50.  
  51.         print(" ");
  52.  
  53.         print("weather is " + weather);
  54.  
  55.              if(weather == Weather::Sunny)
  56.         {
  57.             print("its sunny");
  58.             return;
  59.         }
  60.         else if(weather == Weather::Rainy)
  61.         {
  62.             print("its rainy");
  63.         }
  64.         else if(weather == Weather::Snowy)
  65.         {
  66.             print("its snowy");
  67.         }
  68.         else if(weather == Weather::Cloudy)
  69.         {
  70.             print("its cloudy");
  71.         }
  72.         else if(weather == Weather::Stormy)
  73.         {
  74.             print("its stormy");
  75.         }
  76.     }
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement