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")
}
}
})
#my code stopped working in 1.19.60
1 messages · Page 1 of 1 (latest)
The console warn isn't even doing anything and I'm getting no errors in the console log
Content log*
combatLog.damageSource.damagingEntity
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?
Try it
Debug Result
There are errors in this [code](#1073965334631039047 message):
[36m<repl>.js[0m:[33m11[0m:[33m12[0m - [31merror[0m[30m TS2339: [0mProperty 'tell' does not exist on type 'Entity'.
[7m11[0m attacker.tell("§l§cYou are now in §o§4Combat!")
[7m [0m [31m ~~~~[0m
[36m<repl>.js[0m:[33m14[0m:[33m5[0m - [31merror[0m[30m TS2339: [0mProperty 'tell' does not exist on type 'Entity'.
[7m14[0m hit.tell("§l§cYou are now in §o§4Combat!")
[7m [0m [31m ~~~~[0m
[36m<repl>.js[0m:[33m21[0m:[33m18[0m - [31merror[0m[30m TS2552: [0mCannot find name 'player'. Did you mean 'Player'?
[7m21[0m const health = player.getComponent("minecraft:health").current
[7m [0m [31m ~~~~~~[0m
[36m@minecraft/server.d.ts[0m:[33m3428[0m:[33m15[0m
[7m3428[0m class Player extends Entity {
[7m [0m [36m ~~~~~~[0m
'Player' is declared here.
But it worked before