Add sound buffer and different item collection sound

This commit is contained in:
jordan4ibanez 2021-04-03 20:39:08 -04:00
parent b14bc21829
commit c572db92aa
7 changed files with 47 additions and 5 deletions

View File

@ -1,3 +1,24 @@
--these are lua locals, used for higher performance
local minetest,math,vector,ipairs = minetest,math,vector,ipairs
--this is used for the player pool in the sound buffer
local pool = {}
local tick = false
local name
minetest.register_on_joinplayer(function(player)
name = player:get_player_name()
pool[name] = 0
end)
local name
minetest.register_on_leaveplayer(function(player)
name = player:get_player_name()
pool[name] = nil
end)
local has_awards = minetest.get_modpath("awards") local has_awards = minetest.get_modpath("awards")
local mcl_item_entity = {} local mcl_item_entity = {}
@ -77,8 +98,30 @@ end
minetest.register_globalstep(function(dtime) minetest.register_globalstep(function(dtime)
tick = not tick
for _,player in pairs(minetest.get_connected_players()) do for _,player in pairs(minetest.get_connected_players()) do
if player:get_hp() > 0 or not minetest.settings:get_bool("enable_damage") then if player:get_hp() > 0 or not minetest.settings:get_bool("enable_damage") then
local name = player:get_player_name()
if tick == true and pool[name] > 0 then
minetest.sound_play("item_drop_pickup", {
pos = pos,
gain = 1,
max_hear_distance = 16,
pitch = math.random(60,100)/100
})
if pool[name] > 6 then
pool[name] = 6
else
pool[name] = pool[name] - 1
end
end
local pos = player:get_pos() local pos = player:get_pos()
local inv = player:get_inventory() local inv = player:get_inventory()
local checkpos = {x=pos.x,y=pos.y + item_drop_settings.player_collect_height,z=pos.z} local checkpos = {x=pos.x,y=pos.y + item_drop_settings.player_collect_height,z=pos.z}
@ -94,11 +137,7 @@ minetest.register_globalstep(function(dtime)
-- Ignore if itemstring is not set yet -- Ignore if itemstring is not set yet
if object:get_luaentity().itemstring ~= "" then if object:get_luaentity().itemstring ~= "" then
inv:add_item("main", ItemStack(object:get_luaentity().itemstring)) inv:add_item("main", ItemStack(object:get_luaentity().itemstring))
minetest.sound_play("item_drop_pickup", {
pos = pos,
max_hear_distance = 16,
gain = 1.0,
}, true)
check_pickup_achievements(object, player) check_pickup_achievements(object, player)
-- Destroy entity -- Destroy entity
@ -111,6 +150,8 @@ minetest.register_globalstep(function(dtime)
object:move_to(checkpos) object:move_to(checkpos)
pool[name] = pool[name] + 1
minetest.after(0.25, function() minetest.after(0.25, function()
--safety check --safety check
if object and object:get_luaentity() then if object and object:get_luaentity() then

View File

@ -0,0 +1 @@
Item_Drop_Pickup - https://freesound.org/people/benniknop/sounds/317848/ (License: CC0)