#XP

1 messages · Page 1 of 1 (latest)

halcyon totem
#

how can i detect if the player has collected xp. if my only option is scripts can someone give me all the code i need to make it work as i dont do scripts

halcyon totem
#

huh?

outer reef
#

What he means is that when the player collect XP, it's not get XP from player

halcyon totem
#

no i ment when the players collects a xp orb

tranquil oasis
#

Detect how much total xp the player has, and compare it after it collected an XPs.

kindred orbit
# halcyon totem no i ment when the players collects a xp orb

Well there is not event that handles this but you can run a check every tick to see if the xp has changed with abosberation limits it should be fine

system.runInterval(() => {
    for (let player of world.getAllPlayers()) {
        const xp = player.getTotalXp()
        if ( player.lastXp < xp ) {
           //Stuff
        }
        player.lastXp = xp
    }
})
tranquil oasis
#

Or just use getTotalXp() so it covers overall player's xp including when leveling up.

craggy whale
#

@kindred orbit
Where do you get "mc.world.getAllPlayers()"?

kindred orbit
fresh gulch
#

Hes talking about the total xp.

#

" 💀 "

frozen bone
#

get the nearest player to the orb

#

and thats the player that collected

kindred orbit