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);
});
#how to do a player stats
1 messages · Page 1 of 1 (latest)
where did you find "world.events" ?
?
it doesn't exist and it's nowhere written in the documentation
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
world.afterEvents ?
to begin you can read the documentation: https://wiki.bedrock.dev/scripting/script-server.html
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?
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
yes thats the idea and the form should display that players scores with money and deaths and such aka "stats"
pls help this code is super broken
just tell me where you find your code ?
because playerInteractWithEntity does not exists neither
used this
gave me this:
@gusty tapir
cannot read property 'subscribe' of undefined in line world.afterEvents.playerInteractWithEntity.subscribe.... That means playerInteractWithEntity is not a existing event
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.
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
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);
});
this is what i was trying to do
interact
why doesnt it work
if i called apan this event?
did i spell it wrong?
_
because this class exists in the code but is not referenced anywhere
I think it's not possible, it will probably be implemented later
or it is not yet documented
ah
This is a workaround
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?
I don't know, you have to test
does any1 know how to do this?
?
.hasTag(`Tag`)
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
are you using 1.9?
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) => {
})
})
used this
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"
ty lol
So long story lol
?
Nah, i like to looking ppl talking and take a alot time but don't get it :)
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}`);
});
});```
ty @green badger
gGold Units§r: §r${money2}
like this
as form body
to display the player's stats
thx for this tho
Scoreboard?
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
Looks good
yeah...
but it nbeeds to show the stats of the person u right clicked
its to view other players stats
The target?
Oh lol then you need to get the targets scoreboard
What's your recent code
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
}
}```
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
GPT-4?
Yeah
lol we'll see if it works
Might need to make sure to hit entity not player
You need to know how to ask gpt4 correctl