Advertisement
Guest User

Untitled

a guest
Apr 20th, 2019
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.82 KB | None | 0 0
  1. // Setze eine initiales DEFAULT wetter //
  2. mp.world.weather = "CLEAR";
  3. // Einmal die Funktion aufrufen um die Rekursion zu Starten
  4. generateNewWeather();
  5.  
  6.  
  7. async function generateNewWeather() {
  8. /* @randWeather - Int - Zufälliges neues Wetter bestimmen
  9. * @randTime - int - Zufällige zeit bestimmen (Minuten)
  10. * @newWeather - String - neues Wetter
  11. * @maxDurance - Int - Maximale Wetterdauer (mindestens halbe Zeit)
  12. */
  13. let randWeather, randTime, newWeather, maxDurance;
  14. let weatherDuration = 60000;
  15. randWeather = Math.floor(Math.random() * 100);
  16.  
  17. if(randWeather < 25) {
  18. newWeather = "CLEAR";
  19. maxDurance = 90;
  20. } else if(randWeather < 35) {
  21. newWeather = "EXTRASUNNY";
  22. maxDurance = 30;
  23. } else if(randWeather < 50) {
  24. newWeather = "CLOUDS";
  25. maxDurance = 60;
  26. } else if(randWeather < 55) {
  27. newWeather = "OVERCAST";
  28. maxDurance = 45;
  29. } else if(randWeather < 60) {
  30. newWeather = "FOGGY";
  31. maxDurance = 30;
  32. } else if(randWeather < 70) {
  33. newWeather = "RAIN";
  34. maxDurance = 75;
  35. } else if(randWeather < 87) {
  36. newWeather = "THUNDER";
  37. maxDurance = 30;
  38. } else {
  39. newWeather = "CLEARING";
  40. maxDurance = 15;
  41. }
  42. // Generiere eine Zeit zwischen maxDurance/2 und maxDurance für das neue Wetter in ms für setTimeout //
  43. randTime = Math.floor(Math.random() * maxDurance * weatherDuration) + (maxDurance * weatherDuration);
  44. // Setze das neue Wetter im Übergang
  45. mp.world.setWeatherTransition(newWeather);
  46. //KONSOLE LOG
  47. //oconsole.log("Changed Weather to " + newWeather + " - Durance: " + randTime + "ms");
  48. // Setze einen Zeitpunkt für das erneute ändern des Wetters
  49. setTimeout(generateNewWeather, randTime);
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement