#help me fix this please

1 messages · Page 1 of 1 (latest)

celest meadow
#

using ai and i know its not the best but its pretty fast to help me so i don't have to ask as many questions


// Event handler for player hitting an entity
world.afterEvents.entityHitEntity.subscribe((eventData) => {
    const player = eventData.player;
    const entity = eventData.hurtEntity;

    // Check if the entity's type matches one in the combatEntities array
    const entityTypeId = entity.typeId;
    const combatInfo = entityTypes.combatEntities.find((info) => info.entity === entityTypeId);

    if (combatInfo) {
        // Entity is in the array, grant XP for hitting
        updateXPAndActionBar(player, combatInfo.hitXP, 'combat');
    }
});

// Event handler for entity death
world.afterEvents.entityDie.subscribe((eventData) => {
    const entity = eventData.entity;

    // Check if the entity's type matches one in the combatEntities array
    const entityTypeId = entity.typeId;
    const combatInfo = entityTypes.combatEntities.find((info) => info.entity === entityTypeId);

    if (combatInfo) {
        // Entity is in the array, grant XP for death
        const players = eventData.players; // List of players involved in the death
        for (const player of players) {
            updateXPAndActionBar(player, combatInfo.deathXP, 'combat');
        }
    }
});```

im tryn to get the get the entity the player hit and then player killed if the entity or other player dies.

then xp will drop for the player that attacks or kills an entity or player entity
#

just need help getting the getEntity or whatever it is targeted correclty

celest meadow
#

lol, well i just need help targeting the entities and the players in the events

#

clean up the code because something is wrong and its late i can't think right now

#

thats essientially my demise

#

its for a combat skill in an mcmmo

#

tryn to give xp on hit, and then also when the entity is killed

#

those values will be different

buoyant cedarBOT
#
Debug Result

There are 8 errors in this [code](#1157493178476281876 message):

<repl>.js:4:30 - error TS2339: Property 'player' does not exist on type 'EntityHitEntityAfterEvent'.

4     const player = eventData.player;
                               ~~~~~~

``````ansi
<repl>.js:5:30 - error TS2551: Property 'hurtEntity' does not exist on type 'EntityHitEntityAfterEvent'. Did you mean 'hitEntity'?

5     const entity = eventData.hurtEntity;
                               ~~~~~~~~~~

  @minecraft/server.d.ts:3205:22
    3205             readonly hitEntity: Entity;
                              ~~~~~~~~~
    'hitEntity' is declared here.

``````ansi
<repl>.js:9:24 - error TS2552: Cannot find name 'entityTypes'. Did you mean 'entityTypeId'?

9     const combatInfo = entityTypes.combatEntities.find((info) => info.entity === entityTypeId);
                         ~~~~~~~~~~~

  <repl>.js:8:11
    8     const entityTypeId = entity.typeId;
                ~~~~~~~~~~~~
    'entityTypeId' is declared here.

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

13         updateXPAndActionBar(player, combatInfo.hitXP, 'combat');
           ~~~~~~~~~~~~~~~~~~~~

``````ansi
<repl>.js:19:30 - error TS2339: Property 'entity' does not exist on type 'EntityDieAfterEvent'.

19     const entity = eventData.entity;
                                ~~~~~~

``````ansi
<repl>.js:23:24 - error TS2552: Cannot find name 'entityTypes'. Did you mean 'entityTypeId'?

23     const combatInfo = entityTypes.combatEntities.find((info) => info.entity === entityTypeId);
                          ~~~~~~~~~~~

  <repl>.js:22:11
    22     const entityTypeId = entity.typeId;
                 ~~~~~~~~~~~~
    'entityTypeId' is declared here.

``````ansi
<repl>.js:27:35 - error TS2339: Property 'players' does not exist on type 'EntityDieAfterEvent'.

27         const players = eventData.players; // List of players involved in the death
                                     ~~~~~~~

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

29             updateXPAndActionBar(player, combatInfo.deathXP, 'combat');
               ~~~~~~~~~~~~~~~~~~~~

celest meadow
#
// Event handler for player hitting an entity
world.afterEvents.entityHitEntity.subscribe((eventData) => {
    const player = eventData.player;
    const entity = eventData.hurtEntity;

    // Check if the entity's type matches one in the combatEntities array
    const entityTypeId = entity;
    const combatInfo = entityTypes.combatEntities.find((info) => info.entity === entityTypeId);

    if (combatInfo) {
        // Entity is in the array, grant XP for hitting
        updateXPAndActionBar(player, combatInfo.hitXP, 'combat');
    }
});

// Event handler for entity death
world.afterEvents.entityDie.subscribe((eventData) => {
    const entity = eventData.entity;

    // Check if the entity's type matches one in the combatEntities array
    const entityTypeId = entity
    const combatInfo = entityTypes.combatEntities.find((info) => info.entity === entityTypeId);

    if (combatInfo) {
        // Entity is in the array, grant XP for death
        const players = eventData.players; // List of players involved in the death
        for (const player of players) {
            updateXPAndActionBar(player, combatInfo.deathXP, 'combat');
        }
    }
});```
buoyant cedarBOT
#
Debug Result

There are 14 errors in this [code](#1157493178476281876 message).
Please read the attached file for the result.

celest meadow
#

awhhhhhh ok

jade steppe
#

Not .player

celest meadow
#

world.afterEvents.entityHitEntity.subscribe((eventData) => {
const player = eventData.damagingEntity;
const entity = eventData.hurtEntity;

jade steppe
#

Check each of events propertie