#How would I make a Chest Shop form-ui

1 messages · Page 1 of 1 (latest)

violet niche
#

When I open the chest it shows a form-ui menu

bitter barn
#

detect interaction on block

#

then system.run

#

and build ur form

slim warren
#

use ItemUseOn in beforeEvent

#

but you will need an item in the player's mainhand to achieve this

bitter barn
#

nope

#

with no item it works to

slim warren
slim warren
bitter barn
#

bruh

#

i fuck this update so much

slim warren
#

yea me too

#

every update comes with suck changes

bitter barn
#

then ```js
if (player.getComponent("minecraft:inventory").container.getItem(player.selectedSlot)) return;

slim warren
bitter barn
#

#cancel-1.20

slim warren
#

it wont detect interactions anymore with mainhand

nimble grotto
slim warren
slim warren
bitter barn
slim warren
#

i wish they have an option to retrieve the previous script api version

nimble grotto
#

We all

violet niche
#

@bitter barn do u know the script

bitter barn
#

not possible at this moment

violet niche
#

Oh

bitter barn
#

cuz the only event that made it possible is bugged rn

#

also to spawn chest minecart u have to do this in system.run so double cancel

slim warren
violet niche
#

Ok

#

@slim warren wait so u know the script

#

It’s fine if u don’t

#

Well I guess now one knows

#

@slim warren

#

Would u know how to make a villager shop form-ui

bitter barn
#

it's ez

slim warren
bitter barn
#

just detect the hit

slim warren
#

i use that on my events

bitter barn
#

oh k

#

i use eventData

violet niche
#

@slim warren is that for villager shop

slim warren
slim warren
#

its for chest thing that you asked for

violet niche
#

Oh Ty

slim warren
#

but you need to punch the chest there

violet niche
#

Ok np

#

But would I use
world.afterEvents.entityHit.subscribe({hitEntity, hitBlock, entity} = > {
//Everything else
})

slim warren
#

if thats what you will use then you need to edit some in the code

violet niche
#

Ok I might not use that then…

#

What would the import be

#

Import { something } from ‘@minecraft/server’

slim warren
#
world.afterEvents.entityHit.subscribe(({hitEntity, hitBlock, entity}) => {
    let player = entity
    if (!(player instanceof Player)) return
    if (hitBlock?.typeId == "your:chosen_block") {
        //your form code
    }
    if (hitEntity?.typeId == "your:chosen_entity") {
        //your form code
    }
  }
)
slim warren
violet niche
#

What do I put for your: and chosen_entity

bitter barn
#

when they gonna be under attack

#

example villager

violet niche
#

So “your:villager” for example

slim warren
#

no

#

use the right namespace

#

for villager it will be "minecraft:villager"

violet niche
#

Oh

slim warren
#

for chest it will be "minecraft:chest"

violet niche
#

Sry I forget stuff sometimes

bitter barn
#

np broski

violet niche
#

There’s already an error

slim warren
#

what is it

violet niche
#

entity} =>

#

It doesn’t like =>

#

Idk why

#

Hello?

#

@slim warren

#

Anyone

#

….

#

It works if I just do = or ==

bitter barn
#

and yep

slim warren
#

oh i know

violet niche
#

?

slim warren
#

({hitEntity, hitBlock, entity}) =>

#

make it like that

#

inside parenthesis

violet niche
#

Still doesn’t I’ll send on different account

ancient apex
violet niche
#

Can u help pls

slim warren
#

thats wrong

violet niche
#

What is it

slim warren
#

world.afterEvents.entityHit.subscribe(({hitEntity, hitBlock, entity}) => {

bitter barn
#
world.afterEvents.entityHit.subscribe(({ hitBlock, hitEntity, entity }) => {

});
violet niche
#

Also what do I put for your:chosen_block

bitter barn
#

id of block

#

minecraft:chest is example

slim warren
violet niche
#

So what is your:chosen_entity

bitter barn
slim warren
#

depending on what you need

#

modify the code depending on your need

violet niche
#

So minecraft:chest

slim warren
violet niche
#

So what is your:chosen_entity

#

Can I have example pls

bitter barn
#

bro

#

i said it 4 times

#

id of entity

#

minecraft:zombie

violet niche
#

So I would do

#

😗

bitter barn
#

just replace it with id of entity

violet niche
#

Oops

#

I didn’t mean to do that

#

So

#

I would do

#

if (hitEntity.typeId == “minecraft:zombie”) for example

bitter barn
#

yes

violet niche
#

How would that be useful tho

#

And also what would I do for the hitBlock form code and the hitEntity form code

#

Which one is for the ui menu

#

@bitter barn

bitter barn
#

both

#

are for ui

violet niche
#

So I just copy it

#

Both

bitter barn
#

but selectg

#

one of them

violet niche
#

What is ‘selectg’

bitter barn
#

i mean select

#

select one of them

violet niche
#

Wdym “select one of them”

bitter barn
#

bro

#

just select

#

block or entity

violet niche
#

So I don’t need entity

bitter barn
#

then remove if with entity

violet niche
#

Can u just show me what it would look like

bitter barn
#
world.afterEvents.entityHit.subscribe(({ hitBlock, hitEntity, entity }) => {
    if (hitBlock.typeId == 'minecraft:chest') {
      // ur code here
    };
});
violet niche
#

So I don’t need if (!(player instance of Player)) return or let player = entity

bitter barn
#

yes

violet niche
#

Ok ty

violet niche
#

@bitter barn

#

It says an error

#

Cause I did: (on different account btw)

ancient apex
#

let form4 = new ui.ActionFormData()

violet niche
#

@slim warren

#

Nvm but it’s not working

#

@bitter barn

#

@bitter barn

#

@bitter barn

#

PLS ANYONE

slim warren
violet niche
#

It’s not working the script

#

I’ll so u my code

slim warren
#

please state the problem, not just "its not working"

bitter barn
#

i got 4 pings here

#

tf

violet niche
#

Ok

bitter barn
#

send code

#

don't ask to ask

#

or get help

violet niche
#

Ok

bitter barn
#

just send it

#

bro u are typing 15 seconds ok

#

just send ur code

ancient apex
#

``import { world } from '@minecraft/server'
import { ActionFormData } from '@minecraft/server-ui'
import * as ui from '@minecraft/server-ui'

let form4 = new ui.ActionFormData()

world.afterEvents.entityHit.subscribe(({hitBlock}) => {
if (hitBlock?.typeId == "minecraft:chest") {
form4.title("Bombie Shop")
form4.body("This is the Shop")
}
})``

slim warren
#

why do you have multiple imports of actionformdata

violet niche
#

And when I punch the chest nothing happens

#

Idk

slim warren
#

ill try it on my world hold on

violet niche
#

Ok

bitter barn
#
import { world } from '@minecraft/server';
import * as ui from '@minecraft/server-ui';

world.afterEvents.entityHit.subscribe(({hitBlock, entity}) => {
    if (hitBlock?.typeId == "minecraft:chest") {
      const form = new ui.ActionFormData()
        .title("Bombie Shop")
        .body("This is the Shop")
        .button(``) // button is required in this type of form
        .show(player).then((resultData) => {

      });
    };
});
#

fixed

slim warren
#

oh yeah, he didnt put a button

bitter barn
#
  1. button is required
  2. he forgot to .show()
  3. he forgot to add entity cuz he has to show it to someone
  4. double import
slim warren
#

lmao

violet niche
#

Lol

bitter barn
#

what i was supposted to do guys

#

blame at their code, then insult his entire family and challenge him 1v1 on the hive?

violet niche
#

Error

bitter barn
#

send error

violet niche
#

Ok

ancient apex
violet niche
#

What have I done wrong

bitter barn
#

oh ye

#

replace player with entity

#

my bad

violet niche
#

Ty

bitter barn
#

np

violet niche
#

Then if u do a chest form

#

U know how to make like a villager form ui

#

When u click on it, it opens a ui menu

slim warren
violet niche
#

So it’s

#

world.afterEvents.hitEntity.subscribe(({hitEntity, entity}) => {
if (hitEntity?.typeId == “minecraft:chest”) {
const form = new ui.ActionFormData()
//code Here

#

@slim warren

#

Or is it wrong

lyric carbonBOT
#
Debug Result

There is an error in this [code](#1119978445032669224 message):

<repl>.js:10:15 - error TS2304: Cannot find name 'player'.

10         .show(player).then((resultData) => {
                 ~~~~~~

bitter barn
slim warren
ancient apex
#

ok

#

but theres

#

a problem

#

will it do the shop for every chest @slim warren

bitter barn
#

to set which chest

ancient apex
#

and is there someway I can add a specific data to it

bitter barn
#

test for xyz

ancient apex
#

what will it look like

bitter barn
#
if (hitBlock.x == x && hitBlock.y == y && hitBlock.z == z && hitBlock.typeId == "minecraft:chest")
ancient apex
#

ok ty

bitter barn
#

np

#

replace x, y, z with int

ancient apex
#

wait

#

im trying to do it with a villager

#

heres the code

#

`` import { world } from '@minecraft/server'
import * as ui from '@minecraft/server-ui'

world.afterEvents.entityHit.subscribe(({hitEntity, entity}) => {
if (hitEntity?.typeId == "minecraft:chest") {
const form4 = new ui.ActionFormData()
.title("VIP Room")
.body("Tp to The VIP Room")
.button(Tp, 'textures/items/ender_pearl') // button is required in this type of form
.show(entity).then((resultData) => {

    })
}

}) ``

#

I might of done something wrong

slim warren
#

do you think minecraft:chest is villager

ancient apex
#

oh...

#

um

#

still doesnt work

bitter barn
#
import { world } from '@minecraft/server'
import * as ui from '@minecraft/server-ui'

world.afterEvents.entityHit.subscribe(({hitEntity, entity}) => {
    if (hitEntity?.typeId == "minecraft:villager") {
      const form4 = new ui.ActionFormData()
        .title("VIP Room")
        .body("Tp to The VIP Room")
        .button(`Tp`, 'textures/items/ender_pearl') // button is required in this type of form
        .show(entity).then((resultData) => {

        })
    }
}) 
#

it should work rn'

ancient apex
#

still doesnt work

#

no error code

#

look cause this is my code:

#

``import { world } from '@minecraft/server'
import * as ui from '@minecraft/server-ui'

world.afterEvents.entityHit.subscribe(({hitEntity, entity}) => {
if (hitEntity?.typeId == "minecraft:villager") {
const form4 = new ui.ActionFormData()
.title("VIP Room")
.body("Tp to The VIP Room")
.button(Tp, 'textures/items/ender_pearl') // button is required in this type of form
.show(entity).then((resultData) => {

    })
}

}) ``

#

so is it not possibe

#

or should i just add it to the chest shop one

bitter barn
#
import { world } from '@minecraft/server'
import * as ui from '@minecraft/server-ui'

world.afterEvents.entityHit.subscribe((eventData) => {
    const player = eventData.entity
    const hit = eventData.hitEntity
    if (!hit) return;
    if (hit.typeId == "minecraft:villager") {
      new ui.ActionFormData()
        .title("VIP Room")
        .body("Tp to The VIP Room")
        .button(`Tp`, 'textures/items/ender_pearl')
        .show(player).then((resultData) => {

        })
    }
}) 
#

it should work

ancient apex
#

it says hitEntity is not defined

lyric carbonBOT
#
Debug Result

There are 7 errors in this [code](#1119978445032669224 message):

<repl>.js:4:39 - error TS2304: Cannot find name 'eventData'.

4 world.afterEvents.entityHit.subscribe(eventData) => {
                                        ~~~~~~~~~

``````ansi
<repl>.js:4:50 - error TS1005: ';' expected.

4 world.afterEvents.entityHit.subscribe(eventData) => {
                                                   ~~

``````ansi
<repl>.js:5:20 - error TS2304: Cannot find name 'eventData'.

5     const player = eventData.entity
                     ~~~~~~~~~

``````ansi
<repl>.js:6:17 - error TS2304: Cannot find name 'eventData'.

6     const hit = eventData.hitEntity
                  ~~~~~~~~~

``````ansi
<repl>.js:8:9 - error TS2304: Cannot find name 'hitEntity'.

8     if (hitEntity.typeId == "minecraft:villager") {
          ~~~~~~~~~

``````ansi
<repl>.js:13:15 - error TS2304: Cannot find name 'entity'.

13         .show(entity).then((resultData) => {
                 ~~~~~~

``````ansi
<repl>.js:17:2 - error TS1128: Declaration or statement expected.

17 })
    ~

bitter barn
#

wrong syntax

lyric carbonBOT
#
Debug Result

There is an error in this [code](#1119978445032669224 message):

<repl>.js:13:15 - error TS2345: Argument of type 'Entity' is not assignable to parameter of type 'Player'.
  Type 'Entity' is missing the following properties from type 'Player': level, name, onScreenDisplay, selectedSlot, and 16 more.

13         .show(player).then((resultData) => {
                 ~~~~~~

ancient apex
#

so what is correct

bitter barn
#
import { world } from '@minecraft/server'
import * as ui from '@minecraft/server-ui'

world.afterEvents.entityHit.subscribe((eventData) => {
    const player = eventData.entity
    const hit = eventData.hitEntity
    if (!hit) return;
    if (hit.typeId == "minecraft:villager") {
      new ui.ActionFormData()
        .title("VIP Room")
        .body("Tp to The VIP Room")
        .button(`Tp`, 'textures/items/ender_pearl')
        .show(player).then((resultData) => {

        })
    }
}) 
ancient apex
#

that's the same

bitter barn
#

corrected syntax

ancient apex
#

ok

#

still

#

no error but not working

bitter barn
#

did u hit villager?

ancient apex
#

yes

bitter barn
#

hmm

#

did u import>

lyric carbonBOT
#
Debug Result

There is an error in this [code](#1119978445032669224 message):

<repl>.js:13:15 - error TS2345: Argument of type 'Entity' is not assignable to parameter of type 'Player'.
  Type 'Entity' is missing the following properties from type 'Player': level, name, onScreenDisplay, selectedSlot, and 16 more.

13         .show(player).then((resultData) => {
                 ~~~~~~

ancient apex
#

ye

#

ok

bitter barn
#

hmm weird

#

it should work

ancient apex
#

well do u know a one that u right click instead of hit

bitter barn
#
import { world } from '@minecraft/server'
import * as ui from '@minecraft/server-ui'

world.afterEvents.entityHit.subscribe((eventData) => {
    const player = eventData.entity
    const hit = eventData.hitEntity
    if (!hit) return;
    if (hit.typeId == "minecraft:villager") {
      if (entity instanceof Player) {
         new ui.ActionFormData()
            .title("VIP Room")
            .body("Tp to The VIP Room")
            .button(`Tp`, 'textures/items/ender_pearl')
            .show(player).then((resultData) => {

        })
      };
    }
}) 
ancient apex
#

it doesnt work..

#

if u know the clickable one then do that one pls

#

cause it seems like theres no luck

#

@bitter barn

#

do u know the script for the clickable one

bitter barn
#

i know, but you're beggin for a lot of code rn

ancient apex
#

ik and im sry

#

im trying to build a server

#

and it will help if u can help me

#

but if u feel like ur being pressured, I understand....bao_panda_blank

bitter barn
#

no, I am just too lazy to do this rn

ancient apex
#

ok

#

well when u are ready, just send cause i might not be there when u are ready

#

for now, ill just try on my own

bitter barn
#

k

#

i wrote about 3k lines of code

#

that's why i am a bit lazy rn

ancient apex
#

ok

bitter barn
bitter barn
#

some scripts

ancient apex
#

cant u then copy and paste

bitter barn
#

but i didn't make shop yet

#

you can make an entire shop in 200 lines max

ancient apex
#

no i dont want it for shop tho..

#

i just want in general

bitter barn
#

well the actual algorithm will be like 30 lines

bitter barn
#

then

ancient apex
#

my server

bitter barn
#

do you want a shop?

ancient apex
#

what villager

bitter barn
#

Anything

#

doesn’t matter

ancient apex
#

well yea

bitter barn
#

tell me what you want

#

I’ll make it for you and you can just edit the items inside of it

#

and prices etc

ancient apex
#

um like buy shop

#

for villager

bitter barn
#

Ok do you know javascript a little

ancient apex
#

ye ik

bitter barn
#

do you know objects

ancient apex
#

wdym objects

bitter barn
#
const object = {“test”: 5}```
ancient apex
#

