haxball / haxball-issues

115 stars 43 forks source link

Check quantity of administrator online. #1026

Closed Sielinton closed 4 years ago

Sielinton commented 4 years ago

How can I add a condition that if there is only 1 administrator online, the bot will grant administrator rights to another random player?

I tried some ways, like example = byPlayer.length but I believe it is necessary to check the list of players online with getPlayerList ()?

iAmLuks commented 4 years ago

https://github.com/haxball/haxball-issues/wiki/Headless-Host

Check "Example:" just below api

Sielinton commented 4 years ago

Thanks.

I tried it this way: if (players.find ((player) => player.admin)> 1) return; But player.find just looks for the administrator, does not return the amount.

I will try the following command: if (players.length ((player) => player.admin)> 1) return;

Wazarr94 commented 4 years ago

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array

What you're looking for is the filter method, and apply the length property. players.filter(p => p.admin).length returns the number of admins in the room.

Sielinton commented 4 years ago

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array

What you're looking for is the filter method, and apply the length property. players.filter(p => p.admin).length returns the number of admins in the room.

Exactly, thank you very much for your help!