world.events.itemUse.subscribe(ev => {
if (ev.item.id == 'minecraft:clock' && ev.source.id == 'minecraft:player') {
var source = ev.source;
form.show(ev.source).then(res => {
source.runCommand(`tellraw @a {"rawtext":[{"text":"test complete ${res.selection + 1}"}]}`);
});
}
});```
Anyone able tell me why this doesn't work / what needs to be changed.
Much appreciated
#itemUse
1 messages · Page 1 of 1 (latest)
import { world, Player } from 'minecraft/server';
world.beforeEvents.itemUse.subscribe(ev => {
if (ev.itemStack.id == 'minecraft:clock' && !ev.source instanceof Player) {
var source = ev.source;
form.show(ev.source).then(res => {
source.runCommand(`tellraw @a {"rawtext":[{"text":"test complete ${res.selection + 1}"}]}`);
});
}
});```
Please use #1067535382285135923 later on.
Alright, thank you. Will do 🙂
It's still not working, any idea why?
Not getting anymore errors, it's just not openinh
I believe (!ev.source instanceOf Player) means that the code won't be run if the entity is a player
Any idea how fix it?
Remove the && !ev.source instanceOf Player from the if condition
Where did you create the server form? To open it?
@muted zephyr is right,
If form is not defined, nothing will show, though there should be an error message ...
Try:
import { world, Player } from 'minecraft/server';
world.beforeEvents.itemUse.subscribe(ev => {
if (ev.itemStack.id == 'minecraft:clock') {
var source = ev.source;
let form = new ActionFormData();
form.title("title");
form.button("button1");
form.show(source).then(res => {
source.runCommand(`tellraw @a {"rawtext":[{"text":`test complete ${res.selection + 1}`}]}`);
});
}
});```
And enable the logs