add lightning.effect_range setting for audio and visuals range limiting

This commit is contained in:
Thomas Rudin 2019-10-12 10:53:46 +02:00 committed by sofar
parent 883a8484b5
commit 134f1e6371

View File

@ -19,6 +19,8 @@ lightning.range_v = 50
lightning.size = 100 lightning.size = 100
-- disable this to stop lightning mod from striking -- disable this to stop lightning mod from striking
lightning.auto = true lightning.auto = true
-- range of the skybox highlight and sound effect
lightning.effect_range = 500
local rng = PcgRandom(32321123312123) local rng = PcgRandom(32321123312123)
@ -127,7 +129,7 @@ lightning.strike = function(pos)
glow = 14, glow = 14,
}) })
minetest.sound_play({ pos = pos, name = "lightning_thunder", gain = 10, max_hear_distance = 500 }) minetest.sound_play({ pos = pos, name = "lightning_thunder", gain = 10, max_hear_distance = lightning.effect_range })
-- damage nearby objects, player or not -- damage nearby objects, player or not
for _, obj in ipairs(minetest.get_objects_inside_radius(pos, 5)) do for _, obj in ipairs(minetest.get_objects_inside_radius(pos, 5)) do
@ -138,14 +140,18 @@ lightning.strike = function(pos)
local playerlist = minetest.get_connected_players() local playerlist = minetest.get_connected_players()
for i = 1, #playerlist do for i = 1, #playerlist do
local player = playerlist[i] local player = playerlist[i]
local sky = {} local distance = vector.distance(player:get_pos(), pos)
sky.bgcolor, sky.type, sky.textures = player:get_sky() -- only affect players inside effect_range
if distance < lightning.effect_range then
local sky = {}
sky.bgcolor, sky.type, sky.textures = player:get_sky()
local name = player:get_player_name() local name = player:get_player_name()
if ps[name] == nil then if ps[name] == nil then
ps[name] = sky ps[name] = sky
player:set_sky(0xffffff, "plain", {}) player:set_sky(0xffffff, "plain", {})
end
end end
end end