#Need to open a UI when punching entity

1 messages · Page 1 of 1 (latest)

sharp sand
#

Help

#

“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!");
    }
}

})

distant aspen
#
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`)
        }
    })
    
}
unborn prairie
sharp sand
#

It’s not working

#

Ima check once mores

#

@unborn prairie it doesn’t work

unborn prairie
#

You just had to ping me. I could have made a mistake or something else. No need to create a new post

sharp sand
#

Oh ok

unborn prairie
#

What error does the debugger display?

sharp sand
#

Im on a server

#

Not a world or realm

unborn prairie
#

It doesn't matter

#

The debugger should show some errors if it doesn't work

sharp sand
#

Main.js ran with error

unborn prairie
#

This doesn't mean anything to me. Copy the whole error and come here

sharp sand
#

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

sharp sand
#

Bro

unborn prairie
sharp sand
#

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

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`)
        }
    })
}```
sharp sand
#

It says line 14 now

#

@unborn prairie

unborn prairie
sharp sand
#

Oh yeah mb

#

@unborn prairie

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`)
        }
    })
}
edgy tusk
#

ngl, this is scuffed as hell

sharp sand
#

Wym

unborn prairie
edgy tusk
sharp sand
#

How is it bad tho

edgy tusk
sharp sand
#

Yo Coddy how do I add a texture to that button

edgy tusk
edgy tusk
#

Or just add an image to the side?

#

Bruh, serty already gave it.

#

.button('<name>', 'textures/...');

#

it's a path

sharp sand
#

Oh ok

#

I did it

edgy tusk
#
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

sharp sand
#

What’s this

#

So copy paste that code into my script ?

#

@edgy tusk line 5 is not working

edgy tusk
sharp sand
#

Ok

#

Now when I hit Npc it just doesn’t open

#

@edgy tusk

edgy tusk
edgy tusk
sharp sand
#

Yea I put type of

#

Id

#

I’m testing on cow and it doesn’t show up

#

And cow id is simple

edgy tusk
#

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.
      }
   });
}```
sharp sand
#

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.
  }

});
}

sharp sand
#

Now it works

#

@edgy tusk one more question how do I make it a chest Ui instead of that

edgy tusk
#

Tho you can fake it

sharp sand
#

Wym by take it

#

Fake

#

What you mean by fake it @edgy tusk

edgy tusk
#

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