Giving players one arrow every two seconds, possibly with /replaceitem

Giving players one arrow every two seconds, possibly with /replaceitem - Two Beach Volleyball Giving Fist Bump Gesture

So, I need o give players one arrow every two seconds, but with a maximum of two arrows in the inventory. To do this, I tried adding a scoreboard objective called ArrowN and setting the score to 1 if the player has one arrow and to 2 if the player has two arrow. Then every two seconds replacing with two arrows if the player has an ArrowN score of 1 and not replacing if he has a score of 2. Now, I couldn't get how to set a score of 0 for a player that has no arrows, to replace him one arrow. Something like this just works for a half:

scoreboard objectives set @a[score_ArrowN=!1,score_ArrowN=!2] ArrowN 0

I think operation could be useful, but i can't use that command.

Note: it must be multiplayer friendly

Edit:probably using /give is a lot easier but I don't like having arrows popping on your face every two seconds



Best Answer

One way to do this would be to set up a command block to give everyone an arrow every 2 seconds, then in a repeating command block put:
/scoreboard players set @a Arrows 1 {Inventory:[{id:minecraft:arrow,Count:3b}]}
and then:
clear @a[score_Arrows_min=1] minecraft:arrow
give @a[score_Arrows_min=1] minecraft:arrow 2
/scoreboard players set @a[score_Arrows_min=1] Arrows 0
in command blocks in a fill clock so that they all trigger on the same tick, in this order. (if you are on the 1.9 snapshots, you can replace a fill clock with a command chain and the Arrows score with a tag)
This is not ideal, and if a player gets more than 3 arrows somehow, they will keep getting arrows forever, but without the ability to check negated NBT, such as {Inventory:[{Count:!2b}]}, I think this is your best bet.




Pictures about "Giving players one arrow every two seconds, possibly with /replaceitem"

Giving players one arrow every two seconds, possibly with /replaceitem - Numbers Wall Decor
Giving players one arrow every two seconds, possibly with /replaceitem - 123 Cutout Decor on Red Surface
Giving players one arrow every two seconds, possibly with /replaceitem - Red Background With 123 Text Overlay



What is the replaceitem command in minecraft?

You can use the /replaceitem command to instanty replace one item with another item. You can replace armor items worn, weapons held in your hands, items stored in chests and items in your inventory/hotbar. This is a great way to quickly put armor on a player during a Minecraft battle or change out a worn out weapon.

What is slotId int?

Specifies the inventory slot to be modified. Valid values depend on whether a block or an entity is being modified. See Slot for details. slotId: int must be a 32-bit integer number. And it must be between -2147483648 and 2147483647 (inclusive).



\




Sources: Stack Exchange - This article follows the attribution requirements of Stack Exchange and is licensed under CC BY-SA 3.0.

Images: RODNAE Productions, Magda Ehlers, Magda Ehlers, Black ice