First of all, this is one of my first scripts, so I didn't even know it could be writed better than this. It works, then for me it's fine.
But, if you have any suggestion for a better code I'm happy to read you.
Second, I couldn't find any APIs that remove points. I found setValue only.
And yes, I'm writing with JavaScript.
I have a scripted block designed to summon an item above it if a player scoreboard is >100, then remove 100 from scoreboard.
function tick(event) {
var player = event.block.world.getAllPlayers()[0].displayName;
var cash = event.block.world.getScoreboard().getObjective('Cash').getScore(player).getValue();
if (cash >= 100){
event.block.executeCommand ('/summon Item ~ ~1 ~ {Item:{id:"minecraft:iron_ingot",Count:1b}}');
event.block.executeCommand ('/scoreboard players remove @p Cash 100')
}}
Now I would like to give this block to the player, so he can place it where he likes in order to summon the item where he need it.
How can I do?
I thought i should give the scripted block w/script thru /give command, but I don't know how.
Thanks for any suggestion.
EDIT: the script is written in Javascript.
EDIT2: I managed to /give the block with script as NBTtag, but when placed down there's no script inside it.