#my code stopped working in 1.19.60

1 messages · Page 1 of 1 (latest)

lofty pivot
#
import { world, system } from '@minecraft/server'

//Sets the inCombat score to 30s:
world.events.entityHurt.subscribe((combatLog) => {
  const hit = combatLog.hurtEntity
  const attacker = combatLog.damagingEntity
  if (hit.typeId !== "minecraft:player" || attacker?.typeId !== "minecraft:player") return;
  
  //Telling the player if they are inCombat:
    if (getScore(attacker, 'inCombat') == 0) {
  attacker.tell("§l§cYou are now in §o§4Combat!")
  }
    if (getScore(hit, 'inCombat') == 0) {
hit.tell("§l§cYou are now in §o§4Combat!")
}
console.warn('Hit detected')
  hit.runCommandAsync('scoreboard players set @s inCombat 600')
  attacker.runCommandAsync('scoreboard players set @s inCombat 600')

//Kill system:
  const health = player.getComponent("minecraft:health").current
  if (hit.typeId !== "minecraft:player" || attacker?.typeId !== "minecraft:player") return;
  if (health <= 0) {
    attacker.runCommandAsync('scoreboard players add @s kills 1')
    attacker.runCommandAsync('effect @s instant_health 255 1 true')
  }
})

//Getting the player inCombat score:
function getScore(player, inCombat) {
  return world.scoreboard.getObjective(inCombat).getScore(player.scoreboard)
}

//Testing if the player has properly loaded in:
world.events.playerSpawn.subscribe((join) => {
        if (!join.initialSpawn) return;
  let player = join.player
  if (getScore(player, 'inCombat') !== 0) {
    world.say(`§l§4${player.name} §chas been killed for Combat Logging!`)
    player.runCommandAsync("scoreboard players set @s inCombat 0")
    player.runCommandAsync("kill @s")
    }
  }
}) 
#

The console warn isn't even doing anything and I'm getting no errors in the console log

#

Content log*

drowsy lintel
#

combatLog.damageSource.damagingEntity

plucky siren
#

why are you posting same question again and again

#

just use your old post

drowsy lintel
#
    }
})
```end
#

ngl, it's not easy to find your own post

plucky siren
lofty pivot
#

My Discord is broken

#

I can't see my old posts

#

They show up like threads

#

@drowsy lintel

#
import { world, system } from '@minecraft/server'

//Sets the inCombat score to 30s:
world.events.entityHurt.subscribe((combatLog) => {
  const hit = combatLog.hurtEntity
  const attacker = combatLog.damageSource.damagingEntity
  if (hit.typeId !== "minecraft:player" || attacker?.typeId !== "minecraft:player") return;
  
  //Telling the player if they are inCombat:
    if (getScore(attacker, 'inCombat') == 0) {
  attacker.tell("§l§cYou are now in §o§4Combat!")
  }
    if (getScore(hit, 'inCombat') == 0) {
hit.tell("§l§cYou are now in §o§4Combat!")
}
console.warn('Hit detected')
  hit.runCommandAsync('scoreboard players set @s inCombat 600')
  attacker.runCommandAsync('scoreboard players set @s inCombat 600')

//Kill system:
  const health = player.getComponent("minecraft:health").current
  if (hit.typeId !== "minecraft:player" || attacker?.typeId !== "minecraft:player") return;
  if (health <= 0) {
    attacker.runCommandAsync('scoreboard players add @s kills 1')
    attacker.runCommandAsync('effect @s instant_health 255 1 true')
  }
})

//Getting the player inCombat score:
function getScore(player, inCombat) {
  return world.scoreboard.getObjective(inCombat).getScore(player.scoreboard)
}

//Testing if the player has properly loaded in:
world.events.playerSpawn.subscribe((join) => {
	    if (!join.initialSpawn) return;
  let player = join.player
  if (getScore(player, 'inCombat') !== 0) {
    world.say(`§l§4${player.name} §chas been killed for Combat Logging!`)
    player.runCommandAsync("scoreboard players set @s inCombat 0")
    player.runCommandAsync("kill @s")
  }
}) 
#

Will this work?

lofty pivot
#

Still didn't work :(

#

First console log still isn't working

#

Do u know why

dull bloomBOT
#
Debug Result

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

<repl>.js:11:12 - error TS2339: Property 'tell' does not exist on type 'Entity'.

11   attacker.tell("§l§cYou are now in §o§4Combat!")
              ~~~~
<repl>.js:14:5 - error TS2339: Property 'tell' does not exist on type 'Entity'.

14 hit.tell("§l§cYou are now in §o§4Combat!")
       ~~~~
<repl>.js:21:18 - error TS2552: Cannot find name 'player'. Did you mean 'Player'?

21   const health = player.getComponent("minecraft:health").current
                    ~~~~~~

  @minecraft/server.d.ts:3428:15
    3428         class Player extends Entity {
                       ~~~~~~
    'Player' is declared here.

drowsy lintel
#

Perhaps player kill still doesn't work in entityHurt...

#

Idk

lofty pivot
#

But it worked before