From 5f5dc94dec368c1dbc08f3bee7c2841b15000e30 Mon Sep 17 00:00:00 2001 From: LoneWolfHT Date: Thu, 5 Dec 2024 16:04:21 -0800 Subject: [PATCH] Add a player setting to control the amount of snow particles --- .luacheckrc | 3 +- snow/init.lua | 104 ++++++++++++++++++++++++++++++++++++-------------- snow/mod.conf | 1 + 3 files changed, 78 insertions(+), 30 deletions(-) diff --git a/.luacheckrc b/.luacheckrc index 9428e75..8a8f545 100644 --- a/.luacheckrc +++ b/.luacheckrc @@ -3,7 +3,8 @@ unused_args = false globals = { "snow", "winterize", "minetest", "throwable_snow", "default", - "ctf_teams", "hud_events", "skybox" + "ctf_teams", "hud_events", "skybox", + "ctf_settings", } read_globals = { diff --git a/snow/init.lua b/snow/init.lua index 473ebb3..10795e9 100644 --- a/snow/init.lua +++ b/snow/init.lua @@ -1,13 +1,11 @@ if os.date("%m") ~= "12" then return end --- Particlespawner attachment is currently broken, so the following code positions a --- particle spawner which lasts for 1.4s every 0.7s for each player. The spawners are --- bound to individual players - snow = { SPAWN_SNOW = false, } +local spawners = {} + -- Set clouds for normal skybox local old_clear = skybox.clear skybox.clear = function(player) @@ -33,39 +31,87 @@ end -- Spawns snow particles around player local function spawn_particles(player) - minetest.add_particlespawner({ - amount = 6 * 60, - minpos = vector.new(-25, 10, -25), - maxpos = vector.new( 25, 25, 25), - minvel = vector.new(-2, -7, -2), - maxvel = vector.new(-2, -9, -2), - time = math.random(60, 90), - minexptime = 10, - maxexptime = 10, - minsize = 1, - maxsize = 3, - collisiondetection = true, - collision_removal = true, - object_collision = true, - vertical = false, - texture = ("[combine:7x7:%s,%s=snow_snowflakes.png"):format(math.random(0, 3) * -7, math.random(0, 1) * -7), - playername = player:get_player_name(), - attached = player, - glow = 2 - }) + local name = player:get_player_name() + local amount = 6 * 60 + + if ctf_settings then + amount = amount * tonumber(ctf_settings.settings["snow:particle_amount"]._list_map[ + tonumber(ctf_settings.get(player, "snow:particle_amount")) + ]) + end + + if amount > 0 then + local time = math.random(60, 90) + + spawners[name] = { + id = minetest.add_particlespawner({ + amount = amount, + minpos = vector.new(-25, 10, -25), + maxpos = vector.new( 25, 25, 25), + minvel = vector.new(-2, -7, -2), + maxvel = vector.new(-2, -9, -2), + time = time, + minexptime = 10, + maxexptime = 10, + minsize = 1, + maxsize = 3, + collisiondetection = true, + collision_removal = true, + object_collision = true, + vertical = false, + texture = ("[combine:7x7:%s,%s=snow_snowflakes.png"):format(math.random(0, 3) * -7, math.random(0, 1) * -7), + playername = name, + attached = player, + glow = 2 + }), + timer = minetest.after(time-1, function() + spawners[name] = nil + end) + } + else + spawners[name] = nil + end end local spawner_step = 50 minetest.register_globalstep(function(dtime) + if not snow.SPAWN_SNOW then return end + if spawner_step >= 60 then - if snow.SPAWN_SNOW then - spawner_step = 0 + spawner_step = 0 - for _, player in pairs(minetest.get_connected_players()) do - spawn_particles(player) - end + for _, player in pairs(minetest.get_connected_players()) do + spawn_particles(player) end else spawner_step = spawner_step + dtime end end) + +if ctf_settings then + ctf_settings.register("snow:particle_amount", { + type = "list", + description = "How much falling snow to spawn around you", + list = { + "Snow Particles - Default", + "Snow Particles - None", + "Snow Particles - 0.5x", + "Snow Particles - 2x", + "Snow Particles - 5x", + "Snow Particles - 10x", + "Snow Particles - 20x", + }, + _list_map = {1, 0, 0.5, 2, 5, 10, 20}, + default = "1", -- "Snow Particles - Default" + on_change = function(player, new_value) + local name = player:get_player_name() + + if spawners[name] then + minetest.delete_particlespawner(spawners[name].id) + spawners[name].timer:cancel() + end + + spawn_particles(player) + end + }) +end \ No newline at end of file diff --git a/snow/mod.conf b/snow/mod.conf index a883a7c..51f558f 100644 --- a/snow/mod.conf +++ b/snow/mod.conf @@ -1,2 +1,3 @@ name = snow depends = skybox +optional_depends = ctf_settings