I've been looking around for a right-click detection addon or script (I want the player to right click a sword and have it spawn a zombie), but I wasn't able to find one. I tried looking at the documentation for UseItem, but I wasn't able to find anywhere how to use it properly. Can someone help me make a script like this, or find something like it?
#How do I use UseItemAfterEvent and other classes like it?
1 messages · Page 1 of 1 (latest)
world.afterEvents.itemUse.subscribe(evd => {
const player = evd.source;
const item = evd.itemStack;
if (item.typeId === 'minecraft:diamond_sword') {
player.runCommandAsync('say I clicked with a sword!');
}
});```
Thank you very much! 🙂
I'm trying this out, and I can't get anything to work. I believe I am on version 1.20.13
index.js
import { world, system } from '@minecraft/server';
world.afterEvents.itemUse.subscribe(evd => {
const player = evd.source;
const item = evd.itemStack;
if (item.typeId === 'minecraft:diamond_sword') {
player.runCommandAsync('say I clicked with a sword!');
}
});
manifest.json
{
"format_version": 2,
"header": {
"name": "right click detect",
"description": "yes",
"uuid": "895fc41c-42af-4797-baf9-5711895e5e8d",
"version": [0, 1, 0],
"min_engine_version": [1, 20, 0]
},
"modules": [
{
"type": "script",
"language": "javascript",
"uuid": "d2066371-1478-43b3-82e7-566d20ce4517",
"entry": "scripts/index.js",
"version": [0, 1, 0]
}
],
"capabilities": ["script_eval"],
"dependencies": [
{
"module_name": "@minecraft/server",
"version": "1.5.0"
},
{
"module_name": "@minecraft/server-ui",
"version": "1.2.0-beta"
}
]
}
Did i do something wrong here?
Like you playing 1.20.13?
Thats a yes witch is werid but anyways is there any errors?
Like in the debug console
where's the debug console?
Tbh education edition idk
fair enough
Tbh I don't think I've ever see anyone on edu scripting
It wouldn't be there
but i'm not seeing anything run at all
yeahhh it's mainly so my school friends can play on the world lmao
Idk if you even can you would have to ask some one else
Merrybrine64 [@] is very smart
He might know
alright
i mean the /reload command still exists, and it still says it resets scripts
idk if that means anything tho
Is there not any error in the content log gui?
on 1.20.13 1.5.0 doesnt exist
latest is 1.4.0-beta
Alright, I'll try that thanks
I don't have access to the log
do u have normal mc or naw?
no it should work
Alr
It works! Jeez
I'm so disappointed that it was that simple
Thanks for the help
yw
Also is there a good place to learn about ItemStack
Documentation for Script API - v1.20.10