#how do i make this on interact

1 messages · Page 1 of 1 (latest)

rugged notch
#

import { world, Player } from "@minecraft/server";
import { ActionFormData } from "@minecraft/server-ui"
export function getScore(target, objective) {
try {
return world.scoreboard.getObjective(objective).getScore(typeof target === 'string' ? oB.getParticipants().find(pT => pT.displayName == target) : target.scoreboardIdentity)
} catch {
return 0
}
}

world.afterEvents.entityHitEntity.subscribe(data => {
if (data.hitEntity.hasTag("SpawnProtection")) {
let player = data.damagingEntity
if (!(player instanceof Player)) return;
let stats = data.hitEntity
let playerStats = new ActionFormData()
.title(§l§f${stats.name}'s Stats)
.body(§f${stats.name} balance is ${getScore(stats, money)}\n${stats.name} is §dLevel §d${getScore(stats, Level)})
.button("§fClose Menu")
playerStats.show(player).then(response => {
if (response.selection === 0) {
player.playSound(note.base);
player.sendMessage(§r§7[§u!§7]: You Have Just Viewed ${stats.name}'s Stats.)
}
})
}
})

#

i need this to activate when you interact with a player that has any tag rather than hitting player with the spawn protection tag

#

@here

celest hill
#

Just remove the if condition that check if the player has that specified tag?

#
import { world, Player } from "@minecraft/server";
import { ActionFormData } from "@minecraft/server-ui"
export function getScore(target, objective) {
    try {
        return world.scoreboard.getObjective(objective).getScore(typeof target === 'string' ? oB.getParticipants().find(pT => pT.displayName == target) : target.scoreboardIdentity)
    } catch {
        return 0
    }
}

world.afterEvents.entityHitEntity.subscribe(data => {
    let player = data.damagingEntity
    if (!(player instanceof Player)) return;
    let stats = data.hitEntity
    let playerStats = new ActionFormData()
        .title(`§l§f${stats.name}'s Stats`)
        .body(`§f${stats.name} balance is ${getScore(stats, `money`)}\n${stats.name} is §dLevel §d${getScore(stats, `Level`)}`)
        .button("§fClose Menu")
    playerStats.show(player).then(response => {
        if (response.selection === 0) {
            player.playSound(`note.base`);
            player.sendMessage(`§r§7[§u!§7]: You Have Just Viewed ${stats.name}'s Stats.`)
            }
    })
})