#How i can make a Leaderboard
1 messages · Page 1 of 1 (latest)
i dont have any base of this entity
stop
you don't need any custom entity you can just use invisible armor stand
and where i put tis code i will not use form
up to you 🤷♂️ , get the entity you want to have the leader boards then use the code their
up to you 🤷♂️ , get the entity you want to have the leader boards then use the code their
?
Why just don't you let others help me if I can't and you don't want to help me
I can help you it's just that I want you to try first, then if you were not able to get anywhere then ask
I TRY
ok show me what you have
To begin with, I can't even find the code to make the leaderboard and 2 I don't have the code because I don't know how it works so if you can't help me, go help someone else.
import {system,world} from '@minecraft/server'
system.runInterval(()=>{
const list = []
const scores =
world.scoreboard.getObjective('Scores').getScores()//Returns a array of scores and participants of that objective
scores.sort((a,b)=>b.score-a.score) //Sorts it into a array from greatest to least
for (let i = 0; i<scores.length; i++){
const score = scores[i]
list.push(`${score.participant}:${score.score}`)
}
const board = list.join('\n')//Joins the array into one string with a new line seperator
const entity = world.getDimension('overworld').getEntities({tags:['LeaderBoard']}).find(e=>{
e.hasTag('LeaderBoard')
})
entity.nameTag = board
})
``` this should get you started
@main chasm
To be able to use the code I need to understand it
docs, https://jaylydev.github.io/scriptapi-docs/1.20.0/index.html https://learn.microsoft.com/en-us/minecraft/creator/scriptapi/minecraft/server/minecraft-server
ok
it imports the required modules for the code to work, then with the system.runInterval it runs the code in the ()=>{//code} at a constant interval, then in the code it setsup a variable list that is a array, then it setsup another variable scores which is a array scores and participiants in that objective, next it sorts the scores array to descending order(greatest to least) then it loops through all the elements in the scores array(for (let i = 0; i<scores.length; i++)) then pushs that data to the list array, then outside the loop, it setup a variable board that joins the list array into a string that is seperated by the \n seperator(like when you press ctrl space in discord to make a new line) then it gets the entities in the world with the tag leaderboard then finds the entity that has the tag leaderboard and sets the the nameTag of the entity to the board variable, hope this explains it, if not then look at the docs
make a leaderboard where? like on a entity or on a form?
can you help me
what entity
any
function getObjective(entity) {
const tag = entity.getTags().find(tag => tag.startsWith("objective:"));
return tag ? tag.slice(10) : null;
}
function getCustomName(entity) {
const tag = entity.getTags().find(tag => tag.startsWith("title:"));
return tag ? tag.slice(6) : null;
}
function getScore(entity, allPlayerNames, leaderboardObjective) {
const tag = entity.getTags().find(tag => tag.startsWith("scores:")) || "scores:[]";
const existingScores = JSON.parse(tag.slice(7)).filter(([name]) => !allPlayerNames.includes(name));
const newScore = world.getAllPlayers().map(oyuncu => {
try {
return [oyuncu.name, leaderboardObjective.getScore(oyuncu.scoreboardIdentity)];
} catch (error) {
return null;
}
}).filter(v => v);
const score = existingScores.concat(newScore).sort((a, b) => b[1] - a[1]).slice(0, 10);
entity.removeTag(tag);
entity.addTag(`scores:${JSON.stringify(score)}`);
return score;
}
function updateNameTag(entity, customName, scores) {
if (scores.length === 0) return;
const nameTag = `${customName || '§cUnnamed'}§r${scores.map(([name, score], i) => `\n§4${i + 1}. §c${name}§r: §p${score}`).join('')}`;
entity.nameTag = nameTag;
}
system.runInterval(() => {
const entities = world.getDimension("overworld").getEntities({ type: 'entity:hologram' });
for (const entity of entities) {
const leader = getObjective(entity);
if (!leader) continue;
const customName = getCustomName(entity);
const Objective = world.scoreboard.getObjective(leader);
const playerNames = world.getAllPlayers().map(oyuncu => oyuncu.name);
const scores = getScore(entity, playerNames, Objective);
updateNameTag(entity, customName, scores);
}
}, 20);```
o
ok i try
ok
is good
i try to make it good
hello, how can i make the scoreboard appear in game?
what tags do i need to give to the entity
what commands
i don't understand the code
sorry
i already have the scoreboard
/tag @s add "title:§6Kills"
i just need the commands to display the text on the entity's name
ok
did it work?
didn't work
what did u do
i changed the entity to a cow
minecraft:cow
then
i used these commands on the cow
oooh ok
One question, does this code work?
I'm going to try the code
look up in chat
It doesn't work when I put the objective tag it gives an error
the same you sent, but replacing @s with @e[type=cow]
and i added an objective with the name "Kills"
lemme join u