Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local rain_height = 50
- local raining = false
- local sound_handler = nil
- local timer_step = 0
- local timer_step2 = 0
- --[[minetest.register_globalstep(function(dtime)
- if raining then
- timer_step2 = timer_step2+1
- if timer_step2 >= 2 then
- rain_height = 0
- for _,player in ipairs(minetest.get_connected_players()) do
- local pos = player:getpos().y+20
- if pos>rain_height then
- rain_height = pos
- end
- if rain_height > 100 then
- rain_height = 100
- end
- rain_height = math.floor(rain_height+0.5)
- end
- timer_step2 = 0
- end
- timer_step = timer_step+dtime
- if timer_step >= 20 then
- --if math.random(1, 100) <= 20 then
- -- raining = false
- -- if sound_handler ~= nil then
- -- minetest.sound_stop(sound_handler)
- -- sound_handler = nil
- -- end
- --end
- timer_step = 0
- end
- else
- timer_step = timer_step+dtime
- if timer_step >= 20 then
- --if math.random(1, 100) <= 5 then
- -- raining = true
- -- sound_handler = minetest.sound_play("weather_rain.ogg", {loop = true})
- --end
- timer_step = 0
- end
- end
- end)]]
- minetest.register_node("weather:rain_1", {
- description = "Rain",
- drawtype = "torchlike",
- tiles = {{name="weather_rain_1_animated.png", animation={type="vertical_frames", aspect_w=32, aspect_h=32, length=0.3}}},
- walkable = false,
- paramtype = "light",
- sunlight_propagates = true,
- buildable_to = true,
- pointable = false,
- groups = {dig_immediate=2},
- })
- minetest.register_node("weather:rain_2", {
- description = "Rain",
- drawtype = "torchlike",
- tiles = {{name="weather_rain_2_animated.png", animation={type="vertical_frames", aspect_w=32, aspect_h=32, length=0.3}}},
- walkable = false,
- paramtype = "light",
- sunlight_propagates = true,
- buildable_to = true,
- pointable = false,
- groups = {dig_immediate=2},
- })
- local add = {}
- minetest.register_globalstep(function(dtime)
- local pos = add[1]
- if pos == nil then
- return
- end
- minetest.register_node(pos, {name="weather:rain_"..math.random(1,2)})
- table.remove(add, 1)
- end)
- minetest.register_abm({
- nodenames = {"weather:rain_1", "weather:rain_2"},
- interval = 1,
- chance = 10,
- action = function(pos, node)
- --[[if pos.y > rain_height then
- minetest.env:remove_node(pos)
- return
- end
- if raining then
- local pos2 = pos
- pos2.y = pos2.y+1
- if pos2.y<>TODO rain_height and not string.find(minetest.env:get_node(pos2).name, "weather:rain_") then
- minetest.env:remove_node(pos)
- pos.y = pos.y-1
- local i=0
- while i<10 and string.find(minetest.env:get_node(pos).name, "weather:rain_") do
- minetest.env:remove_node(pos)
- pos.y = pos.y+1
- i = i+1
- end
- return
- end
- pos.y = pos.y-1
- if minetest.env:get_node(pos).name == "air" then
- minetest.env:set_node(pos, {name="weather:rain_"..math.random(1,2)})
- pos.y = pos.y-1
- local i=0
- while i<10 and minetest.env:get_node(pos).name == "air" do
- minetest.env:set_node(pos, {name="weather:rain_"..math.random(1,2)})
- pos.y = pos.y-1
- i = i+1
- end
- end
- else
- minetest.env:remove_node(pos)
- pos.y = pos.y-1
- local i=0
- while i<10 and string.find(minetest.env:get_node(pos).name, "weather:rain_") do
- minetest.env:remove_node(pos)
- pos.y = pos.y-1
- i = i+1
- end
- end]]
- pos.y = pos.y-1
- local node = minetest.env:get_node(pos)
- if node.name == "air" then
- table.insert(add, pos)
- end
- end
- })
- minetest.register_abm({
- nodenames = {"air"},
- interval = 1,
- chance = 2,
- action = function(pos, node)
- if not raining then
- return
- end
- if pos.y ~= rain_height then
- return
- end
- table.insert(add, pos)
- end
- })
- minetest.register_chatcommand("rain", {
- description = "Start/Stop raining",
- privs = {settime = true},
- func = function(name, param)
- if raining then
- raining = false
- if sound_handler ~= nil then
- minetest.sound_stop(sound_handler)
- sound_handler = nil
- end
- minetest.chat_send_player(name, "Stop raining")
- else
- raining = true
- --[[rain_height = 0
- for _,player in ipairs(minetest.get_connected_players()) do
- local pos = player:getpos().y+20
- if pos>rain_height then
- rain_height = pos
- end
- if rain_height > 100 then
- rain_height = 100
- end
- rain_height = math.floor(rain_height+0.5)
- end]]
- sound_handler = minetest.sound_play("weather_rain", {loop = true})
- minetest.chat_send_player(name, "Start raining")
- end
- end
- })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement