I'm making a map and every time someone kills a mob I want them to get 1 experience level but I'm not sure how to do it. It should only use command blocks, no mods or plugins.

  • Of course I'm stuck that's why I'm asking. Why the down vote? – FireStrike289 Nov 14 '14 at 2:34
  • Where are you stuck? It's much easier to help you if you show what you've already tried, so that we can just show you what you got wrong, and you're off to the races again. – Frank Nov 14 '14 at 2:36
  • I have got the thing ps to give them the experience I just don't know how do detect how many mob kills they have had using Command Blocks – FireStrike289 Nov 14 '14 at 2:38

This is a simple matter of our friend, the scoreboard. First, setup a scoreboard for mob kills:

/scoreboard objectives add Kills stat.mobKills

This will automatically keep track of a player's mob kills. We can also manipulate it manually. We'll get into that. Now, we want to detect (on a clock) when a player has a Kills score of 1, and give them 1 experience level, and then set their Kills score to 0

/xp @a[score_Kills_min=1] 1L
/scoreboard players set @a[score_Kills_min=1] Kills 0

These two commands should run at the same time to work right, though if redstone quirks cause it to not work right, you can run /testfor @p[score_Kills_min=1] on a clock, and send the output of that command block to the /xp and /scoreboard commands in sequence.

Note this will also count passive mobs; chickens etc. There's no real way to avoid this, unless you want to keep track of each entity killed with /scoreboard objectives add KillEntity stat.killEntity.<entity> (e.g. /scoreboard objectives add KillZombie stat.killEntity.Zombie). Which you can do, but you'll need a set of /xp and /scoreboard reset commands for each one.

  • If I used a rapid comparator clock will it be to fast for the Command Blocks? – FireStrike289 Nov 14 '14 at 4:06
  • You should be able to use a 20 Hz fill clock, so a comparator clock should be fine. – Unionhawk Nov 14 '14 at 4:07

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.