#How do I use UseItemAfterEvent and other classes like it?

1 messages · Page 1 of 1 (latest)

gray copper
#

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?

woven iris
#
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!');
    }
});```
gray copper
#

Thank you very much! 🙂

gray copper
# woven iris ```js world.afterEvents.itemUse.subscribe(evd => { const player = evd.source...

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?

gray copper
arctic stream
#

Thats a yes witch is werid but anyways is there any errors?

#

Like in the debug console

gray copper
#

where's the debug console?

arctic stream
#

Did you enable it? otherwise it plan to see?

#

It's in settings under creator

gray copper
#

i forgot to mention i'm in education edition 💀

#

it didn't show any errors tho

arctic stream
#

Tbh education edition idk

gray copper
#

fair enough

arctic stream
#

Tbh I don't think I've ever see anyone on edu scripting

gray copper
#

i mean

#

it's not showing any errors

arctic stream
gray copper
#

but i'm not seeing anything run at all

gray copper
arctic stream
#

Idk if you even can you would have to ask some one else

#

Merrybrine64 [@] is very smart

#

He might know

gray copper
#

alright

#

i mean the /reload command still exists, and it still says it resets scripts

#

idk if that means anything tho

thin tendon
glad wraith
#

latest is 1.4.0-beta

gray copper
#

Alright, I'll try that thanks

glad wraith
#

also do u have content log gui on?

gray copper
glad wraith
#

do u have normal mc or naw?

gray copper
#

I do

#

Should I switch over then?

glad wraith
#

no it should work

gray copper
#

Alr

#

It works! Jeez

#

I'm so disappointed that it was that simple

#

Thanks for the help

glad wraith
#

yw

gray copper
#

Also is there a good place to learn about ItemStack