#help with entity hit thing

1 messages · Page 1 of 1 (latest)

west grove
#
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;
  }
});
hexed frigate
#

according to the error,
1st, whats on line406

west grove
#

line 406 is

#

@hexed frigate

hexed frigate
#

now where do u think the EquipmentSlot goes there

west grove
#

?

#

idk 😭

hexed frigate
#

uhhh, do u check the docs or typings?

west grove
west grove
#

exept for the one i showed ytoyu

#

it worked up until recently

#

i think an update broke it?

#

@hexed frigate

full python
#

'equippable' & 'Mainhand' ???

hexed frigate
#

ctrl + leftclick getEquipmentSlot

west grove
#

i dont understand why this doesnt work

hexed frigate
full python
#

Fair

#

Lol

west grove
hexed frigate
west grove
#

ah i think i see

hexed frigate
#

ctrl + getEquipment
actually i do it on all the chars there to see what goes where

west grove
#

when i click control and hover

#

some thinmgs underline

#

those dont

hexed frigate
#

click it

west grove
#

whjat?

#

huh

west grove
#

im confused abt this

hexed frigate
#

do it on getEquipment

west grove
#

uh ok

#

i did?

hexed frigate
#

did it take u to the types?

west grove
#

huh??????

#

no??

west grove
#

equiptable?

#

im trying to do an entity hit event

#

that doesnt work

#

that used to and how doesnt

hexed frigate
#

sth like this

#

then ctrl + left-click the EquipmentSlot for the types used

torpid crown
west grove
#

so if a player just attacks anything it runs the action

#

target.addTag

#

so the target shouild recive the tag

torpid crown
west grove
slate gustBOT
# west grove ```js world.afterEvents.entityHitEntity.subscribe(({ damagingEntity: player, hit...

Debug result for [code](#1342337989736402955 message)

Compiler Result

Compiler found 1 errors:

<REPL0>.js:4:73 - error TS2345: Argument of type '"mainhand"' is not assignable to parameter of type 'EquipmentSlot'.

4   const hand = player.getComponent('minecraft:equippable').getEquipment('mainhand');
                                                                          ~~~~~~~~~~

Lint Result

There are no errors from ESLint.

west grove
#

just tryna make the event work

#

for if player hits entity give the entity a tag

#

simple as that

hexed frigate
west grove
#

?

full python
hexed frigate
full python
#

selected*

torpid crown
hexed frigate
torpid crown
west grove
#

doesnt work

torpid crown
#

orrr. If you're fancy, import EquipmentSlot to the server and do EquipmentSlot.Mainhand

west grove
#

ill try that ig

torpid crown
#

or also do getEquipmentSlot()

west grove
#

ill try both of those

#

nope

#

@torpid crown

torpid crown
#

waittt. Are you updating the right file?

west grove
west grove
#

this is what it looks like now

torpid crown
west grove
#

it gave an error when i tried that code

torpid crown
# west grove

no it's not a string it's getEquipment(EquipmentSlot.Mainhand)

west grove
#

this is so confuseing

hexed frigate
#
import { EquipmentSlot } from "@minecraft/server"
``````js
getEquipment(EquipmentSlot.Mainhand)
west grove
west grove
#

still doesnt wwork

torpid crown
#

I just tried it worked fine with me.

hexed frigate
#
"Mainhand"
EqipmentSlot.Mainhand
west grove
hexed frigate
#

either of those

west grove
#
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?

torpid crown
#
world.afterEvents.entityHitEntity.subscribe(({ hitEntity, damagingEntity }) => {
   const equippable = damagingEntity.getComponent('equippable');
   const mainhand = equippable.getEquipment('Mainhand');
   console.error(mainhand?.typeId);
});```
west grove
#

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

hexed frigate
#

for?

west grove
#

if that makes sense

#

the actions

torpid crown
#

for?

west grove
#

it gives 'sithd' tag

#

wont do it again for 30s

#

the tag is tied to cool damage system

hexed frigate
#

u can inflict the dmg & tag consecutively, and the last hit should decide the last cooldown?

#

like reset the 30s CD every hit

west grove
#

@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

torpid crown
west grove
#
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;
  }
});
west grove
#

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

torpid crown
west grove
#

itsa all good i got everything working