Merge pull request 'add sound at jetpack' (#29) from Kindaglia/industrialtest:sound into master

This commit is contained in:
mrkubax10 2025-04-25 10:48:46 +02:00
commit 5898cc4e1c
2 changed files with 20 additions and 2 deletions

Binary file not shown.

View File

@ -19,12 +19,30 @@ industrialtest.JetpackBase=table.copy(industrialtest.GearTool)
industrialtest.internal.unpackTableInto(industrialtest.JetpackBase,{
part="torso"
})
local soundHandles = {}
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 soundHandles[playerName] then
local pos = player:get_pos()
local handle = minetest.sound_play("industrialtest_jetpack_loop", {
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
})
soundHandles[playerName] = handle
end
return true
else
if soundHandles[playerName] then
minetest.sound_stop(soundHandles[playerName])
soundHandles[playerName] = nil
end
end
return false
end