Compare commits

...

8 Commits

7 changed files with 61 additions and 16 deletions

19
.luacheckrc Normal file
View File

@ -0,0 +1,19 @@
globals = {
"lightning"
}
read_globals = {
-- Stdlib
string = {fields = {"split"}},
table = {fields = {"copy", "getn"}},
"PcgRandom",
-- Minetest
"minetest",
"vector", "ItemStack",
"dump",
-- mods
"default", "fire"
}

11
.travis.yml Normal file
View File

@ -0,0 +1,11 @@
language: generic
addons:
apt:
packages:
- luarocks
before_install:
- luarocks install --local luacheck
script:
- $HOME/.luarocks/bin/luacheck ./
notifications:
email: false

View File

@ -1,2 +0,0 @@
default?
fire?

View File

@ -1 +0,0 @@
A mod that adds thunder and lightning effects.

View File

@ -19,9 +19,14 @@ lightning.range_v = 50
lightning.size = 100
-- disable this to stop lightning mod from striking
lightning.auto = true
-- range of the skybox highlight and sound effect
lightning.effect_range = 500
local random_fire = minetest.settings:get_bool("lightning_random_fire") ~= false
local rng = PcgRandom(32321123312123)
-- table with playername as key and previous skybox as value
local ps = {}
local ttl = 1
@ -34,9 +39,12 @@ local revertsky = function()
return
end
for key, entry in pairs(ps) do
local sky = entry.sky
entry.p:set_sky(sky.bgcolor, sky.type, sky.textures)
for playername, sky in pairs(ps) do
local player = minetest.get_player_by_name(playername)
-- check if the player is still online
if player then
player:set_sky(sky.bgcolor, sky.type, sky.textures)
end
end
ps = {}
@ -57,7 +65,7 @@ local function choose_pos(pos)
local r = rng:next(1, playercount)
local randomplayer = playerlist[r]
pos = randomplayer:getpos()
pos = randomplayer:get_pos()
-- avoid striking underground
if pos.y < -20 then
@ -123,7 +131,7 @@ lightning.strike = function(pos)
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
for _, obj in ipairs(minetest.get_objects_inside_radius(pos, 5)) do
@ -134,14 +142,18 @@ lightning.strike = function(pos)
local playerlist = minetest.get_connected_players()
for i = 1, #playerlist do
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()
if ps[name] == nil then
ps[name] = {p = player, sky = sky}
player:set_sky(0xffffff, "plain", {})
local name = player:get_player_name()
if ps[name] == nil then
ps[name] = sky
player:set_sky(0xffffff, "plain", {})
end
end
end
@ -157,7 +169,7 @@ lightning.strike = function(pos)
return
end
-- very rarely, potentially cause a fire
if fire and rng:next(1,1000) == 1 then
if fire and random_fire and rng:next(1,1000) == 1 then
minetest.set_node(pos2, {name = "fire:basic_flame"})
else
minetest.set_node(pos2, {name = "lightning:dying_flame"})
@ -217,7 +229,7 @@ minetest.register_node("lightning:dying_flame", {
})
-- if other mods disable auto lightning during initialization, don't trigger the first lightning.
minetest.after(5, function(dtime)
minetest.after(5, function()
if lightning.auto then
minetest.after(rng:next(lightning.interval_low,
lightning.interval_high), lightning.strike)

View File

@ -1 +1,3 @@
name = lightning
optional_depends = default, fire
description = A mod that adds thunder and lightning effects.

4
settingtypes.txt Normal file
View File

@ -0,0 +1,4 @@
# When fire is enabled, this setting specifies whether the lightnings
# have a small chance to start a fire.
# Value 'false' will disable fire caused by lightnings.
lightning_random_fire (Enable random fire) bool true