#Playsound not working in datapack

1 messages · Page 1 of 1 (latest)

night stump
#

I have a little troll datapack to play a creeper sound behind the player. it checks the player's rotation and then plays a sound behind them. however, it first plays footstep sounds and then the creeper hiss. but only the first sound plays, and the ones in scheduled functions dont. i know the functions are getting run because the tag is getting removed at the end, but the sounds wont play, even though im doing execute as @a to workaround scheduled functions not working with @s

anyone know whats wrong?

night stump
#

The desired effect is to play three walk sounds within a second of each other, wait 8 seconds and then play one more, and then after 7 seconds the creeper hissing noise.

wispy otter
#

I think you’re over complicating it a bit

#

Unless someone has like 360 speakers around their head they won’t know if the playsound is just at the player or if it’s behind them

#

So you could probably just do ~ ~ ~ instead of something like ^ ^ ^-1 or however you’re playing it behind the player

night stump
wispy otter
#

Can you send the contents of the function you’re using play the sounds?

night stump
#

tick:
execute as @a store result score @s rotx run data get entity @s Rotation[0]
execute as @a if score @s rotx matches -135..-45 run scoreboard players set @s rot 2
execute as @a if score @s rotx matches -45..45 run scoreboard players set @s rot 1
execute as @a if score @s rotx matches 45..135 run scoreboard players set @s rot 3
execute as @a if score @s rotx matches 135..180 run scoreboard players set @s rot 0
execute as @a if score @s rotx matches -180..-135 run scoreboard players set @s rot 0

#

load:
scoreboard objectives add rotx dummy
scoreboard objectives add rot dummy

#

creeper:
execute as @r run tag @s add troll_creeper
execute as @a[tag=troll_creeper] if score @s rot matches 0 run playsound block.grass.step hostile @s ~ ~ ~2.5 0.25 1
execute as @a[tag=troll_creeper] if score @s rot matches 1 run playsound block.grass.step hostile @s ~ ~ ~-2.5 0.25 1
execute as @a[tag=troll_creeper] if score @s rot matches 2 run playsound block.grass.step hostile @s ~-2.5 ~ ~ 0.25 1
execute as @a[tag=troll_creeper] if score @s rot matches 3 run playsound block.grass.step hostile @s ~2.5 ~ ~ 0.25 1
schedule function trolls:creeper/creeper_walk_1 1s

wispy otter
#

Okay gimme a bit to look at this

night stump
#

creeper/creeper_walk1 (the first one where sound stops)
execute as @a[tag=troll_creeper] if score @s rot matches 0 run playsound block.grass.step hostile @s ~ ~ ~2.5 0.25 1
execute as @a[tag=troll_creeper] if score @s rot matches 1 run playsound block.grass.step hostile @s ~ ~ ~-2.5 0.25 1
execute as @a[tag=troll_creeper] if score @s rot matches 2 run playsound block.grass.step hostile @s ~-2.5 ~ ~ 0.25 1
execute as @a[tag=troll_creeper] if score @s rot matches 3 run playsound block.grass.step hostile @s ~2.5 ~ ~ 0.25 1
schedule function trolls:creeper/creeper_walk_2 1s

wispy otter
#

Okay this isn’t even to do with your playsound issue so far but do you know how relative rotation coordinates work?

night stump
#

i thnik so

#

what i thought was, since by that point in the execute command its being run as a player the ~ ~ ~ would be the players location, and so i could use that to play a sound behind the player based off the direction they were facing

#

cause that works in creeper.mcfunction

#

but the sounds cant be heard in creeper/creeper_walk1-3 or creeper/creeper_prime

night stump
wispy otter
night stump
#

oh i thought they were called relative lol

wispy otter
#

Okay I’m gonna read all of what you sent and think really hard

#

Local coordinates as in ^ ^ ^

night stump
#

ohh

#

then i have no idea what those do

#

the ^ ^ ^

#

i only know ~ ~ ~

wispy otter
#

That explains a bit

#

They are like ~ ~ ~ but for rotation instead of position

night stump
#

🤯 \

#

that makes things a lot simpler

wispy otter
#

So you could do all of this rotation calculation with no scoreboards I think

#

Yeah

night stump
#

hmm so like

wispy otter
#

^ ^ ^1 would be one block forward to where the player is looking

night stump
#

wait

#

but wouldnt you only need 2 ^'s

#

because theres 2 rotations in minecraft

wispy otter
#

right

night stump
#

yaw and pitch

wispy otter
#

The third one is where the player is looking I think

#

Gimme a second to read the wiki

night stump
#

ok

wispy otter
#

Want a link to what I’m looking at

#

Gtg

#

I’ll be back to help once I have some free time

night stump
#

ok

#

i think it will work ill update

#

it didnt

#

i removed the scoreboards

#

and replaced the playsouunds with

#

execute as @a[tag=troll_creeper] run playsound entity.creeper.primed hostile @s ^ ^ ^-3 1 0

#

and it still only plays the first one

#

and it was always a certain place not behind me

native grotto
#

it looks you're only executing as the players, not at, so the sounds are still played at the world origin

#

so you'd want execute as @a[tag=troll_creeper] at @s run ...

night stump
#

it worked!

#

i thought that running the command as the player would set the origin to the player

#

but it doesnt :/