haxball / haxball-issues

115 stars 43 forks source link

Haxball Headless API #284

Closed bartosz-lanik closed 6 years ago

bartosz-lanik commented 6 years ago

Hello. Function getPlayerList() should have an option to choose a team to select from. Function setPlayerTeam() should have an option to move all players from team to spec. Greetings, Manderigon.

Raamyy commented 6 years ago

You can filter them using filter() function

Raamyy commented 6 years ago

Feel free making your own functions using existing ones. As an example you can make function that is called resetPlayers() which loops on all of the players and use setPlayerTeam() to set their teams into 0 (Spectator teamId).

Wrathen commented 6 years ago

function GetRedTeam(){return room.getPlayerList().filter((player) => player.team == 1);}; function GetBlueTeam(){return room.getPlayerList().filter((player) => player.team == 2);}; function GetSpecTeam(){return room.getPlayerList().filter((player) => player.team == 0);};

or function GetTeam(id){return room.getPlayerList().filter((player) => player.team == id);};

To Move Everyone To Spec: function MoveAllToSpec() { var allPlayers = room.getPlayerList().filter((player) => player.id!= 0); for(var i = 0; i < allPlayers.length; i++) { room.setPlayerTeam(allPlayers[i].id, 0); } room.sendChat("Done!"); }

basro commented 6 years ago

I wont be adding these methods since they are easily doable from the already existing api.