#help with entity hit thing
1 messages · Page 1 of 1 (latest)
world.afterEvents.entityHitEntity.subscribe(({ damagingEntity: player, hitEntity: target }) => {
if (player.typeId !== 'minecraft:player') return;
const hand = player.getComponent('minecraft:equippable').getEquipment('mainhand');
if (!hand) return;
switch (hand.typeId) {
case 'csith:menacing_spell_actual': {
target.addTag("sithd")
break;
}
case 'cc:honeysword': {
target.addTag("slowed")
break;
}
default: break;
}
});
according to the error,
1st, whats on line406
now where do u think the EquipmentSlot goes there
uhhh, do u check the docs or typings?
it doesnt throw errors
exept for the one i showed ytoyu
it worked up until recently
i think an update broke it?
@hexed frigate
'equippable' & 'Mainhand' ???
ctrl + leftclick getEquipmentSlot
i dont understand why this doesnt work
not yet, gota teach how to troubleshoot, hehe
on line 406
ah i think i see
ctrl + getEquipment
actually i do it on all the chars there to see what goes where
click it
do it on getEquipment
did it take u to the types?
equiptable?
im trying to do an entity hit event
that doesnt work
that used to and how doesnt
Unrelated but are you trying to get the component to a mob not player?
anything
so if a player just attacks anything it runs the action
target.addTag
so the target shouild recive the tag
Eh, equippable only works on player rn
bro ctrl left click doesn absolultely nothing
Debug result for [code](#1342337989736402955 message)
Compiler found 1 errors:
[36m<REPL0>.js[0m:[33m4[0m:[33m73[0m - [31merror[0m[30m TS2345: [0mArgument of type '"mainhand"' is not assignable to parameter of type 'EquipmentSlot'.
[7m4[0m const hand = player.getComponent('minecraft:equippable').getEquipment('mainhand');
[7m [0m [31m ~~~~~~~~~~[0m
There are no errors from ESLint.
yeah idk what is even happening
just tryna make the event work
for if player hits entity give the entity a tag
simple as that
ok, mb prob my typing was diff 💀
u can try finding the EquipmentSlot in the types
equp
?
selectedSlotIndex? Maybe?
-# puqe
selected*
Potan-
the typing has this
so change 'mainhand' to 'Mainhand'
orrr. If you're fancy, import EquipmentSlot to the server and do EquipmentSlot.Mainhand
ill try that ig
or also do getEquipmentSlot()
waittt. Are you updating the right file?
what even is that 😭
yes?
this is what it looks like now
Are you sure? Do a console.error() to the file
it gave an error when i tried that code
no it's not a string it's getEquipment(EquipmentSlot.Mainhand)
import { EquipmentSlot } from "@minecraft/server"
``````js
getEquipment(EquipmentSlot.Mainhand)
i have both of these
still doesnt wwork
I just tried it worked fine with me.
"Mainhand"
EqipmentSlot.Mainhand
what???
either of those
world.afterEvents.entityHitEntity.subscribe(({ damagingEntity: player, hitEntity: target }) => {
if (player.typeId !== 'minecraft:player') return;
const hand = player.getComponent('minecraft:equippable').getEquipment(EquipmentSlot.Mainhand);
if (!hand) return;
switch (hand.typeId) {
case 'csith:menacing_spell_actual': {
target.addTag("sithd")
break;
}
case 'cc:honeysword': {
target.addTag("slowed")
break;
}
default: break;
}
});```
this is what i have and nothing?
world.afterEvents.entityHitEntity.subscribe(({ hitEntity, damagingEntity }) => {
const equippable = damagingEntity.getComponent('equippable');
const mainhand = equippable.getEquipment('Mainhand');
console.error(mainhand?.typeId);
});```
ok
what about the part where it works 😭
where the target recives the tag
wait a sec
lets gooo
i got it to work
ty for u guy's help
i have anotehr ?
is there a way to add a cooldown?
30s
for?
for?
it gives 'sithd' tag
wont do it again for 30s
the tag is tied to cool damage system
u can inflict the dmg & tag consecutively, and the last hit should decide the last cooldown?
like reset the 30s CD every hit
@hexed frigate
world.afterEvents.entityHitEntity.subscribe(({ damagingEntity: player, hitEntity: target }) => {
if (player.typeId !== 'minecraft:player') return;
const playerName = player.name;
const currentTime = Date.now();
const lastAttackTime = playerCooldowns.get(playerName) || 0;
const timeDiff = (currentTime - lastAttackTime) / 1000;
if (timeDiff < 30) {
const cooldownTime = (30 - timeDiff).toFixed(1);
player.sendMessage(`§cYou are on cooldown for ${cooldownTime}s!`);
player.playSound("sith.action.unsucsessful");
player.runCommandAsync(`title @s actionbar {"rawtext":[{"text":"§cCooldown: ${cooldownTime}s"}]}`);
return;
}
playerCooldowns.set(playerName, currentTime);
const hand = player.getComponent('minecraft:equippable').getEquipment(EquipmentSlot.Mainhand);
if (!hand) return;
switch (hand.typeId) {
case 'sith:menacing_spell_actual': {
target.addTag("sithd");
player.sendMessage("§cYou have struck with your Menacing Spell!");
player.playSound("random.orb");
break;
}
case 'cc:honeysword': {
target.addTag("slowed");
player.sendMessage("§cYou have struck with your Honey Sword!");
player.playSound("random.orb");
break;
}
default: break;
}
});```
i added cooldown
but it wont display on actionbar
@torpid crown
Title accept rawtext? Did you mean titleraw?
world.afterEvents.entityHitEntity.subscribe(({ damagingEntity: player, hitEntity: target }) => {
if (player.typeId !== 'minecraft:player') return;
const playerName = player.name;
const currentTime = Date.now();
const lastAttackTime = playerCooldowns.get(playerName) || 0;
const timeDiff = (currentTime - lastAttackTime) / 1000;
const hand = player.getComponent('minecraft:equippable').getEquipment(EquipmentSlot.Mainhand);
if (!hand) return;
if (hand.typeId === 'sith:menacing_spell_actual' && timeDiff < 30) {
const cooldownTime = Math.max(30 - timeDiff, 0).toFixed(0);
player.sendMessage(`§cYou are on cooldown for ${cooldownTime}s!`);
player.playSound("sith.action.unsucsessful");
const updateActionBar = () => {
const remainingTime = Math.max(30 - ((Date.now() - lastAttackTime) / 1000), 0).toFixed(1);
if (remainingTime > 0.1) {
player.runCommandAsync(`titleraw @s actionbar {"rawtext":[{"text":"§cCooldown: ${remainingTime}s"}]}`);
system.runTimeout(updateActionBar, 20); // Update every second (20 ticks)
} else {
player.runCommandAsync(`titleraw @s actionbar {"rawtext":[{"text":"§aStrike ready!"}]}`);
}
};
updateActionBar();
return;
}
playerCooldowns.set(playerName, currentTime);
switch (hand.typeId) {
case 'sith:menacing_spell_actual': {
target.addTag("sithd");
player.sendMessage("§cYou have struck with your Menacing Spell!");
player.playSound("sith.action.strike");
player.playSound("sith.action.woosh");
break;
}
case 'cc:honeysword': {
target.addTag("slowed");
player.sendMessage("§cYou have struck with your Honey Sword!");
player.playSound("random.orb");
break;
}
default: break;
}
});
mb
fixed that
BUT
cant figuire out why
im tryna fix this
but the error sound and cooldown chat message is being sent/displayed even if player attacks with diffrent item
besides the spell book
is that makes sense
Sorry, can you explain what you are doing again?
itsa all good i got everything working