Could I make it so that when I kill a player for the first time, a command block gives me an iron sword, on my second kill it gives me a diamond sword, on my third kill it gives me an enchanted item, and so on?

I also want a way to reset this, as well as a start button. I know a way that I can do this by doing /scoreboard objectives add objectivename playerKillCount, and then a comparator does /give @p iron_sword. However, if I am too far from the command block and another player is next to it, the command block will give the sword to them instead. Also, @p won't work for the whole world, because I have to be near it. Can somebody please help me with a way that I can do this?

  • What is your question? – Virusboy Dec 6 '14 at 17:04
  • my question is how to count kills then give items for example on my first kill i get iron sowrd on my second kill i get diamond sword and so do other players also a way to reset this – Usain Dec 6 '14 at 17:11
  • 3
    What have you tried to achieve this on your own? You'll get a much better reception here at Arqade if you demonstrate some effort to solve this yourself. We aren't a code on demand service, and it won't be a good experience for you if that's what you use us as. – Frank Dec 6 '14 at 17:54
  • Yes i agree to an exent. However don't give op privs to just anyone – Virusboy Dec 7 '14 at 2:33

First, as you said in your question, declare a scoreboard objective of type playerKillCount to track player kills:

/scoreboard objectives add PlayerKills playerKillCount

Next, create a dummy objective that will track which rewards a player has already been given:

/scoreboard objectives add KillRewardGiven dummy

Now, on a clock (any type will do so long as you can control execution order, I'll use a 20Hz /fill clock) you'll need two blocks for each reward. One to give the reward:

/give @a[score_PlayerKills_min=1,score_KillRewardGiven=0] iron_sword

Then another do mark that the player has already received the award:

/scoreboard players set @a[score_PlayerKills_min=1,score_PlayerKills=1] KillRewardGiven 1

Here's an image illustrating how you would do your second tier reward:

enter image description here

To reset this you can run these commands, either in chat or in a command block:

/scoreboard players reset * PlayerKills
/scoreboard players reset * KillRewardGiven

To turn it on and off, you could hook something like this up to the clock:

enter image description here

| improve this answer | |
  • Thank you very much my friend you helped me alot, have a virtual hug from me :D – Usain Dec 8 '14 at 16:24
  • /scoreboard players reset * PlayerKills /scoreboard players reset * KillRewardGiven does work or do i have change the * to anything, please help – Usain Dec 10 '14 at 12:35
  • Also let the asker know to put the blocks in spawn chunks so that it works for "the whole world"? – SevenSidedDie Mar 11 '15 at 21:05

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.