Advertisement
Guest User

Untitled

a guest
Aug 27th, 2012
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.44 KB | None | 0 0
  1. local rain_height = 50
  2. local raining = false
  3.  
  4. local sound_handler = nil
  5.  
  6. local timer_step = 0
  7. local timer_step2 = 0
  8. --[[minetest.register_globalstep(function(dtime)
  9.     if raining then
  10.         timer_step2 = timer_step2+1
  11.         if timer_step2 >= 2 then
  12.             rain_height = 0
  13.             for _,player in ipairs(minetest.get_connected_players()) do
  14.                 local pos = player:getpos().y+20
  15.                 if pos>rain_height then
  16.                     rain_height = pos
  17.                 end
  18.                 if rain_height > 100 then
  19.                     rain_height = 100
  20.                 end
  21.                 rain_height = math.floor(rain_height+0.5)
  22.             end
  23.             timer_step2 = 0
  24.         end
  25.         timer_step = timer_step+dtime
  26.         if timer_step >= 20 then
  27.             --if math.random(1, 100) <= 20 then
  28.             --  raining = false
  29.             --  if sound_handler ~= nil then
  30.             --      minetest.sound_stop(sound_handler)
  31.             --      sound_handler = nil
  32.             --  end
  33.             --end
  34.             timer_step = 0
  35.         end
  36.     else
  37.         timer_step = timer_step+dtime
  38.         if timer_step >= 20 then
  39.             --if math.random(1, 100) <= 5 then
  40.             --  raining = true
  41.             --  sound_handler = minetest.sound_play("weather_rain.ogg", {loop = true})
  42.             --end
  43.             timer_step = 0
  44.         end
  45.     end
  46. end)]]
  47.  
  48. minetest.register_node("weather:rain_1", {
  49.     description = "Rain",
  50.     drawtype = "torchlike",
  51.     tiles = {{name="weather_rain_1_animated.png", animation={type="vertical_frames", aspect_w=32, aspect_h=32, length=0.3}}},
  52.     walkable = false,
  53.     paramtype = "light",
  54.     sunlight_propagates = true,
  55.     buildable_to = true,
  56.     pointable = false,
  57.     groups = {dig_immediate=2},
  58. })
  59.    
  60. minetest.register_node("weather:rain_2", {
  61.     description = "Rain",
  62.     drawtype = "torchlike",
  63.     tiles = {{name="weather_rain_2_animated.png", animation={type="vertical_frames", aspect_w=32, aspect_h=32, length=0.3}}},
  64.     walkable = false,
  65.     paramtype = "light",
  66.     sunlight_propagates = true,
  67.     buildable_to = true,
  68.     pointable = false,
  69.     groups = {dig_immediate=2},
  70. })
  71.  
  72. local add = {}
  73. minetest.register_globalstep(function(dtime)
  74.     local pos = add[1]
  75.     if pos == nil then
  76.         return
  77.     end
  78.     minetest.register_node(pos, {name="weather:rain_"..math.random(1,2)})
  79.     table.remove(add, 1)
  80. end)
  81.  
  82. minetest.register_abm({
  83.     nodenames = {"weather:rain_1", "weather:rain_2"},
  84.     interval = 1,
  85.     chance = 10,
  86.     action = function(pos, node)
  87.         --[[if pos.y > rain_height then
  88.             minetest.env:remove_node(pos)
  89.             return
  90.         end
  91.         if raining then
  92.             local pos2 = pos
  93.             pos2.y = pos2.y+1
  94.             if pos2.y<>TODO rain_height and  not string.find(minetest.env:get_node(pos2).name, "weather:rain_") then
  95.                 minetest.env:remove_node(pos)
  96.                 pos.y = pos.y-1
  97.                 local i=0
  98.                 while i<10 and string.find(minetest.env:get_node(pos).name, "weather:rain_") do
  99.                     minetest.env:remove_node(pos)
  100.                     pos.y = pos.y+1
  101.                     i = i+1
  102.                 end
  103.                 return
  104.             end
  105.             pos.y = pos.y-1
  106.             if minetest.env:get_node(pos).name == "air" then
  107.                 minetest.env:set_node(pos, {name="weather:rain_"..math.random(1,2)})
  108.                 pos.y = pos.y-1
  109.                 local i=0
  110.                 while i<10 and minetest.env:get_node(pos).name == "air" do
  111.                     minetest.env:set_node(pos, {name="weather:rain_"..math.random(1,2)})
  112.                     pos.y = pos.y-1
  113.                     i = i+1
  114.                 end
  115.             end
  116.         else
  117.             minetest.env:remove_node(pos)
  118.             pos.y = pos.y-1
  119.             local i=0
  120.             while i<10 and string.find(minetest.env:get_node(pos).name, "weather:rain_") do
  121.                 minetest.env:remove_node(pos)
  122.                 pos.y = pos.y-1
  123.                 i = i+1
  124.             end
  125.         end]]
  126.         pos.y = pos.y-1
  127.         local node = minetest.env:get_node(pos)
  128.         if node.name == "air" then
  129.             table.insert(add, pos)
  130.         end
  131.     end
  132. })
  133.  
  134. minetest.register_abm({
  135.     nodenames = {"air"},
  136.     interval = 1,
  137.     chance = 2,
  138.     action = function(pos, node)
  139.         if not raining then
  140.             return
  141.         end
  142.         if pos.y ~= rain_height then
  143.             return
  144.         end
  145.         table.insert(add, pos)
  146.     end
  147. })
  148.  
  149. minetest.register_chatcommand("rain", {
  150.     description = "Start/Stop raining",
  151.     privs = {settime = true},
  152.     func = function(name, param)
  153.         if raining then
  154.             raining = false
  155.             if sound_handler ~= nil then
  156.                 minetest.sound_stop(sound_handler)
  157.                 sound_handler = nil
  158.             end
  159.             minetest.chat_send_player(name, "Stop raining")
  160.         else
  161.             raining = true
  162.             --[[rain_height = 0
  163.             for _,player in ipairs(minetest.get_connected_players()) do
  164.                 local pos = player:getpos().y+20
  165.                 if pos>rain_height then
  166.                     rain_height = pos
  167.                 end
  168.                 if rain_height > 100 then
  169.                     rain_height = 100
  170.                 end
  171.                 rain_height = math.floor(rain_height+0.5)
  172.             end]]
  173.             sound_handler = minetest.sound_play("weather_rain", {loop = true})
  174.             minetest.chat_send_player(name, "Start raining")
  175.         end
  176.     end
  177. })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement