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')
}
});
#does this script only work with weapons ?
1 messages · Page 1 of 1 (latest)
I tried it with a normal custom item and it didn't work but then I tried with a diamond sword and it worked
well what is your custom weapon name
Lmao
that could be a possiblity
But the moment I change it to Minecraft:diamond_sword it starts to work
hmm
The function/command is completely the same for both items
I still say it's the getEquipment
I dont see how it would be that
Would getItem work?
And I don't see how this script isn't working despite it being perfectly correct
Lmao
Maybe cause the item isn't technically equipment or something and just falls under item...idk tbh
...
That's what I used beforehand,lmao
getEquipment is getting the Mainhand slot in this case
Yh idk then
anything defined in your maindhand slot will return
doesnt matter what category the item is in
You mean it shouldn't matter.lol
This script should be working
it does not matter.
Lol
Do you have an idea on what the problem may be ?
can you show the function
I don't think it really matters but sure
setblock ^^^1 ninjago:dirt_set
There
That's it
Nothing more
yeah, I have nothing
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
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
The entire addon ?
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
I wont be looking at the functions
i'll be looking at the item
I could but it may take forever to upload(it's not by any means small) and I ain't looking to leak anything
No I understand.
completely.
Uh
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?
the reason why I wanted the pack so I could try to tinker with things to make it work without making you do it
no insult to your capabilities ofc, but that was my last idea.
I heavily it would work for you, plus if you looked at the code rn im sure you'd find...problems
Problems that are not entirely in my control
All 81 items are on that format, like I said kinda out of my control(and it doesn't effect the scripts) and that's only half since I'm doing the other addon half on a different device so about 400 items on version 1.17
It shouldn't at all effect the scripts tho
Nah I'm using addon maker(yh I'm I'm a horrible person) the guy who's making it is fixing up the app so all our crap doesn't break in like 3 updates
That's why I'm learning scripts rn
yeah I could tell from the screenshot
I use bridge
Lmao
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)
I have bridge...
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)
well that's how it works.
Yh ik
lol
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...
I see
lets hope no one comes in here and tells us we've overlooked the smallest thing
Lmao true
Your item doesn't have the component minecraft:equippable
so instead of equippable it needs to be minecraft:equippable ?
No, you have to put minecraft:equippable in the item json for your item
Where exactly would I put that feature?
In your item json file
you dont
I'm curious as to why?
there's no minecraft:equippabe component for items
minecraft:equippable is an entity component.
Oh, I think it's minecraft:hand_equipped mb
hand_equipped has nothing to do with this
thats just rendering the item like a tool
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
It's not that
I did some editing and the script doesn't work on any item that runs a function
isnt it getEquipmentSlot("Mainhand"); or im crazy?
you can use both
alr
Would it help if I changed it ?
go ahead.
if it somehow works after this then great, but ill be confused
I doubt it'll work tbh
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?
you can, you just need to condition it so it won't run both code for the actions
like checking if the player is sneaking for one action, and checking if the player is not for the other
ah well, on my other item the earth one the player has to be looking down to acitvate something and shfiting to activate something else, but i made that with commands not scripts
maybe thats the problem
you check where the player is looking in the api
just look at the docs.