Skip to content

Instantly share code, notes, and snippets.

@malte-laukoetter
Last active January 12, 2018 15:01
Show Gist options
  • Save malte-laukoetter/83936a71eb32674531d2f9b99f3065c3 to your computer and use it in GitHub Desktop.
Save malte-laukoetter/83936a71eb32674531d2f9b99f3065c3 to your computer and use it in GitHub Desktop.
A bit of code to automate https://forum.hivemc.com/threads/global-leaderboard.294527/ just needs to be copied into the devtools console on https://hive.lergin.de/player and can then be called like calcGlobalLeaderboardPointsPlayer("name")
async function calcGlobalLeaderboardPoints(pl){
let allGamesTotalPoints = await Promise.all(hive.GameTypes.list.map(async gt => {
let lb = new hive.Leaderboard(gt)
await lb.load(980,1000);
let places = await lb.load(998,1000);
let points = (places.get(998).points + places.get(999).points) / 2;
if(isNaN(points)){
points = await Promise.all([998,999].map(pl => places.get(pl).player.gameInfo(gt).then(info => info.points))).then(([a,b])=>(a+b)/2)
}
return points;
})).then(data => data.reduce((a,b) => a+b, 0));
let globalAvgPoints = allGamesTotalPoints / hive.GameTypes.list.length;
let plAvgPoints = await Promise.all(hive.GameTypes.list.map(async gt => {
let info = await pl.gameInfo(gt);
if(!info){
return 0;
}
let gmPoints = 0;
if(info.gamesPlayed){
gmPoints = info.gamesPlayed*100;
}
if(isNaN(gmPoints) && info.rolePoints){
gmPoints = info.rolePoints / 20;
}
if(isNaN(gmPoints) && info.captures && info.kills){
gmPoints = (info.kills + info.captures) / 2
}
if(isNaN(gmPoints) && info.data && info.data.games_played){
gmPoints = info.data.games_played * 100;
}
return info.points + gmPoints;
})).then(data => data.reduce((a,b) => a+b, 0));
return plAvgPoints / globalAvgPoints;
}
const calcGlobalLeaderboardPointsPlayer = name => calcGlobalLeaderboardPoints(new hive.Player(name)).then(points => console.log(`${name}: ${points}`))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment