#Need to open a UI when punching entity
1 messages · Page 1 of 1 (latest)
“use strict";
import { Player, world } from "@minecraft/server";
world.afterEvents.entityHitEntity.subscribe(event => {
const attacker = event.damagingEntity;
const victim = event.hitEntity;
if (attacker instanceof Player) {
if (victim.typeId == "blossom:ooga_npc") {
attacker.sendMessage("You hit the Ooga NPC!");
}
}
})
import { Player, world } from "@minecraft/server";
import {
ActionFormData,
MessageFormData,
ModalFormData,
} from "@minecraft/server-ui";
world.afterEvents.entityHitEntity.subscribe(event => {
const attacker = event.damagingEntity;
const victim = event.hitEntity;
if (attacker instanceof Player) {
if (victim.typeId == "blossom:ooga_npc") {
attacker.sendMessage("You hit the Ooga NPC!");
ui(attacker)
}
}
})
function ui(player) {
const u = new ActionFormData()
u.title(`Menu`)
u.body(`Body`)
u.button(`button 1`)
u.show(player).then((r)=>{
if (r.canceled) return //detect when exit menu
if (r.selection == 0) { //detect when click button 1
player.sendMessage(`Button 1`)
}
})
}
Dude, do you even look at the answers? You have already been answered 2 times https://discord.com/channels/523663022053392405/1327876334009188352
You just had to ping me. I could have made a mistake or something else. No need to create a new post
Oh ok
What error does the debugger display?
Main.js ran with error
This doesn't mean anything to me. Copy the whole error and come here
K
I can’t copy it
I think I fixed it
I fixed it
How do I change the texture on the button to a logo
@unborn prairie
import { Player, world } from "@minecraft/server";
import {
ActionFormData,
MessageFormData,
ModalFormData,
} from "@minecraft/server-ui";
world.afterEvents.entityHitEntity.subscribe(event => {
const attacker = event.damagingEntity;
const victim = event.hitEntity;
if (attacker instanceof Player) {
if (victim.typeId == "blossom:ooga_npc")
ui(attacker)
}
}
})
function ui(player) {
const u = new ActionFormData()
u.title(PvP Menu)
u.body(``)
u.button(PVP)
u.show(player).then((r)=>{
if (r.canceled) return //detect when exit menu
if (r.selection == 0) { //detect when click button 1
player.sendMessage(Warping To PvP)
}
})
}
It said line 17 has problem
@unborn prairie
Bro
I don't know what the problem is, you don't want to tell me error.
I said line 17
import { Player, world } from "@minecraft/server";
import {
ActionFormData,
MessageFormData,
ModalFormData,
} from "@minecraft/server-ui";
world.afterEvents.entityHitEntity.subscribe(event => {
const attacker = event.damagingEntity;
const victim = event.hitEntity;
if (attacker instanceof Player) {
if (victim.typeId == "blossom:ooga_npc")
ui(attacker)
}
}
})
function ui(player) {
const u = new ActionFormData()
u.title(PvP Menu)
u.body(``)
u.button(PVP)
u.show(player).then((r)=>{
if (r.canceled) return //detect when exit menu
if (r.selection == 0) { //detect when click button 1
player.sendMessage(Warping To PvP)
}
})
}
There that’s the error o
@unborn prairie
import { Player, world } from "@minecraft/server";
import {
ActionFormData,
MessageFormData,
ModalFormData,
} from "@minecraft/server-ui";
world.afterEvents.entityHitEntity.subscribe(event => {
const attacker = event.damagingEntity;
const victim = event.hitEntity;
if (attacker instanceof Player) {
if (victim.typeId == "blossom:ooga_npc") {
ui(attacker)
}
}
})
function ui(player) {
const u = new ActionFormData()
u.title("PvP Menu")
u.body(``)
u.button(PVP)
u.show(player).then((r)=>{
if (r.canceled) return //detect when exit menu
if (r.selection == 0) { //detect when click button 1
player.sendMessage(`Warping To PvP`)
}
})
}```
This is the same screenshot
import { Player, world } from "@minecraft/server";
import {
ActionFormData,
MessageFormData,
ModalFormData,
} from "@minecraft/server-ui";
world.afterEvents.entityHitEntity.subscribe(event => {
const attacker = event.damagingEntity;
const victim = event.hitEntity;
if (attacker instanceof Player) {
if (victim.typeId == "blossom:ooga_npc") {
ui(attacker)
}
}
})
function ui(player) {
const u = new ActionFormData()
u.title("PvP Menu")
u.body(``)
u.button(`PVP`)
u.show(player).then((r)=>{
if (r.canceled) return //detect when exit menu
if (r.selection == 0) { //detect when click button 1
player.sendMessage(`Warping To PvP`)
}
})
}
ngl, this is scuffed as hell
Wym
I didn't write this, lol
yeah, it's obvious you don't write like this lmfao
How is it bad tho
It's not bad
Yo Coddy how do I add a texture to that button
Make the whole button an image?
.
Or just add an image to the side?
Bruh, serty already gave it.
.button('<name>', 'textures/...');
it's a path
world.afterEvents.entityHitEntity.subscribe(({ damagingEntity: attacker, hitEntity: victim }) => {
if (!(attacker instanceof Player)) return;
if (victim?.typeId === 'minecraft:horse') ui(attacker);
});
function ui(player) {
new ActionFormData().title('Pvp Menu').button('PVP').show(player)
.then(res => {
if (res.canceled) return;
switch (res.selection) {
case 0: player.sendMessage('Warping PVP'); break;
default: player.sendMessage('No selection'); break; // this triggers when no button was selected on each case you defined.
}
});
}```
they're the same just simpler
What’s this
So copy paste that code into my script ?
@edgy tusk line 5 is not working
you didn't import Player in the server.
Just copy paste it again.
did you put the typeid?
I just put it as <name> for placeholder change it based on the entity you want to
Yea I put type of
Id
I’m testing on cow and it doesn’t show up
And cow id is simple
I tried and this works in me.
Lemme see you current script
Oof my bad, I did something wrong in copy pasting.
world.afterEvents.entityHitEntity.subscribe(({ damagingEntity: attacker, hitEntity: victim }) => {
if (!(attacker instanceof Player)) return;
if (victim?.typeId === 'minecraft:horse') ui(attacker);
});
function ui(player) {
new ActionFormData().title('Pvp Menu').button('PVP').show(player)
.then(res => {
if (res.canceled) return;
switch (res.selection) {
case 0: player.sendMessage('Warping PVP'); break;
default: player.sendMessage('No selection'); break; // this triggers when no button was selected on each case you defined.
}
});
}```
My exact code
import { world, system, Player } from '@minecraft/server';
import { ActionFormData, ModalFormData, MessageFormData } from '@minecraft/server-ui';
world.afterEvents.entityHitEntity.subscribe(({ damagingEntity: victim, hitEntity: attacker }) => {
if (!(attacker instanceof Player)) return;
if (victim?.typeId === 'cow') ui(attacker);
});
function ui(player) {
new ActionFormData().title('Pvp Menu').button('PVP').show(player)
.then(res => {
if (res.canceled) return;
switch (res.selection) {
case 0: player.sendMessage('Warping PVP'); break;
default: player.sendMessage('No selection'); break; // this triggers when no button was selected on each case you defined.
}
});
}
What’s this
Now it works
@edgy tusk one more question how do I make it a chest Ui instead of that
you can't open chest ui or any type of UI except server form
Tho you can fake it
make it looks like chest
tho it's not as easy as 123, you need to learn json ui or you could use Herobrine's Chest UI
Just search the toggle and the GitHub one