#how to do a player stats

1 messages · Page 1 of 1 (latest)

inland breach
#
import { ActionFormData } from '@minecraft/server-ui';

world.events.playerInteractWithEntity.subscribe(eventData => {
    const { player, target } = eventData;
    if (!(target instanceof Player)) return;

    new ActionFormData()
        .title(`${target.name}'s Stats`)
        .body('Text you are going to show')
        .show(player);
});
inland breach
#

hello

#

anyone?

gusty tapir
inland breach
#

?

gusty tapir
#

it doesn't exist and it's nowhere written in the documentation

inland breach
#

uhhhh

#

💀

#

how do i make player stats then

#

lol

#

i just need it to be on interact and open stats showing the otehr platers scores

gusty tapir
#

world.afterEvents ?

inland breach
#

implimenting that will fix this?

#

and how do i add it

#

i am a begeiner

gusty tapir
inland breach
#

alright i will read up

#

but i need to make this player stats syetem sork tho

#
import { ActionFormData } from '@minecraft/server-ui';

world.afterEvents.playerInteractWithEntity.subscribe(eventData => {
    const { player, target } = eventData;
    if (!(target instanceof Player)) return;

    new ActionFormData()
        .title(`${target.name}'s Stats`)
        .body('Text you are going to show')
        .show(player);
});
#

look good?

gusty tapir
#

when you say player stats do you mean statistics?

#

because if your code works it will just open a form for you when you touch another player

inland breach
inland breach
#

pls help this code is super broken

gusty tapir
#

just tell me where you find your code ?

#

because playerInteractWithEntity does not exists neither

inland breach
#

gave me this:

#

@gusty tapir

gusty tapir
#

cannot read property 'subscribe' of undefined in line world.afterEvents.playerInteractWithEntity.subscribe.... That means playerInteractWithEntity is not a existing event

inland breach
#

what?

#

so hoe do i fix this

#

i want it to trigger apan right clicking player

gusty tapir
#

I tried to redirect you to the documentation because the answer to your question is in the documentation.

#

world.afterEvents.entityHitEntity

#

you have to look at the list of existing events to find the one that best meets your expectations.

inland breach
#

yes i understand but do you know if it would be p[ossible to do interact instead

#

because you cant pvp if it is hit

#

i have been made aware of hit event before

#

thank you for sending me the docs

gusty tapir
#

There are two types of events: afterEvents and beforeEvents.

#

beforeEvents will be able to cancel an action because they will be called before the action is done.

#

afterEvents will not be able to cancel an action because they are called after it has been executed

#

@inland breach

import { world, Player } from "@minecraft/server";
import { ActionFormData } from '@minecraft/server-ui';

world.afterEvents.entityHurt.subscribe(({ damageSource: { damagingEntity: source }, hurtEntity: target }) => {
  if (!(source instanceof Player && target instanceof Player)) return;
  new ActionFormData()
        .title(`${target.name}'s Stats`)
        .body('Text you are going to show')
        .show(source);
});
inland breach
#

this is what i was trying to do

#

interact

#

why doesnt it work

#

if i called apan this event?

#

did i spell it wrong?

gusty tapir
#

because this class exists in the code but is not referenced anywhere

inland breach
#

how do i fix that

#

😭

#

pls

gusty tapir
#

I think it's not possible, it will probably be implemented later

#

or it is not yet documented

inland breach
#

ah

inland breach
#

lmk if you know anyone who might know anything

#

also

#

could we make it so that the player hash to have “SpawnProtection” tag in order for it to trigger?

gusty tapir
#

I don't know, you have to test

inland breach
#

oh alr

#

well thanks for your efforts

#

i’ll keep looking into it

inland breach
#

does any1 know how to do this?

inland breach
#

?

inland breach
#

thank you but with interact

#

punch is alr but interact would be phenomenial

uncut delta
#

you need to use beta

#

to use interac

#

interact

inland breach
#

so it hasnt come oput yet

#

dang alright

#

thanks for letting me know

#
import { ActionFormData } from '@minecraft/server-ui';

world.afterEvents.playerInteractWithEntity.subscribe(eventData => {
    const { player, target } = eventData;
    // Check if the target is a Player and if they have the specific tag
    if (!(target instanceof Player) || !target.hasTag('Tag')) return;

    new ActionFormData()
        .title(`${target.name}'s Stats`)
        .body('Text you are going to show')
        .show(player);
});
#

@uncut delta

#

wont work

#

used ur fix

uncut delta
#

are you using 1.9?

uncut delta
# inland breach used ur fix
world.afterEvents.playerInteractWithEntity.subscribe((ev) => {
  const { player, target } = ev
  if(player.typeId !== "minecraft:player" || !target.hasTag(`Tag`)) return
  new ActionFormData().title(``)
  .body(`ActionForm`)
  .button(`Button 1`)
  .show(player).then((r) => {

  })
})
inland breach
uncut delta
inland breach
#

thank you for provifing that

#

how do i make the title diapley <player name>'s stats

#

in this case i am supposed to be viweing barqavius's stats

#

because i right clicked player "Barqavuis"

inland breach
manic dagger
#

So long story lol

inland breach
#

?

manic dagger
#

Nah, i like to looking ppl talking and take a alot time but don't get it :)

inland breach
#

how to i make it diaplay the player's scores and name

#

pls any1

green badger
#

world.afterEvents.playerInteractWithEntity.subscribe((ev) => {
  const { player, target } = ev;
  if (target.hasTag("Tag") && target.typeId != "minecraft:player") return

  new ActionFormData()
    .title(`${player.nameTag}'s Stats`)
    .body(`Select an option:`)
    .button(`Button 1`)
    .show(player)
    .then((response) => {
      if (response === 0) {
        player.sendMessage("You pressed Button 1!");
      }
    })
    .catch((error) => {
      console.error(`An error occurred showing the form: ${error}`);
    });
});```
inland breach
#

ty @green badger

#

gGold Units§r: §r${money2}

#

like this

#

as form body

#

to display the player's stats

green badger
#

Scoreboard?

inland breach
#

yes

#

to display the players money

#

can u do that?

green badger
#

world.afterEvents.playerInteractWithEntity.subscribe((ev) => {
    const { player, target } = ev;
    if (target.hasTag("Tag") && target.typeId != "minecraft:player") return
  
    new ActionFormData()
      .title(`${player.nameTag}'s Stats`)
      .body(`Select an option: \n Money: ${getScore(player, "money")}`)
      .button(`Button 1`)
      .show(player).then(response => {
        if (response.canceled) return;

        if (response.selection == 0) {
          player.sendMessage("You pressed Button 1!");
        }
      })
      .catch((error) => {
        console.error(`An error occurred showing the form: ${error}`);
      });
  });
  
  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
      }
  }


