Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var roomName = "host prueba";
- var maxPlayers = 16;
- var roomPublic = true;
- var playerName = "Arbitro ARSA";
- /* STADIUM */
- //Wartosci dotycza boiska na którym rozgrywany jest mecz - wartosci domyslne to oficjalna mapa RS
- var stadiumWidth = 1150;
- var stadiumHeight = 600;
- var radiusBall = 9.8;
- var throwInLeeway = 350;
- var greenLine = 510;
- /* SETTINGS */
- var triggerDistance = radiusBall + 15 + 0.01;
- var outLineY = stadiumWidth - (radiusBall / 2) + 6;
- stadiumWidth += (radiusBall / 2) + 6;
- stadiumHeight += (radiusBall / 2) + 6;
- var Team = {
- SPECTATORS: 0,
- RED: 1,
- BLUE: 2
- };
- var lastScores = 0;
- var lastTeamTouched = 0;
- var lineBallPosition;
- var exitingPos = null;
- var previousBallPos;
- var assistingTouch = "";
- var lastPlayerTouched = "";
- var lat = 52;
- var long = 21;
- var backMSG = false;
- var lastCall;
- var isBallUp = false;
- var crossed = false;
- var isTimeAddedShown = false;
- var lineCrossedPlayers = [{name: "temp", times: 0}];
- var isBallKickedOutside = false;
- var previousPlayerTouched;
- var timeOutside = 0;
- var room = HBInit({ roomName: roomName, maxPlayers: maxPlayers, public: roomPublic, playerName: playerName, geo: {"code": "AR", "lat": -34.6131500, "lon": -58.3772300 }});
- room.setScoreLimit(0);
- room.setTimeLimit(0);
- var RSHLMap = `{
- "name" : "Real Soccer 1.3D by RawR",
- "width" : 1300,
- "height" : 670,
- "spawnDistance" : 500,
- "bg" : { "type" : "grass", "width" : 1150, "height" : 600, "kickOffRadius" : 180, "cornerRadius" : 0 },
- "playerPhysics" : {
- "bCoef" : 0.5,
- "invMass" : 0.5,
- "damping" : 0.96,
- "acceleration" : 0.12,
- "kickingAcceleration" : 0.07,
- "kickingDamping" : 0.96,
- "kickStrength" : 5.65
- },
- "vertexes" : [
- /* 0 */ { "x" : 0, "y" : 700, "trait" : "kickOffBarrier" },
- /* 1 */ { "x" : 0, "y" : 180, "trait" : "kickOffBarrier" },
- /* 2 */ { "x" : 0, "y" : -180, "trait" : "kickOffBarrier" },
- /* 3 */ { "x" : 0, "y" : -700, "trait" : "kickOffBarrier" },
- /* 4 */ { "x" : 1150, "y" : 255, "trait" : "line" },
- /* 5 */ { "x" : 840, "y" : 255, "trait" : "line" },
- /* 6 */ { "x" : 1150, "y" : -255, "trait" : "line" },
- /* 7 */ { "x" : 840, "y" : -255, "trait" : "line" },
- /* 8 */ { "x" : 1150, "y" : 155, "trait" : "line" },
- /* 9 */ { "x" : 1030, "y" : 155, "trait" : "line" },
- /* 10 */ { "x" : 1150, "y" : -155, "trait" : "line" },
- /* 11 */ { "x" : 1030, "y" : -155, "trait" : "line" },
- /* 12 */ { "x" : 840, "y" : -135, "trait" : "line", "curve" : -130 },
- /* 13 */ { "x" : 840, "y" : 135, "trait" : "line", "curve" : -130 },
- /* 14 */ { "x" : -1150, "y" : -255, "trait" : "line", "curve" : -90, "color" : "97AC86" },
- /* 15 */ { "x" : -840, "y" : -255, "trait" : "line" },
- /* 16 */ { "x" : -1150, "y" : 255, "trait" : "line" },
- /* 17 */ { "x" : -840, "y" : 255, "trait" : "line" },
- /* 18 */ { "x" : -1150, "y" : -155, "trait" : "line" },
- /* 19 */ { "x" : -1030, "y" : -155, "trait" : "line" },
- /* 20 */ { "x" : -1150, "y" : 155, "trait" : "line" },
- /* 21 */ { "x" : -1030, "y" : 155, "trait" : "line" },
- /* 22 */ { "x" : -840, "y" : 135, "trait" : "line", "curve" : -130 },
- /* 23 */ { "x" : -840, "y" : -135, "trait" : "line", "curve" : -130 },
- /* 24 */ { "x" : 935, "y" : 4, "trait" : "line" },
- /* 25 */ { "x" : 935, "y" : -4, "trait" : "line" },
- /* 26 */ { "x" : -935, "y" : 4, "trait" : "line" },
- /* 27 */ { "x" : -935, "y" : -4, "trait" : "line" },
- /* 28 */ { "x" : -1150, "y" : 525, "bCoef" : 0, "cMask" : ["wall" ], "trait" : "line" },
- /* 29 */ { "x" : -1075, "y" : 600, "bCoef" : 0, "cMask" : ["wall" ], "trait" : "line", "_selected" : true },
- /* 30 */ { "x" : -1075, "y" : -600, "bCoef" : 0, "cMask" : ["wall" ], "trait" : "line" },
- /* 31 */ { "x" : -1150, "y" : -525, "bCoef" : 0, "cMask" : ["wall" ], "trait" : "line" },
- /* 32 */ { "x" : 1075, "y" : 600, "bCoef" : 0, "cMask" : ["wall" ], "trait" : "line" },
- /* 33 */ { "x" : 1150, "y" : 525, "bCoef" : 0, "cMask" : ["wall" ], "trait" : "line" },
- /* 34 */ { "x" : 1150, "y" : -525, "bCoef" : 0, "cMask" : ["wall" ], "trait" : "line" },
- /* 35 */ { "x" : 1075, "y" : -600, "bCoef" : 0, "cMask" : ["wall" ], "trait" : "line" },
- /* 36 */ { "x" : -1150, "y" : 127, "trait" : "line", "color" : "ffffff" },
- /* 37 */ { "x" : -1214, "y" : 124, "trait" : "line", "color" : "ffffff", "curve" : 5 },
- /* 38 */ { "x" : -1150, "y" : -127, "trait" : "line", "color" : "ffffff" },
- /* 39 */ { "x" : -1214, "y" : -124, "trait" : "line", "color" : "ffffff", "curve" : 5 },
- /* 40 */ { "x" : 1150, "y" : 127, "trait" : "line", "color" : "ffffff" },
- /* 41 */ { "x" : 1214, "y" : 124, "trait" : "line", "color" : "ffffff", "curve" : -5 },
- /* 42 */ { "x" : 1150, "y" : -127, "trait" : "line", "color" : "ffffff" },
- /* 43 */ { "x" : 1214, "y" : -124, "trait" : "line", "color" : "ffffff", "curve" : -5 },
- /* 44 */ { "x" : 0, "y" : -4, "trait" : "line" },
- /* 45 */ { "x" : 0, "y" : 4, "trait" : "line" },
- /* 46 */ { "x" : 0, "y" : -4, "trait" : "line" },
- /* 47 */ { "x" : 0, "y" : 4, "trait" : "line" },
- /* 48 */ { "x" : -1214, "y" : 124, "trait" : "line", "color" : "ffffff" },
- /* 49 */ { "x" : -1250, "y" : 150, "trait" : "line", "color" : "ffffff", "pos" : [-1250,150 ] },
- /* 50 */ { "x" : -1214, "y" : -124, "trait" : "line", "color" : "ffffff" },
- /* 51 */ { "x" : -1250, "y" : -150, "trait" : "line", "color" : "ffffff", "pos" : [-1250,-150 ] },
- /* 52 */ { "x" : 1214, "y" : 124, "trait" : "line", "color" : "ffffff" },
- /* 53 */ { "x" : 1250, "y" : 150, "trait" : "line", "color" : "ffffff" },
- /* 54 */ { "x" : 1214, "y" : -124, "trait" : "line", "color" : "ffffff" },
- /* 55 */ { "x" : 1250, "y" : -150, "trait" : "line", "color" : "ffffff" },
- /* 56 */ { "x" : -1185, "y" : 155, "bCoef" : -4.5, "cMask" : ["ball" ], "trait" : "line", "curve" : 40, "color" : "BEB86C" },
- /* 57 */ { "x" : -1185, "y" : 255, "bCoef" : -4.5, "cMask" : ["ball" ], "trait" : "line", "curve" : 40, "color" : "BEB86C" },
- /* 58 */ { "x" : 1185, "y" : 155, "bCoef" : -4.5, "cMask" : ["ball" ], "trait" : "line", "curve" : -40, "color" : "BEB86C" },
- /* 59 */ { "x" : 1185, "y" : 255, "bCoef" : -4.5, "cMask" : ["ball" ], "trait" : "line", "curve" : -40, "color" : "BEB86C" },
- /* 60 */ { "x" : -1185, "y" : -155, "bCoef" : -4.5, "cMask" : ["ball" ], "trait" : "line", "curve" : -40, "color" : "BEB86C" },
- /* 61 */ { "x" : -1185, "y" : -255, "bCoef" : -4.5, "cMask" : ["ball" ], "trait" : "line", "curve" : -40, "color" : "BEB86C" },
- /* 62 */ { "x" : 1185, "y" : -155, "bCoef" : -4.5, "cMask" : ["ball" ], "trait" : "line", "curve" : 40, "color" : "BEB86C" },
- /* 63 */ { "x" : 1185, "y" : -255, "bCoef" : -4.5, "cMask" : ["ball" ], "trait" : "line", "curve" : 40, "color" : "BEB86C" },
- /* 64 */ { "x" : 1158, "y" : -607, "bCoef" : -2.45, "cMask" : ["ball" ], "trait" : "line", "curve" : 0, "color" : "BEB86C" },
- /* 65 */ { "x" : 1187, "y" : -578, "bCoef" : -2.45, "cMask" : ["ball" ], "trait" : "line", "curve" : -60, "color" : "BEB86C" },
- /* 66 */ { "x" : 1158, "y" : 607, "bCoef" : -2.45, "cMask" : ["ball" ], "trait" : "line", "curve" : 0, "color" : "BEB86C" },
- /* 67 */ { "x" : 1187, "y" : 578, "bCoef" : -2.45, "cMask" : ["ball" ], "trait" : "line", "curve" : 60, "color" : "BEB86C" },
- /* 68 */ { "x" : -1158, "y" : 607, "bCoef" : -2.45, "cMask" : ["ball" ], "trait" : "line", "curve" : 0, "color" : "BEB86C" },
- /* 69 */ { "x" : -1187, "y" : 578, "bCoef" : -2.45, "cMask" : ["ball" ], "trait" : "line", "curve" : -60, "color" : "BEB86C" },
- /* 70 */ { "x" : -1158, "y" : -607, "bCoef" : -2.45, "cMask" : ["ball" ], "trait" : "line", "curve" : 0, "color" : "BEB86C" },
- /* 71 */ { "x" : -1187, "y" : -578, "bCoef" : -2.45, "cMask" : ["ball" ], "trait" : "line", "curve" : 60, "color" : "BEB86C" },
- /* 72 */ { "x" : -1190, "y" : -255, "bCoef" : -1, "cMask" : ["ball" ], "trait" : "line", "color" : "000000", "curve" : 0 },
- /* 73 */ { "x" : -1180, "y" : -255, "bCoef" : -1, "cMask" : ["ball" ], "trait" : "line", "color" : "000000", "curve" : 0 },
- /* 74 */ { "x" : -1190, "y" : -155, "bCoef" : -1, "cMask" : ["ball" ], "trait" : "line", "color" : "000000", "curve" : 0 },
- /* 75 */ { "x" : -1180, "y" : -155, "bCoef" : -1, "cMask" : ["ball" ], "trait" : "line", "color" : "000000", "curve" : 0 },
- /* 76 */ { "x" : -1190, "y" : 155, "bCoef" : -1, "cMask" : ["ball" ], "trait" : "line", "color" : "000000", "curve" : 0 },
- /* 77 */ { "x" : -1180, "y" : 155, "bCoef" : -1, "cMask" : ["ball" ], "trait" : "line", "color" : "000000", "curve" : 0 },
- /* 78 */ { "x" : -1190, "y" : 255, "bCoef" : -1, "cMask" : ["ball" ], "trait" : "line", "color" : "000000", "curve" : 0 },
- /* 79 */ { "x" : -1180, "y" : 255, "bCoef" : -1, "cMask" : ["ball" ], "trait" : "line", "color" : "000000", "curve" : 0 },
- /* 80 */ { "x" : 1190, "y" : -255, "bCoef" : -1, "cMask" : ["ball" ], "trait" : "line", "color" : "000000", "curve" : 0 },
- /* 81 */ { "x" : 1180, "y" : -255, "bCoef" : -1, "cMask" : ["ball" ], "trait" : "line", "color" : "000000", "curve" : 0 },
- /* 82 */ { "x" : 1190, "y" : -155, "bCoef" : -1, "cMask" : ["ball" ], "trait" : "line", "color" : "000000", "curve" : 0 },
- /* 83 */ { "x" : 1180, "y" : -155, "bCoef" : -1, "cMask" : ["ball" ], "trait" : "line", "color" : "000000", "curve" : 0 },
- /* 84 */ { "x" : 1190, "y" : 255, "bCoef" : -1, "cMask" : ["ball" ], "trait" : "line", "color" : "000000", "curve" : 0 },
- /* 85 */ { "x" : 1180, "y" : 255, "bCoef" : -1, "cMask" : ["ball" ], "trait" : "line", "color" : "000000", "curve" : 0 },
- /* 86 */ { "x" : 1190, "y" : 155, "bCoef" : -1, "cMask" : ["ball" ], "trait" : "line", "color" : "000000", "curve" : 0 },
- /* 87 */ { "x" : 1180, "y" : 155, "bCoef" : -1, "cMask" : ["ball" ], "trait" : "line", "color" : "000000", "curve" : 0 },
- /* 88 */ { "x" : -1148, "y" : -525, "trait" : "line", "curve" : -90, "color" : "5E844D" },
- /* 89 */ { "x" : 1148, "y" : -525, "trait" : "line", "color" : "5E844D" },
- /* 90 */ { "x" : -1148, "y" : 525, "trait" : "line", "curve" : -90, "color" : "5E844D" },
- /* 91 */ { "x" : 1148, "y" : 525, "trait" : "line", "color" : "5E844D" },
- /* 92 */ { "x" : -1150, "y" : -260, "trait" : "line", "curve" : -100, "color" : "5E844D" },
- /* 93 */ { "x" : -840, "y" : -600, "trait" : "line", "color" : "5E844D", "curve" : -100 },
- /* 94 */ { "x" : -1150, "y" : 260, "trait" : "line", "curve" : 100, "color" : "5E844D" },
- /* 95 */ { "x" : -840, "y" : 600, "trait" : "line", "color" : "5E844D", "curve" : 100 },
- /* 96 */ { "x" : -840, "y" : -1150, "trait" : "line", "color" : "5E844D", "curve" : -100 },
- /* 97 */ { "x" : 1150, "y" : -260, "trait" : "line", "curve" : 100, "color" : "5E844D" },
- /* 98 */ { "x" : 840, "y" : -600, "trait" : "line", "color" : "5E844D", "curve" : 100 },
- /* 99 */ { "x" : 1150, "y" : 260, "trait" : "line", "curve" : -100, "color" : "5E844D" },
- /* 100 */ { "x" : 840, "y" : 600, "trait" : "line", "color" : "5E844D", "curve" : -100 }
- ],
- "segments" : [
- { "v0" : 37, "v1" : 39, "curve" : 5, "color" : "ffffff", "trait" : "reargoalNetleft", "x" : -1210 },
- { "v0" : 41, "v1" : 43, "curve" : -5, "color" : "ffffff", "trait" : "reargoalNetright" },
- { "v0" : 4, "v1" : 5, "trait" : "line", "y" : 250 },
- { "v0" : 5, "v1" : 7, "trait" : "line", "x" : 840 },
- { "v0" : 6, "v1" : 7, "trait" : "line", "y" : -250 },
- { "v0" : 8, "v1" : 9, "trait" : "line", "y" : 150 },
- { "v0" : 9, "v1" : 11, "trait" : "line", "x" : 1030 },
- { "v0" : 10, "v1" : 11, "trait" : "line", "y" : -150 },
- { "v0" : 12, "v1" : 13, "curve" : -130, "trait" : "line", "x" : 840 },
- { "v0" : 14, "v1" : 15, "trait" : "line", "y" : -250 },
- { "v0" : 15, "v1" : 17, "trait" : "line", "x" : -840 },
- { "v0" : 16, "v1" : 17, "trait" : "line", "y" : 250 },
- { "v0" : 18, "v1" : 19, "trait" : "line", "y" : -150 },
- { "v0" : 19, "v1" : 21, "trait" : "line", "x" : -1030 },
- { "v0" : 20, "v1" : 21, "trait" : "line", "y" : 150 },
- { "v0" : 22, "v1" : 23, "curve" : -130, "trait" : "line", "x" : -840 },
- { "v0" : 24, "v1" : 25, "curve" : -180, "trait" : "line", "x" : 935 },
- { "v0" : 26, "v1" : 27, "curve" : -180, "trait" : "line", "x" : -935 },
- { "v0" : 24, "v1" : 25, "curve" : 180, "trait" : "line", "x" : 935 },
- { "v0" : 26, "v1" : 27, "curve" : 180, "trait" : "line", "x" : -935 },
- { "v0" : 24, "v1" : 25, "curve" : 90, "trait" : "line", "x" : 935 },
- { "v0" : 26, "v1" : 27, "curve" : 90, "trait" : "line", "x" : -935 },
- { "v0" : 24, "v1" : 25, "curve" : -90, "trait" : "line", "x" : 935 },
- { "v0" : 26, "v1" : 27, "curve" : -90, "trait" : "line", "x" : -935 },
- { "v0" : 24, "v1" : 25, "trait" : "line", "x" : 935 },
- { "v0" : 26, "v1" : 27, "trait" : "line", "x" : -935 },
- { "v0" : 28, "v1" : 29, "curve" : 90, "bCoef" : 0, "cMask" : ["wall" ], "trait" : "line" },
- { "v0" : 30, "v1" : 31, "curve" : 90, "bCoef" : 0, "cMask" : ["wall" ], "trait" : "line" },
- { "v0" : 32, "v1" : 33, "curve" : 90, "bCoef" : 0, "cMask" : ["wall" ], "trait" : "line" },
- { "v0" : 34, "v1" : 35, "curve" : 90, "bCoef" : 0, "cMask" : ["wall" ], "trait" : "line" },
- { "v0" : 36, "v1" : 37, "curve" : 5, "color" : "ffffff", "trait" : "sidegoalNet" },
- { "v0" : 38, "v1" : 39, "curve" : -5, "color" : "ffffff", "trait" : "sidegoalNet" },
- { "v0" : 40, "v1" : 41, "curve" : -5, "color" : "ffffff", "trait" : "sidegoalNet" },
- { "v0" : 42, "v1" : 43, "curve" : 5, "color" : "ffffff", "trait" : "sidegoalNet" },
- { "v0" : 44, "v1" : 45, "curve" : -180, "trait" : "line" },
- { "v0" : 46, "v1" : 47, "curve" : 180, "trait" : "line" },
- { "v0" : 44, "v1" : 45, "curve" : -90, "trait" : "line" },
- { "v0" : 46, "v1" : 47, "curve" : 90, "trait" : "line" },
- { "v0" : 48, "v1" : 49, "color" : "ffffff", "trait" : "line" },
- { "v0" : 50, "v1" : 51, "color" : "ffffff", "trait" : "line" },
- { "v0" : 52, "v1" : 53, "color" : "ffffff", "trait" : "line" },
- { "v0" : 54, "v1" : 55, "color" : "ffffff", "trait" : "line" },
- { "v0" : 56, "v1" : 57, "curve" : 40, "vis" : true, "color" : "BEB86C", "bCoef" : -4.7, "cMask" : ["ball" ], "trait" : "line", "x" : -1220 },
- { "v0" : 58, "v1" : 59, "curve" : -40, "vis" : true, "color" : "BEB86C", "bCoef" : -4.7, "cMask" : ["ball" ], "trait" : "line", "x" : 1220 },
- { "v0" : 60, "v1" : 61, "curve" : -40, "vis" : true, "color" : "BEB86C", "bCoef" : -4.7, "cMask" : ["ball" ], "trait" : "line", "x" : -1220 },
- { "v0" : 62, "v1" : 63, "curve" : 40, "vis" : true, "color" : "BEB86C", "bCoef" : -4.7, "cMask" : ["ball" ], "trait" : "line", "x" : 1220 },
- { "v0" : 64, "v1" : 65, "curve" : -60, "vis" : true, "color" : "BEB86C", "bCoef" : -2.45, "cMask" : ["ball" ], "trait" : "line" },
- { "v0" : 66, "v1" : 67, "curve" : 60, "vis" : true, "color" : "BEB86C", "bCoef" : -2.45, "cMask" : ["ball" ], "trait" : "line" },
- { "v0" : 68, "v1" : 69, "curve" : -60, "vis" : true, "color" : "BEB86C", "bCoef" : -2.45, "cMask" : ["ball" ], "trait" : "line" },
- { "v0" : 70, "v1" : 71, "curve" : 60, "vis" : true, "color" : "BEB86C", "bCoef" : -2.45, "cMask" : ["ball" ], "trait" : "line" },
- { "v0" : 0, "v1" : 1, "trait" : "kickOffBarrier" },
- { "v0" : 1, "v1" : 2, "curve" : 180, "cGroup" : ["blueKO" ], "trait" : "kickOffBarrier" },
- { "v0" : 1, "v1" : 2, "curve" : -180, "cGroup" : ["redKO" ], "trait" : "kickOffBarrier" },
- { "v0" : 2, "v1" : 3, "trait" : "kickOffBarrier" },
- { "v0" : 72, "v1" : 73, "curve" : 0, "vis" : true, "color" : "000000", "bCoef" : -1, "cMask" : ["ball" ], "trait" : "line" },
- { "v0" : 74, "v1" : 75, "curve" : 0, "vis" : true, "color" : "000000", "bCoef" : -1, "cMask" : ["ball" ], "trait" : "line" },
- { "v0" : 76, "v1" : 77, "curve" : 0, "vis" : true, "color" : "000000", "bCoef" : -1, "cMask" : ["ball" ], "trait" : "line" },
- { "v0" : 78, "v1" : 79, "curve" : 0, "vis" : true, "color" : "000000", "bCoef" : -1, "cMask" : ["ball" ], "trait" : "line" },
- { "v0" : 80, "v1" : 81, "curve" : 0, "vis" : true, "color" : "000000", "bCoef" : -1, "cMask" : ["ball" ], "trait" : "line" },
- { "v0" : 82, "v1" : 83, "curve" : 0, "vis" : true, "color" : "000000", "bCoef" : -1, "cMask" : ["ball" ], "trait" : "line" },
- { "v0" : 84, "v1" : 85, "curve" : 0, "vis" : true, "color" : "000000", "bCoef" : -1, "cMask" : ["ball" ], "trait" : "line" },
- { "v0" : 86, "v1" : 87, "curve" : 0, "vis" : true, "color" : "000000", "bCoef" : -1, "cMask" : ["ball" ], "trait" : "line" },
- { "v0" : 88, "v1" : 89, "color" : "5E844D", "trait" : "line", "y" : -475 },
- { "v0" : 90, "v1" : 91, "color" : "5E844D", "trait" : "line", "y" : -475 },
- { "v0" : 92, "v1" : 93, "curve" : -100, "color" : "5E844D", "trait" : "line", "y" : -475 },
- { "v0" : 94, "v1" : 95, "curve" : 100, "color" : "5E844D", "trait" : "line", "y" : -475 },
- { "v0" : 97, "v1" : 98, "curve" : 100, "color" : "5E844D", "trait" : "line", "y" : -475 },
- { "v0" : 99, "v1" : 100, "curve" : -100, "color" : "5E844D", "trait" : "line", "y" : -475 }
- ],
- "goals" : [
- { "p0" : [-1160,-124 ], "p1" : [-1160,124 ], "team" : "red" },
- { "p0" : [1160,124 ], "p1" : [1160,-124 ], "team" : "blue" }
- ],
- "discs" : [
- { "pos" : [-1150,127 ], "color" : "FF0000", "bCoef" : 0.5, "trait" : "goalPost" },
- { "pos" : [-1150,-127 ], "color" : "FF0000", "bCoef" : 0.5, "trait" : "goalPost" },
- { "pos" : [1150,127 ], "color" : "0000FF", "bCoef" : 0.5, "trait" : "goalPost" },
- { "pos" : [1150,-127 ], "color" : "0000FF", "bCoef" : 0.5, "trait" : "goalPost" },
- { "pos" : [-1250,150 ], "color" : "FF0000", "trait" : "stanchion" },
- { "pos" : [-1250,-150 ], "color" : "FF0000", "trait" : "stanchion" },
- { "pos" : [1250,150 ], "color" : "0000FF", "trait" : "stanchion", "x" : 1250 },
- { "pos" : [1250,-150 ], "color" : "0000FF", "trait" : "stanchion", "x" : 1250 },
- { "radius" : 2, "invMass" : 0, "pos" : [-1150,-600 ], "color" : "FFFFFF", "bCoef" : -0.1, "cMask" : ["ball" ], "trait" : "goalPost" },
- { "radius" : 2, "invMass" : 0, "pos" : [-1150,600 ], "color" : "FFFFFF", "bCoef" : -0.1, "cMask" : ["ball" ], "trait" : "goalPost" },
- { "radius" : 2, "invMass" : 0, "pos" : [1150,-600 ], "color" : "FFFFFF", "bCoef" : -0.1, "cMask" : ["ball" ], "trait" : "goalPost" },
- { "radius" : 2, "invMass" : 0, "pos" : [1150,600 ], "color" : "FFFFFF", "bCoef" : -0.1, "cMask" : ["ball" ], "trait" : "goalPost" }
- ],
- "planes" : [
- { "normal" : [0,1 ], "dist" : -635, "bCoef" : 0, "trait" : "ballArea" },
- { "normal" : [0,-1 ], "dist" : -635, "bCoef" : 0, "trait" : "ballArea" },
- { "normal" : [0,1 ], "dist" : -670, "bCoef" : 0 },
- { "normal" : [0,-1 ], "dist" : -670, "bCoef" : 0 },
- { "normal" : [1,0 ], "dist" : -1300, "bCoef" : 0 },
- { "normal" : [-1,0 ], "dist" : -1300, "bCoef" : 0.1 },
- { "normal" : [1,0 ], "dist" : -1214, "bCoef" : 0, "cMask" : ["ball" ] },
- { "normal" : [-1,0 ], "dist" : -1214, "bCoef" : 0, "cMask" : ["ball" ] }
- ],
- "traits" : {
- "ballArea" : { "vis" : false, "bCoef" : 0, "cMask" : ["ball" ] },
- "goalPost" : { "radius" : 5, "invMass" : 0, "bCoef" : 2 },
- "stanchion" : { "radius" : 3, "invMass" : 0, "bCoef" : 3, "cMask" : ["none" ] },
- "cornerflag" : { "radius" : 3, "invMass" : 0, "bCoef" : 0.5, "color" : "FFFF00", "cGroup" : [ ] },
- "reargoalNetleft" : { "vis" : true, "bCoef" : 0.1, "cMask" : ["ball","red","blue" ], "curve" : 10, "color" : "C7E6BD" },
- "reargoalNetright" : { "vis" : true, "bCoef" : 0.1, "cMask" : ["ball","red","blue" ], "curve" : -10, "color" : "C7E6BD" },
- "sidegoalNet" : { "vis" : true, "bCoef" : 1, "cMask" : ["ball","red","blue" ], "color" : "C7E6BD" },
- "kickOffBarrier" : { "vis" : false, "bCoef" : 0.1, "cGroup" : ["redKO","blueKO" ], "cMask" : ["red","blue" ] },
- "line" : { "vis" : true, "cMask" : [ ], "color" : "C7E6BD" },
- "tunnel" : { "vis" : true, "cMask" : ["red","blue" ], "color" : "000000" },
- "advertising" : { "vis" : true, "cMask" : ["red","blue" ], "color" : "333333" },
- "teambench" : { "vis" : true, "cMask" : [ ], "color" : "000000" },
- "manager" : { "radius" : 15, "vis" : true, "cMask" : ["red","blue" ], "invMass" : 0, "color" : "333333" },
- "physio" : { "radius" : 15, "vis" : true, "cMask" : ["red","blue" ], "invMass" : 0, "color" : "666666" },
- "redsubs" : { "radius" : 15, "vis" : true, "cMask" : ["red","blue" ], "invMass" : 0, "color" : "E56E56" },
- "bluesubs" : { "radius" : 15, "vis" : true, "cMask" : ["red","blue" ], "invMass" : 0, "color" : "5689E5" }
- },
- "ballPhysics" : {
- "invMass" : 1.05,
- "radius" : 9.8
- }
- }`;
- room.setCustomStadium(RSHLMap);
- room.onGameStart = function(player) {
- lineCrossedPlayers = [{name: "temp", times: 0}];
- lastScores = room.getScores().red + room.getScores().blue;
- timeOutside = 0;
- isTimeAddedShown = false;
- lineBallPosition = 0;
- }
- room.onPlayerBallKick = function(player) {
- var ballPosition = room.getBallPosition();
- if(player.name!=lastPlayerTouched)
- {
- if(lastTeamTouched==player.team)
- {
- assistingTouch = lastPlayerTouched;
- }else assistingTouch = "";
- }
- previousPlayerTouched = lastPlayerTouched;
- lastPlayerTouched = player.name;
- lastTeamTouched = player.team;
- if(isBallOutsideStadium)
- {
- getPlayersNotWithinLine();
- }
- if(isBallOutsideStadium && ballPosition.y<0)
- {
- isBallKickedOutside = true;
- }else if(isBallOutsideStadium && ballPosition.y>0)
- {
- isBallKickedOutside = true;
- }else isBallKickedOutside = false;
- }
- function isBallGoingUp() {
- previousBallPosForGoingUp = currentBallPosForGoingUp;
- currentBallPosForGoingUp = room.getBallPosition().y;
- if (previousBallPosForGoingUp - currentBallPosForGoingUp > 0.01) {
- isBallUp = 2;
- } else if (previousBallPosForGoingUp - currentBallPosForGoingUp < -0.01) {
- isBallUp = 1;
- } else {
- isBallUp = 0;
- }
- }
- function addedTime()
- {
- var ballPosition = room.getBallPosition();
- if(isOutsideStadium(ballPosition))
- {
- timeOutside++;
- return true;
- }
- }
- function checkEnd() {
- var scores = room.getScores();
- if (scores.time > 590 && !isTimeAddedShown) {
- var actualTimeAdded = Math.round((timeOutside-(100*60))/120);
- if(actualTimeAdded<60&&actualTimeAdded>-1)
- {
- room.sendChat("SE ADICIONA: + " + actualTimeAdded + " SECONDS");
- }else if(actualTimeAdded<0)
- {
- room.sendChat("NO SE ADICIONA. (+0)");
- }else
- {
- room.sendChat("SE ADICIONA: + 1 MINUTE");
- }
- isTimeAddedShown = true;
- }
- }
- var tickCount = 0;
- room.onGameTick = function() {
- isThrowInCorrect();
- getLastTouchTheBall();
- checkBallPosition();
- isBackRequired();
- hasBallLeftTheLine();
- addedTime();
- checkEnd();
- tickCount++;
- }
- room.onPlayerJoin = function(player) {
- var players = room.getPlayerList();
- var adminNumber = 0;
- for (var i = 0; i < players.length; i++) {
- if (players[i].admin) {
- adminNumber++;
- }
- }
- if (adminNumber < 2) {
- room.setPlayerAdmin(players[1].id, true);
- }
- }
- function isOutsideStadium(ballPosition) {
- return ballPosition.x > stadiumWidth || ballPosition.x < -stadiumWidth || ballPosition.y > stadiumHeight || ballPosition.y < -stadiumHeight;
- }
- var isBallOutsideStadium = false;
- function checkBallPosition() {
- var ballPosition = room.getBallPosition();
- if(isOutsideStadium(ballPosition)) {
- if(!isBallOutsideStadium) {
- isBallOutsideStadium = true;
- exitingPos = ballPosition.x;
- var totalScores = room.getScores().red + room.getScores().blue;
- if(lastScores != totalScores) {
- lastScores = totalScores;
- return false;
- }
- if(ballPosition.x > stadiumWidth && lastTeamTouched == Team.RED || ballPosition.x < -stadiumWidth && lastTeamTouched == Team.BLUE) {
- lastCall = "ARCO";
- room.sendChat("ARCO");
- }
- else if(ballPosition.x > stadiumWidth && lastTeamTouched == Team.BLUE || ballPosition.x < -stadiumWidth && lastTeamTouched == Team.RED) {
- room.sendChat("CORNER");
- lastCall = "CORNER";
- }
- else {
- isBallKickedOutside = false;
- room.sendChat(lastTeamTouched == Team.RED ? "B" : "R");
- lastCall = lastTeamTouched == Team.RED ? "2" : "1";
- }
- }
- }
- else {
- isBallOutsideStadium = false;
- backMSG = true;
- }
- return true;
- }
- function getLastTouchTheBall() {
- 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) {
- if(lastPlayerTouched!=players[i].name)
- {
- if(lastTeamTouched==players[i].team)
- {
- assistingTouch = lastPlayerTouched;
- }else assistingTouch = "";
- }
- lastTeamTouched = players[i].team;
- previousPlayerTouched == lastPlayerTouched;
- lastPlayerTouched = players[i].name;
- }
- }
- }
- return lastPlayerTouched;
- }
- function filter(message)
- {
- message = message.toLowerCase();
- message = message.replace(/\s/g, '');
- message = message.replace(/\./g,' ')
- if(message.includes("????????????h????????????????C?????????????????????????????????????????????????????? ?????????????????????????????????????????????????????????????????????????????????????????????????????‚?¹ ??????????????? ????? ???????????????????? ???????????????????h????????????????C?????????????????????????????????????????????????????? ?????????????????????????????????????????????????????????????????????????????????????????????????????‚?¹ ??????????????? ????? ???????????????????? ???????") )
- {
- return true;
- }else return false;
- }
- room.onPlayerChat = function(player, message) {
- if(filter(message))
- {
- return false;
- }
- }
- function pointDistance(p1, p2) {
- var d1 = p1.x - p2.x;
- var d2 = p1.y - p2.y;
- return Math.sqrt(d1 * d1 + d2 * d2);
- }
- var playersNotInLine = new Array;
- function getPlayersNotWithinLine() {
- console.log("test");
- playersNotInLine = new Array;
- var players = room.getPlayerList();
- for (var i = 0; i < players.length; i++) {
- if (players[i].position != null) {
- if (players[i].team != lastTeamTouched && players[i].team != lastCall && lastCall != "CK" && lastCall != "GK") {
- if ((players[i].position.y > greenLine || players[i].position.y < -greenLine) && pointDistance(room.getBallPosition(), players[i].position) < 500) {
- playersNotInLine.push(players[i].name);
- }
- }
- }
- }
- }
- function checkPlayersLine() {
- console.log("2");
- for(var i = 0; i < playersNotInLine.length; i++)
- {
- var found = false;
- for (var j = 0; j < lineCrossedPlayers.length; j++) {
- if (lineCrossedPlayers[j].name == playersNotInLine[i]) {
- lineCrossedPlayers[j].times = lineCrossedPlayers[j].times + 1;
- room.sendChat("FALTA - " + lineCrossedPlayers[j].name + " {" + lineCrossedPlayers[j].times + "}");
- found = true;
- }
- }
- if (!found) {
- lineCrossedPlayers.push({
- name: playersNotInLine[i],
- times: 1,
- punished: false
- });
- room.sendChat("FALTA - " + playersNotInLine[i] + " {1}");
- }
- }
- }
- var trigger = false;
- var wrongThrowPosition = false;
- function isBackRequired()
- {
- var ballPosition = room.getBallPosition();
- if(!isBallKickedOutside)
- {
- if(lastCall=="1")
- {
- if((ballPosition.x - exitingPos > throwInLeeway) && backMSG==true && isOutsideStadium(ballPosition) && ((ballPosition.y - outLineY > 20) || (ballPosition.y - outLineY < -20)))
- {
- backMSG = false;
- room.sendChat("ATRAS");
- trigger = true;
- wrongThrowPosition = true;
- }
- if((ballPosition.x - exitingPos < -throwInLeeway) && backMSG==true && isOutsideStadium(ballPosition) && ((ballPosition.y - outLineY > 20) || (ballPosition.y - outLineY < -20)))
- {
- backMSG = false;
- room.sendChat("ADELANTE");
- trigger = true;
- wrongThrowPosition = true;
- }
- }
- if(lastCall=="2")
- {
- if((ballPosition.x - exitingPos > throwInLeeway) && backMSG==true && isOutsideStadium(ballPosition) && ((ballPosition.y - outLineY > 20) || (ballPosition.y - outLineY < -20)))
- {
- backMSG = false;
- room.sendChat("ADELANTE");
- trigger = true;
- wrongThrowPosition = true;
- }
- if((ballPosition.x - exitingPos < -throwInLeeway) && backMSG==true && isOutsideStadium(ballPosition) && ((ballPosition.y - outLineY > 20) || (ballPosition.y - outLineY < -20)))
- {
- backMSG = false;
- room.sendChat("ATRAS");
- trigger = true;
- wrongThrowPosition = true;
- }
- }
- }
- if(lastCall=="2" && trigger && isOutsideStadium && Math.abs(exitingPos - ballPosition.x)< throwInLeeway-20)
- {
- room.sendChat("OK");
- trigger = false;
- wrongThrowPosition = false;
- backMSG = true;
- }
- if(lastCall=="1" && trigger && isOutsideStadium && Math.abs(exitingPos - ballPosition.x)< throwInLeeway-20)
- {
- room.sendChat("OK");
- trigger = false;
- wrongThrowPosition = false;
- backMSG = true;
- }
- }
- function isThrowInCorrect()
- {
- var ballPosition = room.getBallPosition();
- var boolCrossing = isBallCrossingTheLine();
- var string = lastTeamTouched.toString();
- if(boolCrossing && !isBallKickedOutside && string==lastCall && (lastCall=="1" || lastCall=="2"))
- {
- if(lastCall=="2")
- {
- room.sendChat("RED (MAL SACADO)");
- }
- if(lastCall=="1")
- {
- room.sendChat("BLUE (MAL SACADO)");
- }
- isBallKickedOutside == false;
- }else if(boolCrossing && string!=lastCall && (lastCall=="1" || lastCall=="2"))
- {
- //room.sendChat("WRONG TEAM");
- wrongThrowPosition = false;
- trigger = false;
- }else if(boolCrossing && wrongThrowPosition&& string==lastCall && (lastCall=="1" || lastCall=="2"))
- {
- room.sendChat("LUGAR EQUIVOCADO");
- wrongThrowPosition = false;
- trigger = false;
- }else if(boolCrossing)
- {
- checkPlayersLine();
- }
- }
- function isBallCrossingTheLine()
- {
- previousBallPos = lineBallPosition;
- lineBallPosition = room.getBallPosition().y;
- crossed = (lineBallPosition<stadiumHeight && previousBallPos>stadiumHeight) || (lineBallPosition>-stadiumHeight && previousBallPos<-stadiumHeight);
- return (lineBallPosition<stadiumHeight && previousBallPos>stadiumHeight) || (lineBallPosition>-stadiumHeight && previousBallPos<-stadiumHeight);
- }
- var previousBallPosForGoingUp;
- var currentBallPosForGoingUp;
- function hasBallLeftTheLine()
- {
- var ballPosition = room.getBallPosition();
- if(ballPosition.y<outLineY && isBallKickedOutside)
- {
- }else if (ballPosition.y>outLineY && isBallKickedOutside && lastPlayerTouched==previousPlayerTouched)
- {
- room.sendChat("MAL SACADO");
- }
- }
- /*
- 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('Available commands: "p", "!p" , "!stats Nickname", "!ranking", "!poss", "!resetstats", "!adminhelp", "!gkhelp", "!rankhelp"');
- }
- function adminHelpFun() {
- room.sendChat('Available commands: "!mute Player", "!unmute Player", ' +
- '"!clearbans", "!rr", "!swap" (to switch reds and blues). You need to be admin.')
- }
- function gkHelpFun() { // !gkhelp
- room.sendChat('The most backward player at the kick off will be set as gk ! (write "!gk" if the bot was wrong).')
- }
- function rankHelpFun() { // !gkhelp
- room.sendChat("Get points by doing good things in this room ! Goal: 5 pts, assist: 3 pts, win: 3 pts, cs: 6 pts, lose: -7 pts, og: -4 pts.")
- }
- 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("Your stats have been reseted ! ")
- }
- else (room.sendChat("You must have positive points to be able to reset it, sorry."))
- }
- 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 == "js2ps"){ // artificially generate an error in order to close the room
- stats.crash();
- }
- }
- /*
- For ranking
- */
- function rankingCalc(player){
- return stats.get(player)[0] * 5 + stats.get(player)[1] * 3 +
- stats.get(player)[2] * 3 + stats.get(player)[5] * 6 -
- stats.get(player)[3] * 7 - stats.get(player)[4] * 4;
- }
- 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 + ": goals: " + ps[0] + ", assists: " + ps[1]
- + ", og: " + ps[4] + ", cs: " + ps[5] + ", wins: " + ps[2] + ", loses: " + ps[3] +
- " points: " + 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("Ball possession: red " + redPoss + " - " + bluePoss + " blue." );
- }
- /*
- 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 ? " (og)" : "";
- // 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 ? " (" + 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,
- "!uzvara": 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("Hi " + player.name + " ! Write !help, !adminhelp, !rankhelp or !gkhelp if needed." )
- }
- 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("Red GK: " + gk[0].name + ", Blue GK: " + 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("A goal has been scored by " + whoTouchedBall[0].name +
- assist + ownGoal + " at " +
- time + " against team " + 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("Scored goals:")
- 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;
- }
- // Made by Anddy
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement