From 3136adbe00c2f42a52caf371429a7ad22a54e3ab Mon Sep 17 00:00:00 2001 From: BuckarooBanzay Date: Fri, 11 Oct 2019 08:12:18 +0200 Subject: [PATCH 1/5] add .luacheckrc and fix common errors --- .luacheckrc | 19 +++++++++++++++++++ init.lua | 4 ++-- 2 files changed, 21 insertions(+), 2 deletions(-) create mode 100644 .luacheckrc 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/init.lua b/init.lua index 27ab412..b24d6c4 100644 --- a/init.lua +++ b/init.lua @@ -34,7 +34,7 @@ local revertsky = function() return end - for key, entry in pairs(ps) do + for _, entry in pairs(ps) do local sky = entry.sky entry.p:set_sky(sky.bgcolor, sky.type, sky.textures) end @@ -217,7 +217,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) From 883a8484b5dd43be50c0d8bc60db125ff225b260 Mon Sep 17 00:00:00 2001 From: BuckarooBanzay Date: Fri, 11 Oct 2019 08:32:03 +0200 Subject: [PATCH 2/5] fix stored player object, use name instead --- init.lua | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/init.lua b/init.lua index b24d6c4..e62a3f7 100644 --- a/init.lua +++ b/init.lua @@ -22,6 +22,7 @@ lightning.auto = true local rng = PcgRandom(32321123312123) +-- table with playername as key and previous skybox as value local ps = {} local ttl = 1 @@ -34,9 +35,12 @@ local revertsky = function() return end - for _, 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 = {} @@ -140,7 +144,7 @@ lightning.strike = function(pos) local name = player:get_player_name() if ps[name] == nil then - ps[name] = {p = player, sky = sky} + ps[name] = sky player:set_sky(0xffffff, "plain", {}) end end From 134f1e6371a1825fc387f0e47196093771642b4c Mon Sep 17 00:00:00 2001 From: Thomas Rudin Date: Sat, 12 Oct 2019 10:53:46 +0200 Subject: [PATCH 3/5] add lightning.effect_range setting for audio and visuals range limiting --- init.lua | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/init.lua b/init.lua index e62a3f7..cad2988 100644 --- a/init.lua +++ b/init.lua @@ -19,6 +19,8 @@ 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) @@ -127,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 @@ -138,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] = 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 From 2183978c6fb8f927132a3baa2a03064a84b41267 Mon Sep 17 00:00:00 2001 From: Thomas Rudin Date: Sat, 12 Oct 2019 11:01:32 +0200 Subject: [PATCH 4/5] add .travis.yml --- .travis.yml | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 .travis.yml 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 From 01f2b9c89da1a6e97e5763518ad0f34f4a84236a Mon Sep 17 00:00:00 2001 From: Panquesito7 Date: Tue, 15 Oct 2019 19:59:50 -0500 Subject: [PATCH 5/5] Use mod.conf for dependencies and description --- depends.txt | 2 -- description.txt | 1 - init.lua | 4 ++-- mod.conf | 2 ++ 4 files changed, 4 insertions(+), 5 deletions(-) delete mode 100644 depends.txt delete mode 100644 description.txt 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 cad2988..e254d22 100644 --- a/init.lua +++ b/init.lua @@ -63,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 @@ -232,4 +232,4 @@ minetest.after(5, function() minetest.after(rng:next(lightning.interval_low, lightning.interval_high), lightning.strike) end -end) +end) \ No newline at end of file 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