#Make a Sound play when clicking a block with a specific item

9 messages · Page 1 of 1 (latest)

feral elmBOT
#

Once your ticket has been resolved, please close it with </ticket close:1054771505520717835> command!

bold tusk
#

so here you just got the sound but not the necessarity to have a water bottle in hand?

is this script functuning at first?

still aurora
#
global.clamp = (min, max, value) => Math.max(min, Math.min(value, max))
global.sound = (entity, soundId, volume, pitch, shift) => {
    shift = shift || 0.2; pitch = pitch || 1; volume = volume || 1;
    const {level, x, y, z} = entity;
    level.playSound(null, x, y, z, soundId, 'master', global.clamp(0.5, 2, volume), global.clamp(0.5, 2, pitch - shift/2 + Math.random()*shift));
}
global.sound(event.player, 'entity.cow.milk') 
spark quest
#

To Check If a Player is Holding the correct Item:

if(event.item.is(Item.of("minecraft:dirt")))
still aurora
#

there's an example below

#

clamp means clamp the given value between min value and max value

#

global.sound plays the sound, with clamping the value, to prevent applying a pitch too high or too low

#

replace the event.block.playSound('entity.cow.milk') with the given example

spark quest
#

The Sound ppays already though