From 68abb4d08e4a1461d03b4750beeb11fecb5855fe Mon Sep 17 00:00:00 2001 From: Kindaglia Date: Thu, 24 Apr 2025 21:12:15 +0200 Subject: [PATCH] add sound jetpack --- tools/jetpack.lua | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/tools/jetpack.lua b/tools/jetpack.lua index 16545ca..cdaff83 100644 --- a/tools/jetpack.lua +++ b/tools/jetpack.lua @@ -19,12 +19,30 @@ industrialtest.JetpackBase=table.copy(industrialtest.GearTool) industrialtest.internal.unpackTableInto(industrialtest.JetpackBase,{ part="torso" }) +local sound_handles = {} -function industrialtest.JetpackBase.update(self,player,inv,itemstack,dtime) - local control=player:get_player_control() +function industrialtest.JetpackBase.update(self, player, inv, itemstack, dtime) + local playerName = player:get_player_name() + local control = player:get_player_control() if control.jump and self:tryFly(itemstack) then self.addYVelocityClamped(player,1,10) + if not sound_handles[playerName] then + local pos = player:get_pos() + local handle = minetest.sound_play("JetpackLoop", { + pos = pos, + gain = 1.0, -- Volume of the sound + max_hear_distance = 16, -- Maximum distance to hear the sound + object = player, -- Attach the sound to the player + loop = true, -- The sound is played in a loop + }) + sound_handles[playerName] = handle + end return true + else + if sound_handles[playerName] then + minetest.sound_stop(sound_handles[playerName]) + sound_handles[playerName] = nil + end end return false end