Play armor equip sound when armor got dispensed

This commit is contained in:
Wuzzy 2020-02-18 22:33:58 +01:00
parent 6426e55746
commit 565806558c
3 changed files with 15 additions and 16 deletions

View file

@ -169,6 +169,7 @@ local dispenserdef = {
minetest.registered_nodes["mcl_armor_stand:armor_stand"].on_metadata_inventory_put(standpos) minetest.registered_nodes["mcl_armor_stand:armor_stand"].on_metadata_inventory_put(standpos)
stack:take_item() stack:take_item()
inv:set_stack("main", stack_id, stack) inv:set_stack("main", stack_id, stack)
armor:play_equip_sound(dropitem, nil, standpos)
armor_dispensed = true armor_dispensed = true
end end
else else
@ -202,6 +203,7 @@ local dispenserdef = {
pinv:set_stack("armor", armor_slot, dropitem) pinv:set_stack("armor", armor_slot, dropitem)
armor:set_player_armor(player) armor:set_player_armor(player)
armor:update_inventory(player) armor:update_inventory(player)
armor:play_equip_sound(dropitem, player)
stack:take_item() stack:take_item()
inv:set_stack("main", stack_id, stack) inv:set_stack("main", stack_id, stack)

View file

@ -73,21 +73,14 @@ function armor.on_armor_use(itemstack, user, pointed_thing)
player_inv:set_stack("armor", slot, itemstack_single) player_inv:set_stack("armor", slot, itemstack_single)
armor:set_player_armor(user) armor:set_player_armor(user)
armor:update_inventory(user) armor:update_inventory(user)
armor:play_equip_sound(user, itemstack_single) armor:play_equip_sound(itemstack_single, user)
itemstack:take_item() itemstack:take_item()
elseif itemstack:get_count() <= 1 then elseif itemstack:get_count() <= 1 then
armor_inv:set_stack("armor", slot, itemstack_single) armor_inv:set_stack("armor", slot, itemstack_single)
player_inv:set_stack("armor", slot, itemstack_single) player_inv:set_stack("armor", slot, itemstack_single)
armor:set_player_armor(user) armor:set_player_armor(user)
armor:update_inventory(user) armor:update_inventory(user)
armor:play_equip_sound(user, itemstack_single) armor:play_equip_sound(itemstack_single, user)
itemstack = ItemStack(itemstack_slot)
elseif itemstack:get_count() <= 1 then
armor_inv:set_stack("armor", slot, itemstack_single)
player_inv:set_stack("armor", slot, itemstack_single)
armor:set_player_armor(user)
armor:update_inventory(user)
armor:play_equip_sound(user, itemstack_single)
itemstack = ItemStack(itemstack_slot) itemstack = ItemStack(itemstack_slot)
end end
end end
@ -313,7 +306,7 @@ armor.get_valid_player = function(self, player, msg)
return name, player_inv, armor_inv, pos return name, player_inv, armor_inv, pos
end end
armor.play_equip_sound = function(self, player, stack, unequip) armor.play_equip_sound = function(self, stack, player, pos, unequip)
local def = stack:get_definition() local def = stack:get_definition()
local estr = "equip" local estr = "equip"
if unequip then if unequip then
@ -325,7 +318,11 @@ armor.play_equip_sound = function(self, player, stack, unequip)
snd = { name = "mcl_armor_"..estr.."_generic" } snd = { name = "mcl_armor_"..estr.."_generic" }
end end
if snd then if snd then
minetest.sound_play(snd, {object=player, gain=0.5, max_hear_distance=8}) local dist = 8
if pos then
dist = 16
end
minetest.sound_play(snd, {object=player, pos=pos, gain=0.5, max_hear_distance=dist})
end end
end end
@ -382,13 +379,13 @@ minetest.register_on_joinplayer(function(player)
player:get_inventory():set_stack(listname, index, stack) player:get_inventory():set_stack(listname, index, stack)
armor:set_player_armor(player) armor:set_player_armor(player)
armor:update_inventory(player) armor:update_inventory(player)
armor:play_equip_sound(player, stack) armor:play_equip_sound(stack, player)
end, end,
on_take = function(inv, listname, index, stack, player) on_take = function(inv, listname, index, stack, player)
player:get_inventory():set_stack(listname, index, nil) player:get_inventory():set_stack(listname, index, nil)
armor:set_player_armor(player) armor:set_player_armor(player)
armor:update_inventory(player) armor:update_inventory(player)
armor:play_equip_sound(player, stack, true) armor:play_equip_sound(stack, player, nil, true)
end, end,
on_move = function(inv, from_list, from_index, to_list, to_index, count, player) on_move = function(inv, from_list, from_index, to_list, to_index, count, player)
local plaver_inv = player:get_inventory() local plaver_inv = player:get_inventory()
@ -397,7 +394,7 @@ minetest.register_on_joinplayer(function(player)
player_inv:set_stack(from_list, from_index, nil) player_inv:set_stack(from_list, from_index, nil)
armor:set_player_armor(player) armor:set_player_armor(player)
armor:update_inventory(player) armor:update_inventory(player)
armor:play_equip_sound(player, stack) armor:play_equip_sound(stack, player)
end, end,
allow_put = function(inv, listname, index, stack, player) allow_put = function(inv, listname, index, stack, player)
local iname = stack:get_name() local iname = stack:get_name()

View file

@ -149,7 +149,7 @@ minetest.register_node("mcl_armor_stand:armor_stand", {
single_item:set_count(1) single_item:set_count(1)
if inv:is_empty(list) then if inv:is_empty(list) then
inv:add_item(list, single_item) inv:add_item(list, single_item)
armor:play_equip_sound(clicker, single_item) armor:play_equip_sound(single_item, nil, pos)
update_entity(pos) update_entity(pos)
itemstack:take_item() itemstack:take_item()
return itemstack return itemstack
@ -174,7 +174,7 @@ minetest.register_node("mcl_armor_stand:armor_stand", {
taken = true taken = true
end end
if taken then if taken then
armor:play_equip_sound(clicker, stand_armor, true) armor:play_equip_sound(stand_armor, nil, pos, true)
stand_armor:take_item() stand_armor:take_item()
inv:set_stack("armor_" .. elements[e], 1, stand_armor) inv:set_stack("armor_" .. elements[e], 1, stand_armor)
end end