forked from MineClone5/MineClone5
Merge pull request 'Add sound buffer and different item collection sound' (#1453) from jordan4ibanez/MineClone2-PopSounds:master into master
Reviewed-on: MineClone2/MineClone2#1453
This commit is contained in:
commit
bb6cce06e5
|
@ -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
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
Item_Drop_Pickup - https://freesound.org/people/benniknop/sounds/317848/ (License: CC0)
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading…
Reference in New Issue