so i got this system, a repeat command block test if a player have the custom item in a slot in the inventory, and then a chain command block give the player an effect if the player have the item:
thanks i didnt know how to use tags, that very useful, now i got another problem, this, this is just one item, i have many more, i though on doing a function for each, and i use this command:
Make a new function (for example named LoopMe) that calls the other functions inside it. There can be only one function looped by the gamerule but you can have functions be run inside other functions. The other option is to put every function in a Repeating, Unconditional, Always Active command blocks.
Inside the "LoopMe" function just put the other ones:
And then you can call "LoopMe" instead of "items1" and "items2".Remember not to put "/" slashes at the beginning of commands in functions.
No-no-no! That's a bad way of calling a gameloop function!
You should indeed make a new game function, but you can call other functions directly from it: function rootfolder:items1/item1 function rootfolder:items1/item2 Then you can set your new loop function via /gamerule. Sometimes it makes sense to use an combined approach - have a old good repeating command block call the loop function. But if you want a command-block free world, then you should create a wrapper function like command_block_shadow suggested.
so i got this system, a repeat command block test if a player have the custom item in a slot in the inventory, and then a chain command block give the player an effect if the player have the item:
testfor @a {Inventory:[{Slot:9b,id:"minecraft:emerald",tag:{CanPlaceOn:["minecraft:sapling"]}}]}
testfor @a {Inventory:[{Slot:18b,id:"minecraft:emerald",tag:{CanPlaceOn:["minecraft:sapling"]}}]}
testfor @a {Inventory:[{Slot:27b,id:"minecraft:emerald",tag:{CanPlaceOn:["minecraft:sapling"]}}]}
effect @a minecraft:invisibility 2 0 true
(i use it to target all players, because is just in a single player world)
this works fine, but i want them in a function, so if i create a scoreboard CustomItem1, the effect would be like this
effect @a[score_CustomItem1_min=1,score_CustomItem1=1] minecraft:invisibility 2 0 true
now how can i change the scoreboard with a function, testing for the player to have the item in those particular inventory slots
so this goes in a function:
/scoreboard players tag @a[tag=emerald] remove emerald
#removes the tag "emerald", so if the player dont have the emerald, the tag is removed?
/scoreboard players tag @a add emerald {Inventory:[{Slot:9b,id:"minecraft:emerald",tag:{CanPlaceOn:["minecraft:sapling"]}}]}
/scoreboard players tag @a add emerald {Inventory:[{Slot:18b,id:"minecraft:emerald",tag:{CanPlaceOn:["minecraft:sapling"]}}]}
/scoreboard players tag @a add emerald {Inventory:[{Slot:27b,id:"minecraft:emerald",tag:{CanPlaceOn:["minecraft:sapling"]}}]}
# this lines will add the tag "emerald" to players that have the emerald in those slots??
/scoreboard players tag @a add emerald {Inventory:[{Slot:9b,id:"minecraft:emerald",tag:{CanPlaceOn:["minecraft:sapling"]}},{Slot:18b,id:"minecraft:emerald",tag:{CanPlaceOn:["minecraft:sapling"]}},{Slot:17b,id:"minecraft:emerald",tag:{CanPlaceOn:["minecraft:sapling"]}}]}
#this is the same with only one command??
and this goes in another function:
/effect @a[tag=emerald] minecraft:invisibility 2 0 true
#or it could go in the same function?
thanks i didnt know how to use tags, that very useful, now i got another problem, this, this is just one item, i have many more, i though on doing a function for each, and i use this command:
/gamerule gameLoopFunction rootfolder:items1/item1
but for other item like this
/gamerule gameLoopFunction rootfolder:items1/item2
the item1 stop functioning, so only one function per game? iam doing something wrong?
should i use a function that calls all my functions??
i wanted to do it this way, because if i wanted to disable something it would be easy, should i write everything in only and only function?
thanks
No-no-no! That's a bad way of calling a gameloop function!
You should indeed make a new game function, but you can call other functions directly from it:
function rootfolder:items1/item1
function rootfolder:items1/item2
Then you can set your new loop function via /gamerule.
Sometimes it makes sense to use an combined approach - have a old good repeating command block call the loop function. But if you want a command-block free world, then you should create a wrapper function like command_block_shadow suggested.
Happens to all of us =)
Thank you both, very helpful