add sound jetpack

This commit is contained in:
Kindaglia 2025-04-24 21:12:15 +02:00
parent f1d8d5060c
commit 68abb4d08e

View File

@ -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