Merge branch 'master' of yunohost.local:minetest-mods/lightning into nalc-1.2-dev

This commit is contained in:
Sys Quatre 2019-12-22 13:39:44 +01:00
commit 2040363297
6 changed files with 54 additions and 15 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,12 @@ 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)
-- table with playername as key and previous skybox as value
local ps = {} local ps = {}
local ttl = 1 local ttl = 1
@ -34,9 +37,12 @@ local revertsky = function()
return return
end end
for key, entry in pairs(ps) do for playername, sky in pairs(ps) do
local sky = entry.sky local player = minetest.get_player_by_name(playername)
entry.p:set_sky(sky.bgcolor, sky.type, sky.textures) -- check if the player is still online
if player then
player:set_sky(sky.bgcolor, sky.type, sky.textures)
end
end end
ps = {} ps = {}
@ -57,7 +63,7 @@ local function choose_pos(pos)
local r = rng:next(1, playercount) local r = rng:next(1, playercount)
local randomplayer = playerlist[r] local randomplayer = playerlist[r]
pos = randomplayer:getpos() pos = randomplayer:get_pos()
-- avoid striking underground -- avoid striking underground
if pos.y < -20 then if pos.y < -20 then
@ -123,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
@ -134,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] = {p = player, sky = sky} ps[name] = sky
player:set_sky(0xffffff, "plain", {}) player:set_sky(0xffffff, "plain", {})
end
end end
end end
@ -217,7 +227,7 @@ minetest.register_node("lightning:dying_flame", {
}) })
-- if other mods disable auto lightning during initialization, don't trigger the first lightning. -- 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 if lightning.auto then
minetest.after(rng:next(lightning.interval_low, minetest.after(rng:next(lightning.interval_low,
lightning.interval_high), lightning.strike) lightning.interval_high), lightning.strike)

View File

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