Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- This script is usable in https://www.haxball.com/headless
- Steps:
- 1) Copy this script
- 2) Go to the link, then press F12
- 3) Go to console if it's not already set, then paste
- 4) Enter
- 5) IF THIS TAB IS CLOSED THE ROOM WILL BE CLOSED TOO
- */
- var room = HBInit({ roomName: "FUTSAL 4V4", maxPlayers: 14, playerName : "BANDZIOREK", public : true});
- var futsal = `{
- "name" : "Futsal ChujowyRanking 4v4",
- "width" : 1006,
- "height" : 452,
- "spawnDistance" : 310,
- "bg" : { "type" : "hockey", "width" : 786, "height" : 386, "kickOffRadius" : 106, "cornerRadius" : 0 },
- "vertexes" : [
- /* 0 */ { "x" : -787, "y" : 386, "bCoef" : 1, "cMask" : ["ball" ], "trait" : "ballArea" },
- /* 1 */ { "x" : -787, "y" : 107, "bCoef" : 1, "cMask" : ["ball" ], "trait" : "ballArea" },
- /* 2 */ { "x" : -787, "y" : -107, "bCoef" : 1, "cMask" : ["ball" ], "trait" : "ballArea" },
- /* 3 */ { "x" : -787, "y" : -385, "bCoef" : 1, "cMask" : ["ball" ], "trait" : "ballArea" },
- /* 4 */ { "x" : 787, "y" : 386, "bCoef" : 1, "cMask" : ["ball" ], "trait" : "ballArea" },
- /* 5 */ { "x" : 787, "y" : 107, "bCoef" : 1, "cMask" : ["ball" ], "trait" : "ballArea" },
- /* 6 */ { "x" : 787, "y" : -107, "bCoef" : 1, "cMask" : ["ball" ], "trait" : "ballArea" },
- /* 7 */ { "x" : 787, "y" : -385, "bCoef" : 1, "cMask" : ["ball" ], "trait" : "ballArea" },
- /* 8 */ { "x" : 0, "y" : 106, "trait" : "kickOffBarrier", "curve" : -180 },
- /* 9 */ { "x" : 0, "y" : -106, "trait" : "line", "curve" : -180 },
- /* 10 */ { "x" : -874, "y" : -108, "bCoef" : 0.1, "cMask" : ["ball" ], "trait" : "goalNet" },
- /* 11 */ { "x" : 856, "y" : -108, "bCoef" : 0.1, "cMask" : ["ball" ], "trait" : "goalNet" },
- /* 12 */ { "x" : -874, "y" : 107, "bCoef" : 0.1, "cMask" : ["ball" ], "trait" : "goalNet" },
- /* 13 */ { "x" : 856, "y" : 105, "bCoef" : 0.1, "cMask" : ["ball" ], "trait" : "goalNet" },
- /* 14 */ { "x" : -787, "y" : -286, "trait" : "line" },
- /* 15 */ { "x" : -567, "y" : -50, "trait" : "line" },
- /* 16 */ { "x" : 787, "y" : -286, "trait" : "line" },
- /* 17 */ { "x" : 567, "y" : -50, "trait" : "line" },
- /* 18 */ { "x" : -787, "y" : 286, "trait" : "line" },
- /* 19 */ { "x" : -567, "y" : 50, "trait" : "line" },
- /* 20 */ { "x" : 787, "y" : 286, "trait" : "line" },
- /* 21 */ { "x" : 567, "y" : 50, "trait" : "line" },
- /* 22 */ { "x" : 787, "y" : 386, "bCoef" : 1, "trait" : "ballArea" },
- /* 23 */ { "x" : 787, "y" : -385, "bCoef" : 1, "trait" : "ballArea" },
- /* 24 */ { "x" : 0, "y" : 386, "bCoef" : 0, "trait" : "line" },
- /* 25 */ { "x" : 0, "y" : -385, "bCoef" : 0, "trait" : "line" },
- /* 26 */ { "x" : 0, "y" : 106, "trait" : "kickOffBarrier" },
- /* 27 */ { "x" : 0, "y" : -106, "trait" : "kickOffBarrier" },
- /* 28 */ { "x" : 896, "y" : 395, "bCoef" : 1, "cMask" : ["ball" ], "cGroup" : ["all" ], "trait" : "ballArea", "color" : "000000" },
- /* 29 */ { "x" : 896, "y" : 110, "bCoef" : 1, "cMask" : ["ball" ], "cGroup" : ["all" ], "trait" : "ballArea", "color" : "000000" },
- /* 30 */ { "x" : 896, "y" : -394, "bCoef" : 1, "cMask" : ["ball" ], "cGroup" : ["all" ], "trait" : "ballArea", "color" : "000000" },
- /* 31 */ { "x" : 896, "y" : -110, "bCoef" : 1, "cMask" : ["ball" ], "cGroup" : ["all" ], "trait" : "ballArea", "color" : "000000" },
- /* 32 */ { "x" : -896, "y" : 110, "bCoef" : 1, "cMask" : ["ball" ], "cGroup" : ["all" ], "trait" : "ballArea", "color" : "000000" },
- /* 33 */ { "x" : -896, "y" : 395, "bCoef" : 1, "cMask" : ["ball" ], "cGroup" : ["all" ], "trait" : "ballArea", "color" : "000000" },
- /* 34 */ { "x" : -896, "y" : -395, "bCoef" : 1, "cMask" : ["ball" ], "cGroup" : ["all" ], "trait" : "ballArea", "color" : "000000" },
- /* 35 */ { "x" : -896, "y" : -110, "bCoef" : 1, "cMask" : ["ball" ], "cGroup" : ["all" ], "trait" : "ballArea", "color" : "000000" },
- /* 36 */ { "x" : 0, "y" : 401, "bCoef" : 0.1, "cMask" : ["red","blue" ], "trait" : "kickOffBarrier" },
- /* 37 */ { "x" : 0, "y" : 106, "bCoef" : 0.1, "cMask" : ["red","blue" ], "trait" : "kickOffBarrier" },
- /* 38 */ { "x" : 0, "y" : -401, "bCoef" : 0.1, "cMask" : ["red","blue" ], "cGroup" : ["redKO","blueKO" ], "trait" : "kickOffBarrier" },
- /* 39 */ { "x" : 0, "y" : -106, "bCoef" : 0.1, "cMask" : ["red","blue" ], "cGroup" : ["redKO","blueKO" ], "trait" : "kickOffBarrier" },
- /* 40 */ { "x" : -896, "y" : 395, "bCoef" : 1, "cMask" : ["ball" ], "cGroup" : ["all" ], "trait" : "ballArea", "color" : "000000" },
- /* 41 */ { "x" : 896, "y" : 395, "bCoef" : 1, "cMask" : ["ball" ], "cGroup" : ["all" ], "trait" : "ballArea", "color" : "000000" },
- /* 42 */ { "x" : -896, "y" : -395, "bCoef" : 1, "cMask" : ["ball" ], "cGroup" : ["all" ], "trait" : "ballArea", "color" : "000000" },
- /* 43 */ { "x" : 896, "y" : -394, "bCoef" : 1, "cMask" : ["ball" ], "cGroup" : ["all" ], "trait" : "ballArea", "color" : "000000" }
- ],
- "segments" : [
- { "v0" : 0, "v1" : 1, "trait" : "ballArea" },
- { "v0" : 2, "v1" : 3, "trait" : "ballArea" },
- { "v0" : 4, "v1" : 5, "trait" : "ballArea" },
- { "v0" : 6, "v1" : 7, "trait" : "ballArea" },
- { "v0" : 8, "v1" : 9, "curve" : 180, "cGroup" : ["blueKO" ], "trait" : "kickOffBarrier" },
- { "v0" : 8, "v1" : 9, "curve" : -180, "cGroup" : ["redKO" ], "trait" : "kickOffBarrier" },
- { "v0" : 2, "v1" : 10, "curve" : -3.819298738904888, "vis" : true, "color" : "FFFFFF", "bCoef" : 0.1, "cMask" : ["ball" ], "trait" : "goalNet" },
- { "v0" : 6, "v1" : 11, "curve" : 0, "vis" : true, "color" : "FFFFFF", "bCoef" : 0.1, "cMask" : ["ball" ], "trait" : "goalNet" },
- { "v0" : 1, "v1" : 12, "curve" : 0, "vis" : true, "color" : "FFFFFF", "bCoef" : 0.1, "cMask" : ["ball" ], "trait" : "goalNet" },
- { "v0" : 5, "v1" : 13, "curve" : 0, "vis" : true, "color" : "FFFFFF", "bCoef" : 0.1, "cMask" : ["ball" ], "trait" : "goalNet" },
- { "v0" : 10, "v1" : 12, "curve" : 0, "vis" : true, "color" : "FFFFFF", "bCoef" : 0.1, "cMask" : ["ball" ], "trait" : "goalNet", "x" : -915 },
- { "v0" : 11, "v1" : 13, "curve" : 1.0512692129152263, "vis" : true, "color" : "FFFFFF", "bCoef" : 0.1, "cMask" : ["ball" ], "trait" : "goalNet", "x" : 585 },
- { "v0" : 14, "v1" : 15, "curve" : 90, "color" : "FFFFFF", "trait" : "line" },
- { "v0" : 16, "v1" : 17, "curve" : -90, "color" : "FFFFFF", "trait" : "line" },
- { "v0" : 18, "v1" : 19, "curve" : -90, "color" : "FFFFFF", "trait" : "line" },
- { "v0" : 20, "v1" : 21, "curve" : 90, "color" : "FFFFFF", "trait" : "line" },
- { "v0" : 15, "v1" : 19, "curve" : 0, "vis" : true, "color" : "FFFFFF", "bCoef" : 0, "trait" : "line" },
- { "v0" : 17, "v1" : 21, "curve" : 0, "vis" : true, "color" : "FFFFFF", "bCoef" : 0, "trait" : "line", "x" : 667 },
- { "v0" : 1, "v1" : 0, "vis" : true, "color" : "FFFFFF", "bCoef" : 1, "cMask" : ["ball" ], "trait" : "ballArea", "x" : -665 },
- { "v0" : 5, "v1" : 4, "vis" : true, "color" : "FFFFFF", "bCoef" : 1, "cMask" : ["ball" ], "trait" : "ballArea", "x" : 665 },
- { "v0" : 2, "v1" : 3, "vis" : true, "color" : "FFFFFF", "bCoef" : 1, "cMask" : ["ball" ], "trait" : "ballArea", "x" : -665 },
- { "v0" : 6, "v1" : 7, "vis" : true, "color" : "FFFFFF", "bCoef" : 1, "cMask" : ["ball" ], "trait" : "ballArea", "x" : 665 },
- { "v0" : 0, "v1" : 22, "vis" : true, "color" : "FFFFFF", "bCoef" : 1, "trait" : "ballArea", "y" : 290 },
- { "v0" : 3, "v1" : 23, "vis" : true, "color" : "FFFFFF", "bCoef" : 1, "trait" : "ballArea", "y" : -290 },
- { "v0" : 24, "v1" : 25, "curve" : 0, "vis" : true, "color" : "FFFFFF", "bCoef" : 0, "trait" : "line" },
- { "v0" : 9, "v1" : 8, "curve" : -180, "vis" : true, "color" : "FFFFFF", "bCoef" : 0, "trait" : "line" },
- { "v0" : 27, "v1" : 26, "curve" : 180, "vis" : true, "color" : "FFFFFF", "bCoef" : 0, "trait" : "line" },
- { "v0" : 2, "v1" : 1, "curve" : 0, "vis" : true, "color" : "FFFFFF", "bCoef" : 0, "trait" : "line", "x" : -887 },
- { "v0" : 6, "v1" : 5, "curve" : 0, "vis" : true, "color" : "FFFFFF", "bCoef" : 0, "trait" : "line" },
- { "v0" : 28, "v1" : 29, "vis" : false, "color" : "000000", "bCoef" : 1, "cMask" : ["ball" ], "cGroup" : ["all" ], "trait" : "ballArea" },
- { "v0" : 30, "v1" : 31, "vis" : false, "color" : "000000", "bCoef" : 1, "cMask" : ["ball" ], "cGroup" : ["all" ], "trait" : "ballArea" },
- { "v0" : 32, "v1" : 33, "vis" : false, "color" : "000000", "bCoef" : 1, "cMask" : ["ball" ], "cGroup" : ["all" ], "trait" : "ballArea", "x" : -896 },
- { "v0" : 34, "v1" : 35, "vis" : false, "color" : "000000", "bCoef" : 1, "cMask" : ["ball" ], "cGroup" : ["all" ], "trait" : "ballArea", "x" : -896 },
- { "v0" : 36, "v1" : 37, "vis" : false, "color" : "FFFFFF", "bCoef" : 0.1, "cMask" : ["red","blue" ], "trait" : "kickOffBarrier", "x" : 0 },
- { "v0" : 38, "v1" : 39, "vis" : false, "color" : "FFFFFF", "bCoef" : 0.1, "cMask" : ["red","blue" ], "cGroup" : ["redKO","blueKO" ], "trait" : "kickOffBarrier" },
- { "v0" : 40, "v1" : 41, "vis" : false, "color" : "000000", "bCoef" : 1, "cMask" : ["ball" ], "cGroup" : ["all" ], "trait" : "ballArea" },
- { "v0" : 42, "v1" : 43, "vis" : false, "color" : "000000", "bCoef" : 1, "cMask" : ["ball" ], "cGroup" : ["all" ], "trait" : "ballArea" }
- ],
- "goals" : [
- { "p0" : [-788,-104 ], "p1" : [-786,102 ], "team" : "red" },
- { "p0" : [787,-100 ], "p1" : [787,101 ], "team" : "blue" }
- ],
- "discs" : [
- { "radius" : 6, "pos" : [-786,108 ], "color" : "FFFFFF", "trait" : "goalPost" },
- { "radius" : 6, "pos" : [-787,-107 ], "color" : "FFFFFF", "trait" : "goalPost" },
- { "radius" : 6, "pos" : [787.00002288818,108 ], "color" : "FFFFFF", "trait" : "goalPost" },
- { "radius" : 6, "pos" : [786.00002288818,-107 ], "color" : "FFFFFF", "trait" : "goalPost" }
- ],
- "planes" : [
- { "normal" : [1,0 ], "dist" : -1001, "bCoef" : 1 },
- { "normal" : [-0.99998232014678,-0.0059463765320919 ], "dist" : -1009.0178392873, "bCoef" : 1 },
- { "normal" : [0,1 ], "dist" : -449, "bCoef" : 1 },
- { "normal" : [0,-1 ], "dist" : -455, "bCoef" : 1 }
- ],
- "traits" : {
- "ballArea" : { "vis" : false, "bCoef" : 1, "cMask" : ["ball" ] },
- "goalPost" : { "radius" : 8, "invMass" : 0, "bCoef" : 1 },
- "goalNet" : { "vis" : true, "bCoef" : 0.1, "cMask" : ["all" ] },
- "kickOffBarrier" : { "vis" : false, "bCoef" : 0.1, "cGroup" : ["redKO","blueKO" ], "cMask" : ["red","blue" ] },
- "line" : { "vis" : true, "bCoef" : 0, "cMask" : ["" ] },
- "arco" : { "radius" : 2, "cMask" : ["n/d" ], "color" : "cccccc" }
- },
- "playerPhysics" : {
- "acceleration" : 0.11,
- "kickingAcceleration" : 0.1,
- "kickStrength" : 6.5
- },
- "ballPhysics" : {
- "radius" : 6.4,
- "color" : "EAFF00"
- }
- }`;
- room.setCustomStadium(futsal);
- room.setScoreLimit(3);
- room.setTimeLimit(5);
- /*
- Functions
- */
- // If there are no admins left in the room give admin to one of the remaining players.
- function updateAdmins() {
- // Get all players except the host (id = 0 is always the host)
- var players = room.getPlayerList().filter((player) => player.id != 0 );
- if ( players.length == 0 ) return; // No players left, do nothing.
- if ( players.find((player) => player.admin) != null ) return; // There's an admin left so do nothing.
- room.setPlayerAdmin(players[0].id, true); // Give admin to the first non admin player in the list
- }
- function initPlayerStats(player){
- if (stats.get(player.name)) return;
- stats.set(player.name, [0, 0, 0, 0, 0, 0]) // goals, assists, wins, loses, og, cs
- }
- /*
- for commands
- */
- function swapFun(player){
- if (player.admin == true){
- if (room.getScores() == null) {
- players = room.getPlayerList();
- for (i = 0; i < players.length; i++){
- if (players[i].team == 1){
- room.setPlayerTeam(players[i].id, 2);
- }
- else if (players[i].team == 2){
- room.setPlayerTeam(players[i].id, 1);
- }
- }
- }
- }
- }
- function pushMuteFun(player, message){ // !mute Anddy
- // Prevent somebody to talk in the room (uses the nickname, not the id)
- // need to be admin
- if (player.admin == true){
- if (!(mutedPlayers.includes(message.substr(6)))) mutedPlayers.push(message.substr(6));
- }
- }
- function gotMutedFun(player){
- if (mutedPlayers.includes(player.name)){
- return true;
- }
- }
- function unmuteFun(player, message){ // !unmute Anddy
- // Allow somebody to talk if he has been muted
- // need to be admin
- if (player.admin == true){
- pos = mutedPlayers.indexOf(message.substr(9));
- mutedPlayers.splice(pos, 1);
- }
- }
- function adminFun(player, message){ // !admin Anddyisthebest
- // Gives admin to the person who type this password
- room.setPlayerAdmin(player.id, true);
- return false; // The message won't be displayed
- }
- function putPauseFun() { // p
- room.pauseGame(true);
- }
- function unPauseFun() { // !p
- room.pauseGame(false);
- }
- function helpFun() { // !help
- room.sendChat('Komendy: "p", "!p" , "!stats Nickname", "!ranking", "!poss", "!resetstats", "!adminhelp", "!gkhelp", "!rankhelp"');
- }
- function adminHelpFun() {
- room.sendChat('Komendy: "!mute Player", "!unmute Player", ' +
- '"!clearbans", "!rr", "!swap" ')
- }
- function gkHelpFun() { // !gkhelp
- room.sendChat('Gracz najbliższy własnej bramki zostaje uznany bramkarzem).')
- }
- function rankHelpFun() { // !gkhelp
- room.sendChat("Zdobądź punkty! Gol: 1 pkt, Asysta: 1 pkt, Win: 1 pkt, cs: 1 pkt, Lose: -1 pkt, Og: -1 pkt.")
- }
- function statsFun(player, message){ // !stats Anddy
- if (stats.get(message.substr(7))){
- sendStats(message.substr(7));
- } else{ return false;}
- }
- function rankFun() { // !ranking
- string = ranking();
- room.sendChat("Ranking: " + string);
- }
- function resetStatsFun (player){ // !resetstats
- if (rankingCalc(player.name) > 0){
- stats.set(player.name, [0,0,0,0,0,0]);
- room.sendChat("Twoje statystyki zostały zresetowane! ")
- }
- else (room.sendChat("Musisz mieć pozytywny bilans."))
- }
- function clearFun(player){ // !clear
- if (player.admin == true) room.clearBans();
- }
- function resetFun(player){
- if (player.admin == true){
- room.stopGame();
- room.startGame();
- }
- }
- function gkFun(player){ // !gk
- if (room.getScores() != null && room.getScores().time < 60){
- if (player.team == 1) {
- gk[0] = player;
- }
- else if (player.team == 2){
- gk[1] = player;
- }
- }
- return;
- }
- function closeFun(player){
- if (player.name == "ADMIN CHUJ"){ // artificially generate an error in order to close the room
- stats.crash();
- }
- }
- /*
- For ranking
- */
- function rankingCalc(player){
- return stats.get(player)[0] * 1 + stats.get(player)[1] * 1 +
- stats.get(player)[2] * 1 + stats.get(player)[5] * 1 -
- stats.get(player)[3] * 1 - stats.get(player)[4] * 1;
- }
- function ranking(){
- var overall = [];
- players = Array.from(stats.keys());
- for (var i = 2; i < players.length; i++) {
- score = rankingCalc(players[i])
- // Goal: 5 pts, assist: 3 pts, win: 3 pts, cs: 6 pts, lose: -7 pts, og: -4 pts
- overall.push({name: players[i], value: score});
- }
- overall.sort(function(a,b){
- return b.value - a.value;
- })
- string = "";
- for (var i = 0; i < overall.length; i++) {
- if (overall[i].value != 0){
- string += i+1 + ") " + overall[i].name + ": " + overall[i].value + " pts, ";
- }
- }
- return string;
- }
- function sendStats(name){
- ps = stats.get(name); // stands for playerstats
- room.sendChat(name + ": Gole: " + ps[0] + ", Asysty: " + ps[1]
- + ", Samobóje: " + ps[4] + ", Czyste konta: " + ps[5] + ", Wygrane: " + ps[2] + ", Przegrane: " + ps[3] +
- " Punkty: " + rankingCalc(name));
- }
- function whichTeam(){ // gives the players in the red or blue team
- var players = room.getPlayerList();
- var redTeam = players.filter(player => player.team == 1);
- var blueTeam = players.filter(player => player.team == 2);
- return [redTeam, blueTeam]
- }
- function isGk(){ // gives the mosts backward players before the first kickOff
- var players = room.getPlayerList();
- var min = players[0];
- min.position = {x: room.getBallPosition().x + 60}
- var max = min;
- for (var i = 0; i < players.length; i++) {
- if (players[i].position != null){
- if (min.position.x > players[i].position.x) min = players[i];
- if (max.position.x < players[i].position.x) max = players[i];
- }
- }
- return [min, max]
- }
- function updateWinLoseStats(winners, losers){
- for (var i = 0; i < winners.length; i++) {
- stats.get(winners[i].name)[2] += 1;
- }
- for (var i = 0; i < losers.length; i++) {
- stats.get(losers[i].name)[3] += 1;
- }
- }
- function initBallCarrying(redTeam, blueTeam){
- var ballCarrying = new Map();
- var playing = redTeam.concat(blueTeam);
- for (var i = 0; i < playing.length; i++) {
- ballCarrying.set(playing[i].name, [0, playing[i].team]); // secs, team, %
- }
- return ballCarrying;
- }
- function updateTeamPoss(value){
- if (value[1] == 1) redPoss += value[0];
- if (value[1] == 2) bluePoss += value[0];
- }
- var bluePoss;
- var redPoss;
- function teamPossFun(){
- if (room.getScores() == null) return false;
- bluePoss = 0;
- redPoss = 0
- ballCarrying.forEach(updateTeamPoss);
- redPoss = Math.round((redPoss / room.getScores().time) * 100);
- bluePoss = Math.round((bluePoss / room.getScores().time) * 100);
- room.sendChat("Posiadanie piłki: RED " + redPoss + "% - BLUE " + bluePoss + "% " );
- }
- /*
- For the game
- */
- // Gives the last player who touched the ball, works only if the ball has the same
- // size than in classics maps.
- var radiusBall = 10;
- var triggerDistance = radiusBall + 15 + 0.1;
- function getLastTouchTheBall(lastPlayerTouched, time) {
- var ballPosition = room.getBallPosition();
- var players = room.getPlayerList();
- for(var i = 0; i < players.length; i++) {
- if(players[i].position != null) {
- var distanceToBall = pointDistance(players[i].position, ballPosition);
- if(distanceToBall < triggerDistance) {
- lastPlayerTouched = players[i];
- return lastPlayerTouched;
- }
- }
- }
- return lastPlayerTouched;
- }
- // Calculate the distance between 2 points
- function pointDistance(p1, p2) {
- var d1 = p1.x - p2.x;
- var d2 = p1.y - p2.y;
- return Math.sqrt(d1 * d1 + d2 * d2);
- }
- function isOvertime(){
- scores = room.getScores();
- if (scores != null){
- if (scores.timeLimit != 0){
- if (scores.time > scores.timeLimit){
- if (scores.red == 0 && hasFinished == false){
- stats.get(gk[0].name)[5] += 1;
- stats.get(gk[1].name)[5] += 1;
- hasFinished = true;
- }
- }
- }
- }
- }
- // return: the name of the team who took a goal
- var team_name = team => team == 1 ? "Blue" : "Red";
- // return: whether it's an OG
- var isOwnGoal = (team, player) => team != player.team ? " (samobój)" : "";
- // return: a better display of the second when a goal is scored
- var floor = s => s < 10 ? "0" + s : s;
- // return: whether there's an assist
- var playerTouchedTwice = playerList => playerList[0].team == playerList[1].team ? " (Asysta: " + playerList[1].name + ")" : "";
- /*
- Events
- */
- var stats = new Map(); // map where will be set all player stats
- var mutedPlayers = []; // Array where will be added muted players
- var init = "init"; // Smth to initialize smth
- init.id = 0; // Faster than getting host's id with the method
- init.name = "init";
- var scorers ; // Map where will be set all scorers in the current game (undefined if reset or end)
- var whoTouchedLast; // var representing the last player who touched the ball
- var whoTouchedBall = [init, init]; // Array where will be set the 2 last players who touched the ball
- var gk = [init, init];
- var goalScored = false;
- var commands = {
- // Command that doesnt need to know players attributes.
- "!help": helpFun,
- "!gkhelp": gkHelpFun,
- "!adminhelp": adminHelpFun,
- "!rankhelp": rankHelpFun,
- "!ranking": rankFun,
- "p": putPauseFun,
- "!p": unPauseFun,
- "!poss": teamPossFun,
- // Command that need to know who is the player.
- "!resetstats": resetStatsFun,
- "!gk": gkFun,
- "!bettingexpert": adminFun,
- // Command that need to know if a player is admin.
- "!swap": swapFun,
- "!rr": resetFun,
- "!clear": clearFun,
- "!close": closeFun,
- // Command that need to know what's the message.
- "!stats": statsFun,
- // Command that need to know who is the player and what's the message.
- "!mute" : pushMuteFun,
- "!unmute": unmuteFun
- }
- initPlayerStats(room.getPlayerList()[0]) // lazy lol, i'll fix it later
- initPlayerStats(init);
- room.onPlayerLeave = function(player) {
- updateAdmins();
- }
- room.onPlayerJoin = function(player) {
- updateAdmins(); // Gives admin to the first player who join the room if there's no one
- initPlayerStats(player); // Set new player's stat
- room.sendChat("Witaj " + player.name + " ! Komendy: !help, !adminhelp, !rankhelp o !gkhelp" )
- }
- var redTeam;
- var blueTeam;
- room.onGameStart = function() {
- [redTeam,blueTeam] = whichTeam();
- ballCarrying = initBallCarrying(redTeam, blueTeam);
- }
- room.onPlayerTeamChange = function(player){
- if (room.getScores() != null){
- if (1 <= player.team <= 2) ballCarrying.set(player.name, [0, player.team]);
- }
- }
- room.onPlayerChat = function(player, message) {
- if (mutedPlayers.includes(player.name)) return false;
- let spacePos = message.search(" ");
- let command = message.substr(0, spacePos !== -1 ? spacePos : message.length);
- if (commands.hasOwnProperty(command) == true) return commands[command](player, message);
- }
- room.onPlayerBallKick = function (player){
- whoTouchedLast = player;
- }
- var kickOff = false;
- var hasFinished = false;
- room.onGameTick = function() {
- setInterval(isOvertime, 5000, hasFinished);
- if (kickOff == false) { // simplest comparison to not charge usulessly the tick thing
- if (room.getScores().time != 0){
- kickOff = true;
- gk = isGk();
- room.sendChat("GK RED: " + gk[0].name + ", GK BLUE: " + gk[1].name)
- }
- }
- if (goalScored == false){
- whoTouchedLast = getLastTouchTheBall(whoTouchedLast);
- }
- if (whoTouchedLast != undefined) {
- if (ballCarrying.get(whoTouchedLast.name)) {
- ballCarrying.get(whoTouchedLast.name)[0] += 1/60;
- }
- if ( whoTouchedLast.id != whoTouchedBall[0].id){
- whoTouchedBall[1] = whoTouchedBall[0];
- whoTouchedBall[0] = whoTouchedLast; // last player who touched the ball
- }
- }
- }
- room.onTeamGoal = function(team){ // Write on chat who scored and when.
- goalScored = true;
- var time = room.getScores().time;
- var m = Math.trunc(time/60); var s = Math.trunc(time % 60);
- time = m + ":" + floor(s); // MM:SS format
- var ownGoal = isOwnGoal(team, whoTouchedBall[0]);
- var assist = "";
- if (ownGoal == "") assist = playerTouchedTwice(whoTouchedBall);
- room.sendChat("GOL! Strzelcem " + whoTouchedBall[0].name +
- assist + ownGoal + " w " +
- time + " do bramki " + team_name(team));
- if (ownGoal != "") {
- stats.get(whoTouchedBall[0].name)[4] += 1;
- } else {
- stats.get(whoTouchedBall[0].name)[0] += 1;
- }
- if (whoTouchedBall[1] != init && assist != "") stats.get(whoTouchedBall[1].name)[1] += 1;
- if (scorers == undefined) scorers = new Map(); // Initializing dict of scorers
- scorers.set(scorers.size + 1 +") " + whoTouchedLast.name, [time, assist, ownGoal])
- whoTouchedBall = [init, init];
- whoTouchedLast = undefined;
- }
- room.onPositionsReset = function(){
- goalScored = false;
- }
- room.onTeamVictory = function(scores){ // Sum up all scorers since the beginning of the match.
- if (scores.blue == 0 && gk[0].position != null && hasFinished == false) stats.get(gk[0].name)[5] += 1;
- if (scores.red == 0 && gk[1].position != null && hasFinished == false) stats.get(gk[1].name)[5] += 1;
- if (scores.red > scores.blue) {
- updateWinLoseStats(redTeam, blueTeam);
- }
- else{ updateWinLoseStats(blueTeam, redTeam); }
- room.sendChat("Gole:")
- for (var [key, value] of scorers) { // key: name of the player, value: time of the goal
- room.sendChat(key + " " + value[1] + value[2] + ": " + value[0]);
- }
- teamPossFun();
- }
- room.onGameStop = function(){
- scorers = undefined;
- whoTouchedBall = [init, init];
- whoTouchedLast = undefined;
- gk = [init, init];
- kickOff = false;
- hasFinished = false;
- }
- room.onStadiumChange = function(newStadiumName, byPlayer) {
- if (newStadiumName != "Futsal 4x4") {
- room.setCustomStadium(futsal);
- }
- }
- // Made by Grandes Ligas HaxBall
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement