add sound at jetpack #29

Merged
mrkubax10 merged 4 commits from Kindaglia/industrialtest:sound into master 2025-04-25 10:48:51 +02:00
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 = {}

Rename to soundHandles

Rename to `soundHandles`

i rename JetpackLoop to industrialtest_jetpack_loop an replace sound with sound freecopiright with Creative Commons license (https://freesound.org/people/velcronator/sounds/733985/?)

i rename JetpackLoop to industrialtest_jetpack_loop an replace sound with sound freecopiright with Creative Commons license (https://freesound.org/people/velcronator/sounds/733985/?)

Sure

Sure
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