no. is that bad idk that?

bitter barn
#

Ok I will explain when I send

ancient apex
#

ok

bitter barn
#

I will try make it as understandable as possible

ancient apex
#

ok

bitter barn
bitter barn
#

No

#

Ohhhhh

#

People who use script api skip learning javascript

#

very true

#

yes

#

it's like 20/25% of the people

#

or are on the server just to get free scripts

#

true

#

when smelly has released his goofy chat ranks

#

official bedrock scripting api got more people just to get scripts than actual developers XD

ancient apex
#

so am I going to know the script or not

bitter barn
ancient apex
#

cause @bitter barn said he will tell me thecode

bitter barn
#

I just needed to update it

ancient apex
#

ok

bitter barn
#

I haven't done script api in a long while

#

I'm doing it now

ancient apex
#

oh

#

ok

#

i gtg now @bitter barn can u dm it to me

bitter barn
#

const armours = 
[
    {name: "Leather", cost: 10000, icon: "textures/items/leather_chestplate", structure: "LeatherSet"},
    {name: "Chain", cost: 25000, icon: "textures/items/chainmail_chestplate", structure: "ChainSet"},
    {name: "Iron", cost: 50000, icon: "textures/items/iron_chestplate", structure: "IronSet"},
    {name: "Diamond", cost: 100000, icon: "textures/items/diamond_chestplate", structure: "DiamondSet"},
    {name: "Netherite", cost: 250000, icon: "textures/items/netherite_chestplate", structure: "NetheriteSet"}
]

const swords = 
[
    { name: "Wooden sword", cost: 5000, icon: "textures/items/wood_sword", structure: "woodSword"},
    { name: "Stone sword", cost: 10000, icon: "textures/items/stone_sword", structure: "stoneSword"},
    { name: "Iron sword", cost: 25000, icon: "textures/items/iron_sword", structure: "ironSword"},
    { name: "Diamond sword", cost: 50000, icon: "textures/items/diamond_sword", structure: "diamondSword"},
    { name: "Netherite sword", cost: 100000, icon: "textures/items/netherite_sword", structure: "netheriteSword"}
]

export function getScore(target, objective, useZero = true) {
    try {
        const oB = world.scoreboard.getObjective(objective);
        if (typeof target == "string")
            return oB.getScore(
                oB.getParticipants().find((pT) => pT.displayName == target)
            );
        return oB.getScore(target.scoreboard);
    } catch {
        return useZero ? 0 : NaN;
    }
}

world.afterEvents.entityHit.subscribe(e => {
    const player = world.getAllPlayers().find(p => p.name === e.entity.nameTag)
    console.warn(e.hitEntity.typeId)
    if(e.hitEntity?.typeId.includes("minecraft:villager"))
    {
        return shopUI(player)
    }
})

function shopUI(player){
    const form = new ActionFormData()
    .title("Shop Menu")
    .button(`Armour`)
    .button(`Swords`)
    form.show(player).then(r => {
        switch(r.selection)
        {
            case 0:
                return armourUI(player)
            case 1:
                return swordUI(player)
        }
    })
}

function armourUI(player)
{
    const form = new ActionFormData()
    .title("Armour shop")
    for(let i = 0; i < armours.length; i++){
        form.button(`${armours[i].name}\nCost: ${armours[i].cost}`, `${armours[i].icon}`)
    }
    form.show(player).then(r => {
        const {x,y,z} = player.location
        if(getScore(player.name, "Money") >= armours[r.selection].cost)
        {
            player.sendMessage(`Purchase successful`)
            return world.getDimension('overworld').runCommandAsync(`structure load ${armours[r.selection].structure} ${x} ${y} ${z}`)
        }
    })
}

function swordUI(player)
{
    const form = new ActionFormData()
    .title("Sword shop")
    for(let i = 0; i < swords.length; i++){
        form.button(`${swords[i].name}\nCost: ${swords[i].cost}`, `${swords[i].icon}`)
    }
    form.show(player).then(r => {
        const {x,y,z} = player.location
        if(getScore(player.name, "Money") >= swords[r.selection].cost)
        {
            player.sendMessage(`Purchase successful`)
            return world.getDimension('overworld').runCommandAsync(`structure load ${swords[r.selection].structure} ${x} ${y} ${z}`)
        }
        
    })
}```
#

done

#

@ancient apex

#

bro u were bored af

#

I was

#

I still am

#

It took like what 5-10 mins

#

so

#

ye ik

#

I didnt even test it

#

might work

#

i would never do these amounts of code for free xd

lyric carbonBOT
#
No Errors

No errors in [code](#1119978445032669224 message)

bitter barn
#

only import errors

#

probs

#

Oh it doesnt include import errors anymore

#

coolio

timber pollen
stone gust
# timber pollen

@timber pollen Is that purple icon actually in floating above the chest or is that an invisible item frame?

timber pollen
#

floating

stone gust
#

How'd you do that?

bitter barn
glacial nimbus
#

why not

bitter barn
#

idk

#

it's okay

ancient apex
#

@bitter barn

#

do u know what the imports will be

bitter barn
#

wdym

bitter barn
bitter barn
modern marlin
bitter barn
bitter barn
#

chest is counted as block. but it has some of enttiy inside itself

ancient apex
#

for the code @bitter barn

#

the code u sent me

bitter barn
#
import { world } from '@minecraft/server'
import { ActionFormData } from '@minecraft/server-ui'
slim warren
slim warren
slim warren
modern marlin
slim warren
timber pollen
slim warren
timber pollen
#

also what thing

slim warren
slim warren
timber pollen
#

but how can you make the block floating right

#

and the tools too

snow lotus
timber pollen
#

i know you use mainhand

slim warren
timber pollen
slim warren
#

that alignment stressed me out for almost a month, just to get the right offset and rotation

slim warren
timber pollen
#

damn

#

very good

#

my chest shop align is only for items the rest is weird

slim warren
timber pollen
#

me too

#

its kinda hard to position the block

#

mind giving :>

#

jkjk

#

i used Invisible Item Frame addons to see the item rotation values lol

slim warren
timber pollen
#

oh yea thats true

silk swallow
#

it was no sense to trigger itemUseOn item event with no item

slim warren
#

is it confirmed that they will add an interaction event thing

silk swallow
#

not very confirmed but its in a plan

bitter barn
#

look

#

you can have this in your arms?

#

yes

#

do you can pick it up?

#

yes

#

so it's an item

silk swallow
#

you can give via nbt air but other slots are empty

glacial nimbus
slim warren
glacial nimbus
glacial nimbus
#

You have to assign everything you need or cancel before you call await null; in the async callback

slim warren
slim warren
#

oh sorry, i mixed up one with con

#

so its like that

glacial nimbus
#

That will wait 10 tick await null; is only one tick or js frame haven’t test it exactly but it works

slim warren
slim warren
#

we can't change player names, only their nametags

bitter barn
#

yep

slim warren
autumn portal
#

Oh okay thanks