#elo system Helppp

1 messages · Page 1 of 1 (latest)

compact depot
#

this is the elo system i have made so far, with the elo from player get from scoreboard and opponent elo (bot) is generated randomly. but there are some problems:

  • the elo generated in the second match and so on is the same as the one in the first match. and after the first match, elo from player wont change.
  • sometimes the code run twice. i use entity.spawn event to detect won or lose, but if anyone has better idea i will look for it
    im using 1.7.0 stable
compact depot
#

;-;

quasi crest
#

if you have a for loop like this

for (let player of world.getAllPlayers()) {
  world.afterEvents.entityDie.subscribe(evt => {
    // your code here
  });
}

it'll create one event for each player in the world

#

second, Math.random() will return a number, and the returned value will never change. you must create a random number again if you wish your code to summon random entities

quasi crest
#

let me see if I understand. you're summoning a horse to warn when the player wins, and you're summoning a snow golem when they lose, and the sheep will be used only to tell the rating of the opponent, right?

compact depot
#

for that i use command block to summon

quasi crest
#

you can use world.afterEvents.entityDie instead

compact depot
quasi crest
#
world.afterEvents.entityDie.subscribe(evt => {
  const source = evt.damageSource.damagingEntity;
  const target = evt.deadEntity;

  if (source) {
    // do your things here
  }
})
quasi crest
#

oh, I get it

#

you'll need to store the data on the enemy, you can use scoreboards or dynamic properties for it

compact depot
#

can i use sth like function outside the event and then if needed call it

#

my plan is call a random function when need the bot elo,but idk if thats gonna call random number everytime

quasi crest
#

yeah, you can

function something(value) {
  // something
}
world.afterEvents.entityDie.subscribe(evt => {
  something(evt);
});
#

also, is your random number thing supposed to return a value between -50 and 100?

quasi crest
#

so wasn't it supposed to be something like this?

let max = 50;
let min = 200;
let gene = 10 * Math.floor(Math.random() * (max - min + 1)) + min;
#

it is easier to understand, and multiplying Math.random by Math.random makes no sense either

compact depot
#

but the thing i need to know isthat if i call a function (random) twice, if it gonna return 2 different values

quasi crest
#
function generateRandomNumber(min, max) {
  return Math.random() * (max - min + 1) + min
}
compact depot
#

because my plan is

  • sheep spawn -> get a random number for bot elo
  • if win or lose -> do the math in my code
  • another sheep spawn -> get a different number for bot elo
#

so idk if i call the random function many times when the first sheep die, does it return different values for bot elo

quasi crest
#

a function call will execute all the code again, it'll not reuse the old saved values

#
function generateRandomNumber(min, max) {
  return Math.random() * (max - min + 1) + min
}

for (let x = 0; x < 100; x++) {
  console.log(10 * generateRandomNumber(50, 200));
}```
compact depot
#

so if i call the function, how can i reuse the value it generate before

quasi crest
#

store it outside the block

let lastRandomNumber = 0;

world.afterEvents.entitySpawn.subscribe(evt => {
  const randomNumber = 10 * generateRandomNumber(50, 200);
  // do some stuff
  lastRandomNumber = randomNumber;
});
compact depot
#

like that right

quasi crest
#

if that's how you want to do it, it's just like my example above

compact depot
#

ok i get it

#

ill try then if needed ill tell you

#

thank you

quasi crest
#

this one is in case that you want to remove the sheep and add or remove to the scoreboard when the player dies or kills an enemy

compact depot
quasi crest
quasi crest
compact depot
compact depot
quasi crest
#

you can check other addons for Minecraft, libraries for web development, and other things too so you can learn a lot of new stuff

compact depot
#

this is wat i have changed. the random number works now but when i summon snowball to detect win, nothing works can you check for me @quasi crest

compact depot
#

mb

#

now the thing is it seems to be wrong for the loser elo, the math is somewhat not right here

covert blade
#

Is this like a chess game

compact depot
#

its like that but no draw

compact depot
#

nvm guys i have managed to fix all bugs

#

but theres something else about the calculate idk if i was right or wrong

quasi crest
#

yeah, that was due to a problem with your math. if the win rate is of 0.09 and you multiply 32 by 0.09, you'll only get 9% of the value, and not 91%