diff --git a/.luacheckrc b/.luacheckrc new file mode 100644 index 0000000..e4991d5 --- /dev/null +++ b/.luacheckrc @@ -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" +} diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..1fb315e --- /dev/null +++ b/.travis.yml @@ -0,0 +1,11 @@ +language: generic +addons: + apt: + packages: + - luarocks +before_install: + - luarocks install --local luacheck +script: +- $HOME/.luarocks/bin/luacheck ./ +notifications: + email: false diff --git a/depends.txt b/depends.txt deleted file mode 100644 index 09060cc..0000000 --- a/depends.txt +++ /dev/null @@ -1,2 +0,0 @@ -default? -fire? diff --git a/description.txt b/description.txt deleted file mode 100644 index 98fdb36..0000000 --- a/description.txt +++ /dev/null @@ -1 +0,0 @@ -A mod that adds thunder and lightning effects. diff --git a/init.lua b/init.lua index 3ed0c3a..59198fd 100644 --- a/init.lua +++ b/init.lua @@ -19,9 +19,12 @@ 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 rng = PcgRandom(32321123312123) +-- table with playername as key and previous skybox as value local ps = {} local ttl = 1 @@ -34,9 +37,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 +63,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 +129,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 +140,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 @@ -217,7 +227,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) diff --git a/mod.conf b/mod.conf index 948a407..1b5815a 100644 --- a/mod.conf +++ b/mod.conf @@ -1 +1,3 @@ name = lightning +optional_depends = default, fire +description = A mod that adds thunder and lightning effects. \ No newline at end of file