Advertisement
Guest User

Untitled

a guest
Aug 12th, 2015
288
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.97 KB | None | 0 0
  1. -- Weather simulation resource by vovo4ka
  2. -- e-mail: zolotayapipka@gmail.com
  3. -- client side script
  4. -- v 1.0
  5. -- Dyanmic weather
  6. cyclones = {{0,0,0},{0,0,0},{0,0,0}}
  7.  
  8. function CycAcc ( x1,y1,r1,x2,y2,r2,x3,y3,r3 )
  9. cyclones[1][1] = x1
  10. cyclones[1][2] = y1
  11. cyclones[1][3] = r1
  12. cyclones[2][1] = x2
  13. cyclones[2][2] = y2
  14. cyclones[2][3] = r2
  15. cyclones[3][1] = x3
  16. cyclones[3][2] = y3
  17. cyclones[3][3] = r3
  18. end
  19. addEvent( "AcceptCyclones", true )
  20. addEventHandler( "AcceptCyclones", getRootElement(), CycAcc )
  21.  
  22.  
  23. -----------------------------
  24. -- Constant weather.
  25.  
  26. -- Weather patterns. You can change it to make more realistic weather
  27. -- Every number means half of hour.
  28. -- For example weather id 12 -> 00:00 am 12 - > 00:30 am 15 -> 1:00 am
  29. weat_city = {12,12,15,15,66,66,12,12,61,58,63,28,28,28,6,11,11,11,11,11,11,11,2,2,14,14,14,14,34,34,34,34,1,1,1,1,17,17,18,3,3,3,3,3,1,0,3,3}
  30. weat_green = {1,1,54,1,1,1,9,1,61,58,63,28,28,28,6,11,11,11,11,11,11,11,2,2,14,14,14,14,34,34,34,34,1,1,1,1,17,17,18,3,3,3,2,1,1,0,3,3}
  31. weat_desert = {1,1,1,1,1,19,1,1,61,61,58,28,28,28,18,11,11,11,11,11,11,11,2,2,14,14,14,14,34,34,34,34,1,1,1,1,17,17,18,18,2,2,2,1,1,0,3,19}
  32. weat_lv = {12,12,15,15,66,66,12,12,61,58,28,28,28,28,18,11,11,11,11,11,11,11,2,2,14,14,14,14,34,34,34,34,1,1,1,1,17,17,18,3,3,3,2,1,1,0,3,3}
  33.  
  34. weat_zone= --Const Weather Map -- it looks noobly. but allows precisely determine land type
  35. { -- Terrain type 1 - forest 2 - city 4 - desert 8 - LV (desert+city)
  36. {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
  37. {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
  38. {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
  39. {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
  40. {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
  41. {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,4,4,4,4,4,4,4,4,4,4,4,4,8,8,8,8,8,8,8,8,1,1,1,1,1},
  42. {1,1,1,1,1,1,1,1,1,1,1,1,1,4,4,4,4,4,4,4,4,4,4,4,4,4,8,8,8,8,8,8,8,8,8,1,1,1,1,1},
  43. {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,4,4,4,4,4,4,4,4,4,4,8,8,8,8,8,8,8,8,8,8,1,1,1,1,1},
  44. {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,4,4,4,4,4,4,4,4,4,4,8,8,8,8,8,8,8,8,8,8,1,1,1,1,1},
  45. {1,1,1,1,1,1,1,1,1,1,1,1,1,4,4,4,4,4,4,4,4,4,4,4,8,8,8,8,8,8,8,8,8,8,8,1,1,1,1,1},
  46. {1,1,1,1,1,1,2,1,1,1,1,1,1,1,1,1,4,4,4,4,4,4,4,4,8,8,8,8,8,8,8,8,8,8,8,1,1,1,1,1},
  47. {1,1,1,1,1,1,2,1,1,1,1,1,1,1,1,1,4,4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,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
  72. {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
  73. {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
  74. {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
  75. {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1}
  76. }
  77.  
  78. function WeatherStep(imm)
  79. if ( getElementInterior(getLocalPlayer()) == 0 ) then -- if outside
  80. local hour, mins = getTime ()
  81. hour = hour * 2
  82. if (mins>=30) then
  83. hour = hour + 1
  84. end
  85. local x,y,z = getElementPosition(getLocalPlayer())
  86. local px = math.floor((x+4000)/200)
  87. local py = math.floor((y+4000)/200)
  88. if (px<1) then
  89. px = 1
  90. elseif (px>40) then
  91. px = 40
  92. end
  93.  
  94. if (py<1) then
  95. py = 1
  96. elseif (py>40) then
  97. py = 40
  98. end
  99. py = 41 - py
  100.  
  101. local zone = weat_zone[py][px]
  102. if (zone == 2) then
  103. weat = weat_city[hour]
  104. elseif (zone == 4) then
  105. weat = weat_desert[hour]
  106. elseif (zone == 8) then
  107. weat = weat_lv[hour]
  108. else
  109. weat = weat_green[hour]
  110. end
  111. -- cyclones
  112. local cyc_power = 0
  113. for i, cyc in pairs(cyclones) do
  114. if (cyc[3]>0) then
  115. local dist = getDistanceBetweenPoints2D (x, y, cyc[1], cyc[2])
  116. if (cyc[3]>600) then -- if radius more than 300
  117. if (dist<cyc[3]/4) then -- center of cyclone - rain
  118. cyc_power = math.max(cyc_power,3)
  119. elseif (dist<cyc[3]*1/2) then -- very cloudly
  120. cyc_power = math.max(cyc_power,2)
  121. elseif (dist<cyc[3]) then -- cloudly
  122. cyc_power = math.max(cyc_power,1)
  123. end
  124. else
  125. if (dist<cyc[3]/2) then --
  126. cyc_power = math.max(cyc_power,2)
  127. elseif (dist<cyc[3]) then --
  128. cyc_power = math.max(cyc_power,1)
  129. end
  130. end
  131. end
  132. end
  133.  
  134. if (cyc_power==3) then
  135. if (zone==4) then -- sandstorm
  136. weat = 18
  137. else
  138. weat = 8 -- rain
  139. end
  140. elseif (cyc_power==2) then
  141. if ((hour>2)and(hour<38)) then
  142. weat = 31 -- very cloudly
  143. else
  144. weat = 20
  145. end
  146. elseif (cyc_power==1) then
  147. weat = 7 -- cloudly
  148. end
  149.  
  150. if (imm==0) then
  151. --setWeatherBlended ( weat, delay ) -- ;( I need this function
  152. setWeather( weat )
  153. else
  154. setWeather( weat )
  155. end
  156. --a,b = getWeather()
  157. --outputChatBox(a.." "..b)
  158. --outputChatBox(zone)
  159. end
  160. end
  161.  
  162. function OnSpawn()
  163. if (source==getLocalPlayer()) then
  164. WeatherStep(1)
  165. end
  166. end
  167. addEventHandler ( "onClientPlayerSpawn", getLocalPlayer(), OnSpawn )
  168.  
  169. setTimer ( WeatherStep, 10000, 0, 0)
  170. function weatherConfig ()
  171. setTrafficLightsLocked(false)
  172. setMinuteDuration(60000)
  173. setTrafficLightState(9)
  174. end
  175. addEventHandler("onClientResourceStart",getRootElement(),weatherConfig)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement