#does this script only work with weapons ?

1 messages · Page 1 of 1 (latest)

craggy oriole
#
import { world, Player } from "@minecraft/server";

world.afterEvents.entityHitBlock.subscribe(({ hitBlock, damagingEntity: player }) => {
    if (!(player instanceof Player)) return;

    const item = player.getComponent('equippable')?.getEquipment('Mainhand');

    if (item?.typeId === 'minecraft:diamond_sword') {
        player.runCommand('say Something') 
    }
});

#

I tried it with a normal custom item and it didn't work but then I tried with a diamond sword and it worked

exotic holly
craggy oriole
#

Ninjago:earthelement

#

Or something like that

exotic holly
#

it'll work any item

#

you must've spelled it wrong.

craggy oriole
#

It isn't working

#

Maybe it's the getEquipment

#

?

#

That's what I put ?

exotic holly
#

didnt he do that

#

lol

craggy oriole
#

Lmao

exotic holly
#

this is strange, it should be working

#

I see no spelling errors

craggy oriole
#

Ah dang

#

I thought that too

exotic holly
#

that could be a possiblity

craggy oriole
#

But the moment I change it to Minecraft:diamond_sword it starts to work

exotic holly
#

oh

#

so it has to do with the item

craggy oriole
#

hmm

exotic holly
#

well he said it was working with diamond sword already

#

just not with his item

craggy oriole
#

The function/command is completely the same for both items

#

I still say it's the getEquipment

exotic holly
craggy oriole
#

Would getItem work?

exotic holly
#

thats not the problem

#

if that were the problem why would diamond sword work

craggy oriole
craggy oriole
craggy oriole
#

That's what I used beforehand,lmao

exotic holly
#

getEquipment is getting the Mainhand slot in this case

craggy oriole
exotic holly
#

anything defined in your maindhand slot will return

#

doesnt matter what category the item is in

craggy oriole
#

This script should be working

exotic holly
craggy oriole
#

Lol

craggy oriole
exotic holly
craggy oriole
#

I don't think it really matters but sure

#

setblock ^^^1 ninjago:dirt_set

#

There

#

That's it

#

Nothing more

exotic holly
#

yeah, I have nothing

craggy oriole
#

Well I had more for the original command but I dumbed it down and it still doesn't work

#

execute as @s[scores={stone=1..}] at @s if entity @s[y=~1.1,dy=0.5] unless entity @s[y=~1.6,dy=0.5] run setblock ^^^1 ninjago:dirt_set

Is the original(this works as a normal command without scripts btw)

#

Yep

exotic holly
#

even he wasnt why would it work with diamond sword

#

lmfao

#

its the item

#

for some reason

#

Okay, yU, if you dont mind...
may you share the pack so I can try to figure it out from the inside

exotic holly
#

you can dm me.

craggy oriole
#

Do you mind shifting through about 700 functions, because there's only one script(it's all I'm allowed to make) and it's exactly what I showed you

exotic holly
#

i'll be looking at the item

craggy oriole
#

Ah

#

Okay

#

There's the item

exotic holly
#

so you wont share the pack

#

thats fine

craggy oriole
craggy oriole
#

Uh

exotic holly
#

im just not sure what else I can do

#

sorry

craggy oriole
#

Well giving you the full version won't help(if you only plan on looking at one item) but maybe you could write a different script that does the same thing virtually?

exotic holly
#

no insult to your capabilities ofc, but that was my last idea.

craggy oriole
#

Problems that are not entirely in my control

exotic holly
#

Right, I probably would've said something

#

lmao

craggy oriole
#

Yes

#

Ofc none of the problems should affect how the scripts work but whatev

exotic holly
#

oh

#

Yu

#

dont use 1.17.0 for your format, change it to like 1.20.80+

craggy oriole
#

And there it is

#

Ik it was coming

exotic holly
#

lmfaoo

#

well, item and block events are deprecated

craggy oriole
exotic holly
#

oh

#

my lord

#

im so sorry for you

#

all of those items wont work very soon

craggy oriole
#

It shouldn't at all effect the scripts tho

craggy oriole
#

That's why I'm learning scripts rn

exotic holly
#

I use bridge

craggy oriole
#

Lmao

exotic holly
#

im less of a peasant as you

#

lol

craggy oriole
#

And since addon maker...isn't the best he screwed up of course and we can only make one script file(we can't access the manifest)

craggy oriole
exotic holly
#

come to bridge

#

or better yet, just use VSC

craggy oriole
#

Lmao not to be mean but Ik this would happen.(I send someone the files on my addon and they send me recommendations on doing anything else besides what I'm trying to do)

craggy oriole
#

Yh ik

exotic holly
#

lol

craggy oriole
#

I'm like 70 percent sure it's the fact that the item is an item and not a weapon so I'm guessing when I change the item to a weapon it'll work...

exotic holly
#

Well, im 100% sure its not

#

because ive been working with the api for a bit now

craggy oriole
#

I see

exotic holly
#

lets hope no one comes in here and tells us we've overlooked the smallest thing

craggy oriole
#

Lmao true

autumn crescent
craggy oriole
autumn crescent
#

No, you have to put minecraft:equippable in the item json for your item

craggy oriole
autumn crescent
#

In your item json file

autumn crescent
#

I'm curious as to why?

exotic holly
#

minecraft:equippable is an entity component.

autumn crescent
exotic holly
#

thats just rendering the item like a tool

autumn crescent
#

Hmm makes sense. I've tried using the getEquipment method on custom items before and it worked fine. Guess it's just a spelling problem

craggy oriole
#

It's not that

craggy oriole
warped pike
exotic holly
warped pike
#

alr

craggy oriole
exotic holly
#

if it somehow works after this then great, but ill be confused

craggy oriole
#

I doubt it'll work tbh

craggy oriole
# exotic holly go ahead.

am I able to run multiple scripts on one item, like a script on rigt click, and a script that opens a forum on right click?

exotic holly
craggy oriole
#

maybe thats the problem

exotic holly
#

just look at the docs.