From 44200386f951bc7d864b35194d0b16ed9862a7f0 Mon Sep 17 00:00:00 2001 From: LoneWolfHT Date: Sat, 24 Nov 2018 08:08:16 -0800 Subject: [PATCH] Added trailing smoke particles to the smoke grenade when thrown --- API.md | 5 +++-- depends.txt | 1 + grenades.lua | 7 ++++--- init.lua | 10 +++++++++- 4 files changed, 17 insertions(+), 6 deletions(-) create mode 100644 depends.txt diff --git a/API.md b/API.md index 61dc725..189856c 100644 --- a/API.md +++ b/API.md @@ -18,6 +18,7 @@ Still WIP. Please suggest new features here: https://forum.minetest.net/viewtopi image = "grenades_smoke.png", -- The particle's image life = 1, -- How long (seconds) it takes for the particle to disappear size = 4, -- Size of the particle - glow = 0, -- brightens the texture in darkness + glow = 0, -- Brightens the texture in darkness + interval = 5, -- How long it takes before a particle can be added } - })` \ No newline at end of file + })` diff --git a/depends.txt b/depends.txt new file mode 100644 index 0000000..331d858 --- /dev/null +++ b/depends.txt @@ -0,0 +1 @@ +default \ No newline at end of file diff --git a/grenades.lua b/grenades.lua index fe76c9d..048ec01 100644 --- a/grenades.lua +++ b/grenades.lua @@ -116,6 +116,7 @@ if not smoke or smoke == true then life = 1, size = 4, glow = 0, + interval = 5, } }) end @@ -130,7 +131,7 @@ if not settings:get_bool("enable_grenade_recipes") or settings:get_bool("enable_ if not regular or regular == true then minetest.register_craft({ - type = "shapeless", + type = "shaped", output = "grenades:grenade_regular", recipe = { {"", "default:steel_ingot", ""}, @@ -144,7 +145,7 @@ if not settings:get_bool("enable_grenade_recipes") or settings:get_bool("enable_ if not smoke or smoke == true then minetest.register_craft({ - type = "shapeless", + type = "shaped", output = "grenades:grenade_smoke", recipe = { {"", "default:steel_ingot", ""}, @@ -158,7 +159,7 @@ if not settings:get_bool("enable_grenade_recipes") or settings:get_bool("enable_ if not flash or flash == true then minetest.register_craft({ - type = "shapeless", + type = "shaped", output = "grenades:grenade_flashbang", recipe = { {"", "default:steel_ingot", ""}, diff --git a/init.lua b/init.lua index e862ca3..6840327 100644 --- a/init.lua +++ b/init.lua @@ -28,13 +28,19 @@ function grenades.register_grenade(name, def) local node = minetest.get_node(pos) local obj = self.object + if self.particle == nil then + self.particle = 0 + end + if self.timer then self.timer = self.timer + dtime else self.timer = dtime end - if def.particle then + if def.particle and self.particle >= 4 then + self.particle = 0 + minetest.add_particle({ pos = obj:get_pos(), velocity = vector.divide(obj:get_velocity(), 2), @@ -47,6 +53,8 @@ function grenades.register_grenade(name, def) texture = def.particle.image, glow = def.particle.glow }) + elseif def.particle and self.particle < def.particle.interval then + self.particle = self.particle + 1 end if self.timer > def.timeout or node.name ~= "air" then