Yeah, commands don't work like that. They're highly structured, and don't allow you to replace expected integers with expressions. You're going to have to do this the hard way. You'll also want to be using 1.9 for command block simplicity, although this solution will also work in 1.8 with well structured 20Hz clocks.
First, we need to set up another scoreboard objective that represents the number of items to give; let's call it NumItems
:
/scoreboard objectives add NumItems dummy
We also need an intermediate scoreboard objective to avoid race conditions in the latter stages. This objective is what is going to multiply the DIFF
score, so we'll call it Multiplier
:
/scoreboard objectives add Multiplier dummy
Now, when a player hits the button, they need their NumItems
score set to two times their DIFF
score. We do that with the following commands:
/scoreboard players set @p Multiplier 2
/scoreboard players operation @p Multiplier *= @p DIFF
/scoreboard players operation @p NumItems = @p Multiplier
Great, now we have a number of items to give, we just need to give them... one at a time. Well, we can be a little more efficient than that, but we can't just give an arbitrary number of items. We'll break it down into giving 1 item, 10 items, and a stack of 64 items. Create a chain of command blocks off a repeating command block (or use a 20Hz clock) for these commands, edited to meet your needed specifics:
/give @a[score_NumItems_min=64] <item> 64 [...]
/scoreboard players remove @a[score_NumItems_min=64] NumItems 64
/give @a[score_NumItems_min=10] <item> 10 [...]
/scoreboard players remove @a[score_NumItems_min=10] NumItems 10
/give @a[score_NumItems_min=1] <item> 1 [...]
/scoreboard players remove @a[score_NumItems_min=1] NumItems 1
This is only one possible distribution of give
values, and can easily be improved by choosing a geometric sequence like 2n (1, 2, 4, 8...), which should complete all give operations for item counts up to 128 in 1 or 2 ticks.
It should be apparent why we need the Multiplier
objective, but in case it's not, it's so that we don't start giving items before DIFF has been doubled. As such, we should only write to the NumItems
once when the button is pressed. Even though the likelihood of encountering a race condition error is low without using the Multiplier
objective, it's best to avoid the problem entirely.
I wrote a script to do it...
This is written in Python and works on vanilla minecraft (even snapshots)
I currently give players a purple_shulker_box the first time they are seen by the server
https://github.com/Veritas83/Minecraft.SNAPSHOT.Commands.Mod/blob/master/commands.by.YT_Veritas0923.py
Line 1150-1153
if freeshulkerbox == True:
cmdin = "give " + player + " purple_shulker_box 1\n"
print "[" + get24hrtime() + "] [Script thread/EXEC]: " + cmdin,
p.stdin.write(cmdin)
Change to:
if freeshulkerbox == True:
cmdin = "give " + player + " minecraft:skull 1 3 {SkullOwner:" + player + "}\n"
print "[" + get24hrtime() + "] [Script thread/EXEC]: " + cmdin,
p.stdin.write(cmdin)
I think this will accomplish what you are asking.
Update:
I just tested this, and it does indeed work. :)
Best Answer
You need a loot table (archive) and the command
/loot
(archive) for this.Firstly, the loot table that gives (or summons or inserts or whatever) the head of the player it is invoked on.
Minimal file structure of the datapack:
Here
head_loot
is an arbitrarily chosen namespace, which is reused in the command later. The same withhead.json
, only the file extension needs to be.json
.Contents of
pack.mcmeta
can vary depending on what you want, but this is a minimum example:{"pack":{"pack_format":3,"description":""}}
Contents of
head.json
:Now you can create heads of arbitrary (currently online) players. There are multiple ways to do this, the one that is actually intended for exactly this is:
This runs "as" a random player, but not "at" their position and summons a player head item entity at the execution position (a command block or whatever).
Make sure that the datapack is enabled, this command tells you that:
If you just changed something in the files, use
/reload
.