Started by
_Syntax_3rror_
on
Topic category: Help with Minecraft modding (Java Edition)
I want it so music plays as soon as the player enters a certain dimension and when the music finishes, it waits a certain amount of time and plays the music again. I want this to be a constant loop.
Edited by _Syntax_3rror_ on Sun, 04/07/2024 - 17:29
To start, there should be a "player enters dimension" trigger, either in your dimension element or in global triggers.
For the repeating loop, you are going to want to set up a procedure either for "on player update tick" or "on world update tick". The blow is for on world update so that all players hear it at the same time, but you can adapt it for the player update tick too.
"On world update tick"
Set up 2 global variables, one of them a numeric value called "dimension_ID_sound_lock_timer" and a Boolean/logic "dimension_ID_sound_lock"
If "dimension_ID_sound_lock" = false do{
Set "dimension_ID_sound_lock" = true
Set "dimension_ID_sound_lock_timer" = the amount of time you want for the delay in ticks (20 ticks/second - 60 seconds = 1,200 ticks)
For each player in world as entity iterator (if dimension ID player is in = your dimension do{
Play sound}
)
}
New "main" if statement:
if "dimension_ID_sound_lock" = true do {
If "dimension_ID_sound_lock_timer" > 0 do {
Set "dimension_ID_sound_lock_timer" = get "dimension_ID_sound_lock_timer" minus 1}
Else if "dimension_ID_sound_lock_timer" = 0 do {
Set "dimension_ID_sound_lock" = false}
}
Am I able to have a picture example?
When player enters dimension: https://imgur.com/9ITKSGo & https://imgur.com/zH55cbX
Variables: https://imgur.com/kFrKtbY & https://imgur.com/PhnkL3E
Repeating sound: https://imgur.com/W5z81ZS
Thank you so much for the help!
one last question: Can I use the same variables for multiple dimensions?
Not really. It would be best to make a new variable for each dimension. If you use the same variable, and have multiple players in each dimension, then both dimensions would be modifying the variable at the same time, and it could get a little messy.
The code itself though can be used for any dimension. Just create a new global for each dimension.
Got it! Thank you!