#Give player some effect if they touch certain item/have certain item in inventory
34 messages · Page 1 of 1 (latest)
Once your ticket has been resolved, please close it with </ticket close:1054771505520717835> command!
// Contains all Item IDs that should trigger the effect
const checkForIDs = [
"minecraft:stick"
];
// Runs every tick
PlayerEvents.tick((event)=>{
let player = event.player;
let inventory = player.inventory.getAllItems();
let contains = false;
// Iterates over the items in the player's inventory, checking for the IDs
for(const item of inventory){
// If the currently iterated item is in the checkForIDs array, then set contains to true and break the loop
if(checkForIDs.includes(item.id)){
contains = true;
break;
}
}
// If the player's inventory does not contain any of the IDs, then return
if(!contains) return;
// Run a Minecraft command to give the player an effect
// The effect is "alexsmobs:bug_pheromones" with a duration of 10 seconds and an amplifier of 1
// The effect will display no particle effects (true/false at the end)
event.server.runCommandSilent(`effect give ${player.username} alexsmobs:bug_pheromones 10 1 true`)
})
Change the checkForIDs array for items you want to check for, and ofc change the effect at the end to the desired effect you want. This inside of server_scripts folder.
Use this as an example and change it for your specific use case. This is an example of how i'd accomplish this. Though its best to just run this on the PlayerEvents.inventoryChanged event lol
Its a similar approach to when touching a block. If by "touch" a block you mean a right click or a left click, there's also events for that. BlockEvents.leftClicked and BlockEvents.rightClicked. The event will contain the block id with event.block.id
you probably dont want to do this 20 times a second... maybe once every few seconds lol
Hence why I said inventoryChanged is a far better event lmao
I pulled this script out of my ass a second ago with no thought behind my eyes
either that or a timer
Im not overly familiar with KubeJS, how would a timer work? Run it in the tick event and skip X amount of ticks or does KubeJS support things like setInterval?
there is a built in timer, but i cant remember the syntax
if not you can just make a standard JS counter
let counter = 0
PlayerEvents.tick(e => {
if(counter++ % 60 != 0) return
})
which runs once every 3 sec for instance

@azure pine whats the tick counter thing, im going insane trying to find it
e.level.time iirc 
well yea because you don't remember it 
or I'm wrong
Cant be. You're the wiki guy
If you dont know, no one does
ah true 
server.tickCount()?
ooooh
declaration: package: net.minecraft.server, class: MinecraftServer
server.tickCount without brackets
yeah, i forgot it is a bean
so then its
PlayerEvents.tick(e => {
if(e.server.tickCount % 60 != 0) return
// everything else here
})
Sorry for late checking, I will try
Also, I mean touching block means like player walking near them or stepping them.