#Leaderboard
1 messages · Page 1 of 1 (latest)
@unborn reef
const { scoreboard } = world
const scoreboard_name = 'luck';
const Top_5_Players_Scores = () => {
let leaderBoard = scoreboard.getObjective(scoreboard_name)?.getScores()
.reduce((ar, { participant: { displayName }, score }) => {
ar.push({
player: displayName.split('.').pop(),
score
});
return ar;
}, [])
.sort((a, b) => a.score - b.score).splice(0, 4)
.map((entry, index) => (
`§r§b${index + 1}. §3${entry.player} §b${entry.score}\n`
))
for (; leaderBoard && leaderBoard.length < 3;) {
leaderBoard.push(`§r§b${leaderBoard.length + 1}. §3$N/A §bN/A\n`)
}
return leaderBoard
? '§3§lKOTH\n§r§b---------------\n' + leaderBoard.join('') + "§r§b---------------"
: ''
}
I would need the leaderboard to be the one with the most points to be TOP 1 and below fewer points
not like that
import { world, system } from "@minecraft/server";
const scoreboard = world.scoreboard;
const getObjective = obj => scoreboard.getObjective(obj) ?? scoreboard.addObjective(obj, obj);
function getLeaderBoard(objective, rankingNumber, increasing = true) {
const sort = increasing ? (a, b) => b.score - a.score : (a, b) => a.score - a.score;
const board = getObjective(objective)
.getScores().sort(sort).splice(0, rankingNumber)
.map(({ participant: { displayName }, score }) => ({ displayName, score }));
while (board.length < rankingNumber) {
board.push({ score: 0, displayName: 'N/A' });
}
return board;
};
system.runInterval(() => {
const leaderboard = getLeaderBoard('money', 3)
.map(({ displayName, score }, place) => `${++place}. ${displayName}: ${score}`).join('\n')
for (const player of world.getAllPlayers()) {
player.onScreenDisplay.setActionBar(leaderboard)
}
});
@loud birch
Thanks bro, de enserió gracias
¿Sería "true thanks"? XD no se pero de enserió gracais
recopy the runInterval
Ok
But xd
the rest is fine
how do want them to look like
So they are fine, I mean, the way I wanted them, but the 0 appears in the position that should be Number 1, not Number 0.
how do u manage player's score for that?
Do you mean what the score is?
i mean how do u use scoreboard players add
using script ?
I don't use a script for the scoreboard, I made some functions that make you rise in rank and points according to your eliminations
hmm
When I know more I would like to be able to make fake players to save their scores on the leaderboard
offline players will make this
You know I would like it to say TOP RANKING at the top
like the one who said KOTH
const heading = 'Leaderboard\n<---------->';
system.runInterval(() => {
const leaderboard = heading + getLeaderBoard('money', 3)
XD
Is there a way like on the KOTH leaderboard that Offline players appear alone
"OfflinePlayername"?
No All commands.scoreboard.players.Etc...
im making it rn
wow
question "rn" is Right now?
yes
Ok
@loud birch give this a try
const scoreboard = world.scoreboard;
const getObjective = obj => scoreboard.getObjective(obj) ?? scoreboard.addObjective(obj, obj);
const displayNamesObj = getObjective('display_names');
world.afterEvents.playerSpawn.subscribe(({ initialSpawn, player }) => {
let name
if (!initialSpawn || displayNamesObj.hasParticipant(name = player.name)) return;
const id = player.scoreboardIdentity?.id
displayNamesObj.setScore(name, id ?? scoreboard.getParticipants().sort((a, b) => a.id - b.id).pop().id + 1)
displayNames.set(id, name)
});
const displayNames = new Map(displayNamesObj.getParticipants()
.reduce((o, { type, id, displayName }) => {
return type === 'FakePlayer' ? o.concat([id, displayName]) : o
}, []));
and this is the new function```js
function getLeaderBoard(objective, rankingNumber, decreasing = true) {
const sort = decreasing ? (a, b) => b.score - a.score : (a, b) => a.score - b.score;
const board = getObjective(objective)
.getScores().sort(sort).splice(0, rankingNumber)
.map(({ participant: { id }, score }) => ({ displayName: displayNames.get(id), score }));
while (board.length < rankingNumber) {
board.push({ score: 0, displayName: 'N/A' });
}
return board;
};
thanks
But xd
@unborn reef
@loud birch try
return type === 'FakePlayer' ? [...o,[id, displayName]] : o
All llok god, no errors
Now it just needs to be displayed in the Actionbar
U can use the same runInterval I sent
este?
Like this
👍
still works??
SI
can create this leaderboard like floating text?
I'm looking for leaderboards like these but they will appear on the name of an entity that has a certain tag
If anyone could help me with that I would be grateful
i suggest learning the basics of javascript 1st before asking for big code
I know the veeery basics of JavaScript
And a little of how things work, so I can modify it later without breaking the code
aight
so basically, what i did here is record the player's scoreboardIdentity in an objective full of fakePlayer participants
cus fakePlayer type dont change displayname whatsoever
the score of fakeplayers are the same as the actual player's scoreboardIdentity.id
so i used that to make a map to get the player's displayname
hmm
here's a bit of visual of scoreboardjs const scoreboard = { getObjectives() { return [ { id: "displayNames", displayName: "displayNames", isValid(){}, addScore(){}, setScore(){}, getScore(){}, getScores(){}, hasParticipant(){}, removeParticipant(){}, getParticipants() { return [ { id: 38, type: "FakePlayer", displayName: "Remember M9" }, { id: 90, type: "FakePlayer", displayName: "Remember M3" }, { id: 91, type: "FakePlayer", displayName: "Remember M10" } ] } }, { id: "money", displayName: "§bMoney§r", getParticipants() { return [ { id: 10, type: "Player", displayName: "Remember M9" }, { id: 1, type: "Player", displayName: "Remember M3" }, { id: 27, type: "Player", displayName: "Remember M10" } ] } } ] } }
since the id of participant is number, I decided to use that as score for mapping
getScores() returns {score: number, participant}
array of em
then i used that array to make a map of displaynames
that score should be the same as the player.scoreboardIdentity.id
then to use that map,
const namesMap = new Map(world.scoreboard.getObjective("displayNames").
getScores().map(o => [o.score, o.participant.displayName]))
const richPlayer = world.scoreboard.getObjective("money")
.getScores().reduce((top, p) => {
if (top.score > p.score) return top
return p
}, { score: 0 })
const displayName = namesMap.get(richPlayer.participant.id)
world.sendMessage("richest: "+ displayName)
if ya'll want to avoid this much code, just use fakeplayer when managing the player's scoreboard
so there's no need to make a complex map just to get the participant's displayName