#Xp system

1 messages · Page 1 of 1 (latest)

dusk canopy
#
  ({ deadEntity, damageSource }) => {
    const health = deadEntity.getComponent('minecraft:health')
    if (health.currentValue > 0) return;
    if (!(damageSource.damagingEntity instanceof Player)) return
    damageSource.damagingEntity.sendMessage(`killed something`)
    damageSource.damagingEntity.runCommand(`scoreboard players add @s xp 10`)
  }
)``` would this be a efficient way to give xp/score when killing certain mobs
fresh lagoon
# dusk canopy ```world.afterEvents.entityDie.subscribe( ({ deadEntity, damageSource }) => { ...
import { Player, world } from "@minecraft/server";

world.afterEvents.entityDie.subscribe((eventData) => {
    const killedEntity = eventData.deadEntity;
    const player = eventData.damageSource.damagingEntity;
    if (player instanceof Player) {
        player.sendMessage(`killed smth`);
        let previousScore = 0;
        try { return player.scoreboardIdentity.getScore(world.scoreboard.getObjective("xp"));
        } catch {};
        player.scoreboardIdentity.setScore(world.scoreboard.getObjective("xp"), previousScore + 10);
    };
    return;
}); 
fervent hareBOT
#
No Errors

No errors in [code](#1120346958536659054 message)

dusk canopy
fresh lagoon
#

give me a minute

#
    setScore(entity, objective, number = 0) {
        if (world.scoreboard.getObjectives().filter(filter => filter.id == objective).length == 0) return false;
        const scoreboardEntityArgument = entity.scoreboardIdentity;
        world.scoreboard.getObjective(objective).setScore(scoreboardEntityArgument, number);
        return true;
    };
#

it's for entites

#

and here is for fake players

#
    setScore(partipicant, objective, number = 0) {
        if (world.scoreboard.getObjectives().filter(filter => filter.id == objective).length == 0) return false;
        world.getDimension('overworld').runCommandAsync(`scoreboard players set "${partipicant}" ${objective} ${number}`);
        return true;
    };
dusk canopy
#

ty

fresh lagoon
#

np

dusk canopy
fresh lagoon
#

class Zombie doesn't exist

#

so no

dusk canopy
fresh lagoon
#
if (player instanceof Player && killedEntity.typeId == 'minecraft:zombie') {
  // ur code here
};
dusk canopy
dusk canopy
#

@fresh lagoon

carmine river
# dusk canopy ```world.afterEvents.entityDie.subscribe( ({ deadEntity, damageSource }) => { ...
import { world } from "@minecraft/server"
const entityPoints = {
    "minecraft:zombie": {
        points: () => random(14, 1)
    }
};
globalThis.random = (a = 1, b = 0, c = true) => {
    [a, b] = (a > b ? [a, b] : [b, a]), a = Math.random() * (a - b) + b;
    return c ? Math.round(a) : a;
};
world.afterEvents.entityDie.subscribe(({ damageSource, deadEntity }) => {
    const killer = damageSource.damagingEntity;
    if (killer?.typeId !== 'minecraft:player') return;
    const entityType = deadEntity.typeId;
    if (entityType in entityPoints) {
        const score = entityPoints[entityType].points();
        killer.runCommandAsync(`scoreboard players add @s Money ${score}`);
        killer.playSound(`random.orb`)
        killer.sendMessage(`§6${score}`)
    }
}); 
carmine river
meager yarrow
meager yarrow
#

oh i see, the thing has a minimum and max value

#

you're swapping the variables values if the first one is greater than the second one

#

what does globalThis do

#

?

#

@carmine river

dusk canopy
modest bramble
modest bramble
#

world.afterEvents.entityDie.subscribe(({ damageSource, deadEntity }) => {
    const killer = damageSource.damagingEntity;
    if (killer?.typeId !== 'minecraft:player') return;
    const entityType = deadEntity.typeId;
    if (entityType in entityPoints) {
        const score = entityPoints[entityType][level] ?? 0;/*input the level here*/
        killer.runCommandAsync(`scoreboard players add @s Money ${score}`);
        killer.playSound(`random.orb`)
        killer.sendMessage(`§6${score}`)
    }
});```
dusk canopy
modest bramble
#

scoreboard?

dusk canopy
#

oh lmao and then getscore in the [level] part?

modest bramble
#

yeah

#

or perhaps calculate the level based on entity's armor

dusk canopy
meager yarrow
modest bramble
#

fr

dusk canopy
#

oh maybe in the future lol. thank you