-3

I'm making a custom survival map, and one thing i'd like to implement is custom mobs, but I would also like to get a sound played everytime I hit it myself, either with bow, or sword, or even fists, as long as I can play a sound when a player hurts the custom mob only.

I'm pretty sure i'd have to use an /execute command for thid, but I just don't know really how to use multiple commands with one single command block, and also is it possible to set a score for the mob, and use that for the /execute command?

The mob's name is "Ghost", and it's a Ghast.

  • Have you made any attempt to solve this yourself? Arqade works better when askers show effort to solve their own problems; we see that you have a problem you've worked on, and answerers respond to that. You also get a more specific answer that's tailored exactly to the part you're stuck, and Arqade gets a very specific question. Everybody wins! – Frank Jul 19 '16 at 12:21
  • I'm not sure this is possible in vanilla. You could probably detect when a mob takes damage, but there isn't really a way to check to see who caused it using vanilla redstone and command block mechanics. – Unionhawk Jul 19 '16 at 12:32
  • Probably a better way to handle this could be to use a resource pack for ghasts, assuming you aren't using ghasts anywhere else. – Unionhawk Jul 19 '16 at 12:42
  • 1
    Why one arth is this post on -1? Like what on earth was the goddamn issue here? Seriously whoever that downvoted this, please get reasonable. I understand I should have solved it myself, but isin't stackexchanche for those who wants help? Where does it say I have to solve it myself?I understand it's better if I do so myself,but I was just bussy, and needed a simple answer, not a downvote from someone,I appreciate anyone's answe that is helpful, but I don't appreciate that when I come here and ask for help I get a lower reputation, if you answer a question u get a good repuation simple! – Palestina Jul 19 '16 at 15:15
  • 2
    Like I said, we expect askers to show some effort. You get a much better reception here when you do. When you don't, thing like this happen. We tend to not like being treated as a code on demand service. We don't expect you to solve everything, but we do sort of expect you to try it first before asking. That's not an unreasonable stance. – Frank Jul 19 '16 at 20:44
2

You cannot test for a specific player hurting a mob.

However, you can test for a mob being damaged:

/scoreboard players tag @e[name=Ghost,tag=!Hurt] add Hurt {HurtTime:10s}
/scoreboard players tag @e[name=Ghost,tag=Hurt] remove Hurt {HurtTime:9s}

From here, you now know that a Mob is hurt, and can do things reliably, like play a sound:

/execute @e[name=Ghost,tag=Hurt] ~ ~ ~ /playsound sound @a ~ ~ ~ 1 1 

Now, this assumes that the mob won't get hurt unless there's a player near it, which isn't an unfair observation. It will also play the sound to all players on the server, centered on the location of the Mob.

  • 1
    This way also has advantages over a resource pack since you can specify the name of a custom mob. – Unionhawk Jul 19 '16 at 20:48
  • okay but can I also set a radius to the commands so that a players 100 blocks away wont hear it? – Palestina Jul 23 '16 at 22:10
  • @Palestina It's very unlikely that a player would be able to hear this sound from 100 blocks away, unless the volume you set for the command is very high. Assuming a sane value, only people within a few blocks of the boss would possibly be able to hear it. – Kaz Wolfe Jul 23 '16 at 22:12
  • I just tested it out and it didn't work, I set th e first 2 commands to 2 repeating command blocks that are always active, aswell as the third onne which is the /execute command. on chat it says that it adds the tag, and then removes it, but no sound is being played, what could the cause be? I looked at the command block witht he first command, and it says in the output: "[00:28:27] The dataTag does not match for b2547ee3-4aa4-4fbe-8f7d-d080bdc71cfd" – Palestina Jul 24 '16 at 22:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.