Add a getScore function to make it easier to use.

#

@inland breach

#

it works btw i tested in game

#

corrected the code there was an error for the button

#

@inland breach now try the button selection was wrong, i didn't notice until now. it should work now

inland breach
#

@green badger

#

i right clicked barqavius and it shows my stats

green badger
#

Looks good

inland breach
#

yeah...

#

but it nbeeds to show the stats of the person u right clicked

#

its to view other players stats

green badger
#

The target?

inland breach
#

yes

#

target

green badger
#

Oh lol then you need to get the targets scoreboard

inland breach
#

oh alr

#

could you show me?

#

im sorry i am a begeneir

#

and ilitarate lol

green badger
#

What's your recent code

inland breach
#
import { ActionFormData } from '@minecraft/server-ui';

world.afterEvents.playerInteractWithEntity.subscribe((ev) => {
    const { player, target } = ev;
    if (target.hasTag("playera") && target.typeId != "minecraft:player") return

    new ActionFormData()
        .title(`§8${player.nameTag}'s Stats`)
        .body(` §dTier§r: §b${getScore(player, "tier")}\n\n §eSkycoins§r: ${getScore(player, "money")}\n\n §nDungeon Points§r: ${getScore(player, "dp")}\n\n §gGold Units§r: ${getScore(player, "money2")}\n\n §nRunes§r: ${getScore(player, "rune")}/10`)
        .button(`§cClose\n§8Click or tap`)
        .show(player).then(response => {
            if (response.canceled) return;

            if (response.selection == 0) {
                player.sendMessage(` §aYou viewed ${player.nameTag}'s stats!`);
            }
        })
        .catch((error) => {
            console.error(`An error occurred showing player's stats: ${error}`);
        });
});

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
    }
}```
green badger
# inland breach ```import { world } from '@minecraft/server'; import { ActionFormData } from '@m...

import { world } from '@minecraft/server';
import { ActionFormData } from '@minecraft/server-ui';

world.afterEvents.playerInteractWithEntity.subscribe((ev) => {
    const { player, target } = ev;
    // Check if the target is a player
    if (target.typeId != "minecraft:player") return;

    // Use target's nameTag for title and scores
    new ActionFormData()
        .title(`§8${target.nameTag}'s Stats`)
        .body(` §dTier§r: §b${getScore(target, "tier")}\n\n §eSkycoins§r: ${getScore(target, "money")}\n\n §nDungeon Points§r: ${getScore(target, "dp")}\n\n §gGold Units§r: ${getScore(target, "money2")}\n\n §nRunes§r: ${getScore(target, "rune")}/10`)
        .button(`§cClose\n§8Click or tap`)
        .show(player).then(response => {
            if (response.canceled) return;

            if (response.selection == 0) {
                player.sendMessage(` §aYou viewed ${target.nameTag}'s stats!`);
            }
        })
        .catch((error) => {
            console.error(`An error occurred showing target's stats: ${error}`);
        });
});

function getScore(target, objective) {
    try {
        return world.scoreboard.getObjective(objective).getScore(target.scoreboardIdentity);
    } catch {
        return 0;
    }
}``` try this, I had ai do it for me
inland breach
#

GPT-4?

green badger
#

Yeah

inland breach
#

lol we'll see if it works

green badger
#

Might need to make sure to hit entity not player

green badger
inland breach
#

ty @green badger