how to play a sound only once time when the player select the item on hotbar

Started by SHORT on

Topic category: Help with modding (Java Edition)

Last seen on 15:51, 5. Mar 2024
Joined Sep 2020
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
how to play a sound only once time when the player select the item on hotbar

The title explains almost everything:

  • The sound keeps repeating itself all the time.

  • The item is of my creation.

  • I tried to make one solution with a "do" repeating it once, but it didn't work.

Last seen on 20:38, 3. Apr 2024
Joined Apr 2020
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
I would suggest a Number NBT…
Tue, 05/17/2022 - 18:50

I would suggest a Number NBT tag for the item,  then have a IF statement that says

NBT Variable +=  NBT Variable +  1

IF NBT Variable >= # (convert the length of your sound to ticks and use that number.) {

Play Sound

Set NBT Variable = 0

}

That way the sound will play, then wait for your tick to be >= to your sound length (in ticks, if sound is 3 seconds then its 60 ticks, 1 second = 20ticks) Also this is dependant on your procedure being used with a Update TIck Trigger, So that your NBT Variable will increment.

Last seen on 15:51, 5. Mar 2024
Joined Sep 2020
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
I tried doing it, but it…
Tue, 05/17/2022 - 20:49

I tried doing it, but it didn't work. So I thought if I created 2 variables being time and quantity (that had selected the item) it would work, but it's not working.
And my trigger is on item (Item In Hand Tick)

img

Last seen on 20:38, 3. Apr 2024
Joined Apr 2020
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Okay, so Firstly switch out…
Wed, 05/18/2022 - 01:28

Okay, so Firstly switch out the "Provided Itemstack" blocks with "Item in main hand" blocks. Since your item is on a Update Tick trigger (Item in hand Tick), which is ran every tick while the item is in your hand, then the line Set quantity to = 0 will be ran constantly, therefore not allowing your other line that sets it to 1, to actually trigger. As for the set time to += time + number from text. Is there a particular reason your using number from text with formatter? If not then change out the "number from text" with just a normal number block and set it to 1, so that it increments by 1 every tick while the item is in your hand. I'll check back on this post in a bit and see if you've worked it out.

Last seen on 20:38, 3. Apr 2024
Joined Apr 2020
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
It should look like this   …
Wed, 05/18/2022 - 01:35

It should look like this

help

 

 

 

and for clarity NBT variables do not need to be initialized if they are meant to start at 0 , because they will start at 0 anyways.

Last seen on 15:51, 5. Mar 2024
Joined Sep 2020
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
This will create a loop and…
Wed, 05/18/2022 - 01:47

This will create a loop and does need to await 14.44 ticks to execute…

Last seen on 20:38, 3. Apr 2024
Joined Apr 2020
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Okay, remember 1 second…
Wed, 05/18/2022 - 02:02

Okay, remember 1 second converted into ticks is 20 ticks, your sound is less then 1 second so it will appear to be looping/overlapping, so add some ticks to it, to allow for a small wait, I just tested out the code I sent you and it works fine.

 

On a side note I just made a Discord server if your interested, No Mic required. It would be much easier to debug this

Here is a link: https://discord.gg/afT5NR7Rje

If anyone else needs/wants help and is interested feel free to join the channel.

Last seen on 20:38, 3. Apr 2024
Joined Apr 2020
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
For anyone else who would…
Wed, 05/18/2022 - 19:15

For anyone else who would like to know how to play a sound when a player puts the item in their "Main Hand"

Here's how

ITEM TRIGGERS

1

ITEM IN HAND TICK

2

ITEM IN INVENTORY TICK

3