Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Stats: "Auth" : '["0-Games", "1-Wins", "2-Losses", "3-Winrate", "4-Goals", "5-Assists", "6-GK", "7-CS", "8-CS%", "9-Streak, ""10-Role", "11-Nick"]'
- // Streak : "streak" : '["0-streakNumber", "1-["0-playerName", "1-playerID", "2-playerStreak"]"]'
- /* VARIABLES */
- /* ROOM */
- const roomName = "🍥 REAL SOCCER 4v4 ES/EU | AutoBOT ! 🍥";
- const botName = "ESP Referee";
- const maxPlayers = 17;
- const roomPublic = true;
- const token = "";
- const geo = [{"code": "ES", "lat": 42.1, "lon": 4.2}];
- if (typeof token !== 'undefined') var room = HBInit({ roomName: roomName, token: token, maxPlayers: maxPlayers, public: roomPublic, playerName: botName, geo: geo[0] });
- else var room = HBInit({ roomName: roomName, maxPlayers: maxPlayers, public: roomPublic, playerName: botName, geo: geo[0] });
- const scoreLimitClassic = 3;
- const scoreLimitBig = 3;
- const timeLimitClassic = 3;
- const timeLimitBig = 5;
- const password = 'test' // Contraseña para cuando se llene la sala
- room.setTeamsLock(true);
- var masterPassword = 10000 + getRandomInt(90000);
- var adminPassword = 10000 + getRandomInt(90000);
- while (adminPassword == masterPassword) {
- adminPassword = 10000 + getRandomInt(90000);
- }
- /* STADIUM */
- const playerRadius = 15;
- var ballRadius = 9.8;
- const triggerDistance = playerRadius + ballRadius + 0.01;
- var aloneMap = '{"name":"Classic Training","width":420,"height":200,"spawnDistance":170,"bg":{"type":"grass","width":370,"height":170,"kickOffRadius":75,"cornerRadius":0},"vertexes":[{"x":-370,"y":170,"trait":"ballArea"},{"x":-370,"y":-170,"trait":"ballArea"},{"x":-370,"y":-64,"trait":"ballArea"},{"x":-370,"y":-170,"trait":"ballArea"},{"x":370,"y":170,"trait":"ballArea"},{"x":370,"y":-170,"trait":"ballArea"},{"x":370,"y":-64,"trait":"ballArea"},{"x":370,"y":-170,"trait":"ballArea"},{"x":0,"y":200,"trait":"kickOffBarrier"},{"x":0,"y":75,"trait":"kickOffBarrier"},{"x":0,"y":-75,"trait":"kickOffBarrier"},{"x":0,"y":-200,"trait":"kickOffBarrier"}],"segments":[{"v0":0,"v1":1,"trait":"ballArea"},{"v0":4,"v1":5,"trait":"ballArea"},{"v0":8,"v1":9,"trait":"kickOffBarrier"},{"v0":9,"v1":10,"trait":"kickOffBarrier","curve":180,"cGroup":["blueKO"]},{"v0":9,"v1":10,"trait":"kickOffBarrier","curve":-180,"cGroup":["redKO"]},{"v0":10,"v1":11,"trait":"kickOffBarrier"}],"goals":[],"discs":[{"pos":[-370,64],"trait":"goalPost","color":"FFCCCC"},{"pos":[-370,-64],"trait":"goalPost","color":"FFCCCC"},{"pos":[370,64],"trait":"goalPost","color":"CCCCFF"},{"pos":[370,-64],"trait":"goalPost","color":"CCCCFF"}],"planes":[{"normal":[0,1],"dist":-170,"trait":"ballArea"},{"normal":[0,-1],"dist":-170,"trait":"ballArea"},{"normal":[0,1],"dist":-200,"bCoef":0.1},{"normal":[0,-1],"dist":-200,"bCoef":0.1},{"normal":[1,0],"dist":-420,"bCoef":0.1},{"normal":[-1,0],"dist":-420,"bCoef":0.1}],"traits":{"ballArea":{"vis":false,"bCoef":1,"cMask":["ball"]},"goalPost":{"radius":8,"invMass":0,"bCoef":0.5},"goalNet":{"vis":true,"bCoef":0.1,"cMask":["ball"]},"kickOffBarrier":{"vis":false,"bCoef":0.1,"cGroup":["redKO","blueKO"],"cMask":["red","blue"]}}}';
- var classicMap = '';
- var bigMap = '{"name":"RSHL Real Soccer","width":1300,"height":670,"spawnDistance":500,"bg":{"type":"grass","width":1150,"height":600,"kickOffRadius":180,"cornerRadius":0},"playerPhysics":{"bCoef":.5,"invMass":.5,"damping":.96,"acceleration":.12,"kickingAcceleration":.07,"kickingDamping":.96,"kickStrength":5.65},"vertexes":[{"x":0,"y":700,"trait":"kickOffBarrier"},{"x":0,"y":180,"trait":"kickOffBarrier"},{"x":0,"y":-180,"trait":"kickOffBarrier"},{"x":0,"y":-700,"trait":"kickOffBarrier"},{"x":1150,"y":255,"trait":"line"},{"x":840,"y":255,"trait":"line"},{"x":1150,"y":-255,"trait":"line"},{"x":840,"y":-255,"trait":"line"},{"x":1150,"y":155,"trait":"line"},{"x":1030,"y":155,"trait":"line"},{"x":1150,"y":-155,"trait":"line"},{"x":1030,"y":-155,"trait":"line"},{"x":840,"y":-135,"trait":"line","curve":-130},{"x":840,"y":135,"trait":"line","curve":-130},{"x":-1150,"y":-255,"trait":"line","curve":-90,"color":"97AC86"},{"x":-840,"y":-255,"trait":"line"},{"x":-1150,"y":255,"trait":"line"},{"x":-840,"y":255,"trait":"line"},{"x":-1150,"y":-155,"trait":"line"},{"x":-1030,"y":-155,"trait":"line"},{"x":-1150,"y":155,"trait":"line"},{"x":-1030,"y":155,"trait":"line"},{"x":-840,"y":135,"trait":"line","curve":-130},{"x":-840,"y":-135,"trait":"line","curve":-130},{"x":935,"y":4,"trait":"line"},{"x":935,"y":-4,"trait":"line"},{"x":-935,"y":4,"trait":"line"},{"x":-935,"y":-4,"trait":"line"},{"x":-1150,"y":525,"bCoef":0,"cMask":["wall"],"trait":"line"},{"x":-1075,"y":600,"bCoef":0,"cMask":["wall"],"trait":"line"},{"x":-1075,"y":-600,"bCoef":0,"cMask":["wall"],"trait":"line"},{"x":-1150,"y":-525,"bCoef":0,"cMask":["wall"],"trait":"line"},{"x":1075,"y":600,"bCoef":0,"cMask":["wall"],"trait":"line"},{"x":1150,"y":525,"bCoef":0,"cMask":["wall"],"trait":"line"},{"x":1150,"y":-525,"bCoef":0,"cMask":["wall"],"trait":"line"},{"x":1075,"y":-600,"bCoef":0,"cMask":["wall"],"trait":"line"},{"x":-1150,"y":127,"trait":"line","color":"ffffff"},{"x":-1214,"y":124,"trait":"line","color":"ffffff","curve":5},{"x":-1150,"y":-127,"trait":"line","color":"ffffff"},{"x":-1214,"y":-124,"trait":"line","color":"ffffff","curve":5},{"x":1150,"y":127,"trait":"line","color":"ffffff"},{"x":1214,"y":124,"trait":"line","color":"ffffff","curve":-5},{"x":1150,"y":-127,"trait":"line","color":"ffffff"},{"x":1214,"y":-124,"trait":"line","color":"ffffff","curve":-5},{"x":0,"y":-4,"trait":"line"},{"x":0,"y":4,"trait":"line"},{"x":0,"y":-4,"trait":"line"},{"x":0,"y":4,"trait":"line"},{"x":-1214,"y":124,"trait":"line","color":"ffffff"},{"x":-1250,"y":150,"trait":"line","color":"ffffff","pos":[-1250,150]},{"x":-1214,"y":-124,"trait":"line","color":"ffffff"},{"x":-1250,"y":-150,"trait":"line","color":"ffffff","pos":[-1250,-150]},{"x":1214,"y":124,"trait":"line","color":"ffffff"},{"x":1250,"y":150,"trait":"line","color":"ffffff"},{"x":1214,"y":-124,"trait":"line","color":"ffffff"},{"x":1250,"y":-150,"trait":"line","color":"ffffff"},{"x":-1185,"y":155,"bCoef":-4.5,"cMask":["ball"],"trait":"line","curve":40,"color":"BEB86C"},{"x":-1185,"y":255,"bCoef":-4.5,"cMask":["ball"],"trait":"line","curve":40,"color":"BEB86C"},{"x":1185,"y":155,"bCoef":-4.5,"cMask":["ball"],"trait":"line","curve":-40,"color":"BEB86C"},{"x":1185,"y":255,"bCoef":-4.5,"cMask":["ball"],"trait":"line","curve":-40,"color":"BEB86C"},{"x":-1185,"y":-155,"bCoef":-4.5,"cMask":["ball"],"trait":"line","curve":-40,"color":"BEB86C"},{"x":-1185,"y":-255,"bCoef":-4.5,"cMask":["ball"],"trait":"line","curve":-40,"color":"BEB86C"},{"x":1185,"y":-155,"bCoef":-4.5,"cMask":["ball"],"trait":"line","curve":40,"color":"BEB86C"},{"x":1185,"y":-255,"bCoef":-4.5,"cMask":["ball"],"trait":"line","curve":40,"color":"BEB86C"},{"x":1158,"y":-607,"bCoef":-2.45,"cMask":["ball"],"trait":"line","curve":0,"color":"BEB86C"},{"x":1187,"y":-578,"bCoef":-2.45,"cMask":["ball"],"trait":"line","curve":-60,"color":"BEB86C"},{"x":1158,"y":607,"bCoef":-2.45,"cMask":["ball"],"trait":"line","curve":0,"color":"BEB86C"},{"x":1187,"y":578,"bCoef":-2.45,"cMask":["ball"],"trait":"line","curve":60,"color":"BEB86C"},{"x":-1158,"y":607,"bCoef":-2.45,"cMask":["ball"],"trait":"line","curve":0,"color":"BEB86C"},{"x":-1187,"y":578,"bCoef":-2.45,"cMask":["ball"],"trait":"line","curve":-60,"color":"BEB86C"},{"x":-1158,"y":-607,"bCoef":-2.45,"cMask":["ball"],"trait":"line","curve":0,"color":"BEB86C"},{"x":-1187,"y":-578,"bCoef":-2.45,"cMask":["ball"],"trait":"line","curve":60,"color":"BEB86C"},{"x":-1190,"y":-255,"bCoef":-1,"cMask":["ball"],"trait":"line","color":"000000","curve":0},{"x":-1180,"y":-255,"bCoef":-1,"cMask":["ball"],"trait":"line","color":"000000","curve":0},{"x":-1190,"y":-155,"bCoef":-1,"cMask":["ball"],"trait":"line","color":"000000","curve":0},{"x":-1180,"y":-155,"bCoef":-1,"cMask":["ball"],"trait":"line","color":"000000","curve":0},{"x":-1190,"y":155,"bCoef":-1,"cMask":["ball"],"trait":"line","color":"000000","curve":0},{"x":-1180,"y":155,"bCoef":-1,"cMask":["ball"],"trait":"line","color":"000000","curve":0},{"x":-1190,"y":255,"bCoef":-1,"cMask":["ball"],"trait":"line","color":"000000","curve":0},{"x":-1180,"y":255,"bCoef":-1,"cMask":["ball"],"trait":"line","color":"000000","curve":0},{"x":1190,"y":-255,"bCoef":-1,"cMask":["ball"],"trait":"line","color":"000000","curve":0},{"x":1180,"y":-255,"bCoef":-1,"cMask":["ball"],"trait":"line","color":"000000","curve":0},{"x":1190,"y":-155,"bCoef":-1,"cMask":["ball"],"trait":"line","color":"000000","curve":0},{"x":1180,"y":-155,"bCoef":-1,"cMask":["ball"],"trait":"line","color":"000000","curve":0},{"x":1190,"y":255,"bCoef":-1,"cMask":["ball"],"trait":"line","color":"000000","curve":0},{"x":1180,"y":255,"bCoef":-1,"cMask":["ball"],"trait":"line","color":"000000","curve":0},{"x":1190,"y":155,"bCoef":-1,"cMask":["ball"],"trait":"line","color":"000000","curve":0},{"x":1180,"y":155,"bCoef":-1,"cMask":["ball"],"trait":"line","color":"000000","curve":0},{"x":-1148,"y":-525,"trait":"line","curve":-90,"color":"5E844D"},{"x":1148,"y":-525,"trait":"line","color":"5E844D"},{"x":-1148,"y":525,"trait":"line","curve":-90,"color":"5E844D"},{"x":1148,"y":525,"trait":"line","color":"5E844D"},{"x":-1150,"y":-260,"trait":"line","curve":-90,"color":"5E844D"},{"x":-810,"y":-600,"trait":"line","color":"5E844D","curve":-90},{"x":-1150,"y":260,"trait":"line","curve":90,"color":"5E844D"},{"x":-810,"y":600,"trait":"line","color":"5E844D","curve":90},{"x":-840,"y":-1150,"trait":"line","color":"5E844D","curve":-100},{"x":1150,"y":-260,"trait":"line","curve":90,"color":"5E844D"},{"x":810,"y":-600,"trait":"line","color":"5E844D","curve":90,"_selected":true},{"x":1150,"y":260,"trait":"line","curve":-90,"color":"5E844D"},{"x":810,"y":600,"trait":"line","color":"5E844D","curve":-90}],"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":-90,"color":"5E844D","trait":"line","y":-475},{"v0":94,"v1":95,"curve":90,"color":"5E844D","trait":"line","y":-475},{"v0":97,"v1":98,"curve":90,"color":"5E844D","trait":"line","y":-475},{"v0":99,"v1":100,"curve":-90,"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":.5,"trait":"goalPost"},{"pos":[-1150,-127],"color":"FF0000","bCoef":.5,"trait":"goalPost"},{"pos":[1150,127],"color":"0000FF","bCoef":.5,"trait":"goalPost"},{"pos":[1150,-127],"color":"0000FF","bCoef":.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":-.1,"cMask":["ball"],"trait":"goalPost"},{"radius":2,"invMass":0,"pos":[-1150,600],"color":"FFFFFF","bCoef":-.1,"cMask":["ball"],"trait":"goalPost"},{"radius":2,"invMass":0,"pos":[1150,-600],"color":"FFFFFF","bCoef":-.1,"cMask":["ball"],"trait":"goalPost"},{"radius":2,"invMass":0,"pos":[1150,600],"color":"FFFFFF","bCoef":-.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":.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":.5,"color":"FFFF00","cGroup":[]},"reargoalNetleft":{"vis":true,"bCoef":.1,"cMask":["ball","red","blue"],"curve":10,"color":"C7E6BD"},"reargoalNetright":{"vis":true,"bCoef":.1,"cMask":["ball","red","blue"],"curve":-10,"color":"C7E6BD"},"sidegoalNet":{"vis":true,"bCoef":1,"cMask":["ball","red","blue"],"color":"C7E6BD"},"kickOffBarrier":{"vis":false,"bCoef":.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}}';
- var penaltyMap = '{"name":"HBF Penalty","width":500,"height":620,"spawnDistance":250,"bg":{"type":"grass","width":350,"height":600,"kickOffRadius":1,"cornerRadius":0},"playerPhysics":{"bCoef":.5,"invMass":.5,"damping":.96,"acceleration":.12,"kickingAcceleration":.07,"kickingDamping":.96,"kickStrength":5.65},"ballPhysics":{"radius":9.8,"bCoef":.5,"invMass":1,"damping":.99,"color":"FFFFFF","cMask":["all"],"cGroup":["ball"]},"vertexes":[{"x":275,"y":-110,"trait":"goalNet"},{"x":215,"y":-110,"trait":"goalNet"},{"x":275,"y":110,"trait":"goalNet"},{"x":215,"y":110,"trait":"goalNet"},{"x":315,"y":150,"trait":"cord"},{"x":315,"y":-150,"trait":"cord"},{"x":215,"y":150,"trait":"line"},{"x":85,"y":150,"trait":"line"},{"x":215,"y":-150,"trait":"line"},{"x":85,"y":-150,"trait":"line"},{"x":215,"y":260,"trait":"line"},{"x":-95,"y":260,"trait":"line"},{"x":215,"y":-260,"trait":"line"},{"x":-95,"y":-260,"trait":"line"},{"x":-95,"y":130,"trait":"line"},{"x":-95,"y":-130,"trait":"line"},{"x":-350,"y":-520,"trait":"hline"},{"x":213,"y":-520,"trait":"hline"},{"x":-350,"y":520,"trait":"hline"},{"x":213,"y":520,"trait":"hline"},{"x":-95,"y":598,"trait":"hline"},{"x":213,"y":290,"trait":"hline"},{"x":-95,"y":-598,"trait":"hline"},{"x":213,"y":-290,"trait":"hline"},{"x":265,"y":570,"trait":"cLauncher"},{"x":235,"y":600,"trait":"cLauncher"},{"x":235,"y":610,"trait":"stop"},{"x":275,"y":570,"trait":"stop"},{"x":265,"y":-570,"trait":"cLauncher"},{"x":235,"y":-600,"trait":"cLauncher"},{"x":235,"y":-610,"trait":"stop"},{"x":275,"y":-570,"trait":"stop"},{"x":255,"y":160,"trait":"stop"},{"x":255,"y":250,"trait":"stop"},{"x":260,"y":250,"trait":"stop"},{"x":250,"y":250,"trait":"stop"},{"x":260,"y":160,"trait":"stop"},{"x":250,"y":160,"trait":"stop"},{"x":255,"y":-160,"trait":"stop"},{"x":255,"y":-250,"trait":"stop"},{"x":260,"y":-250,"trait":"stop"},{"x":250,"y":-250,"trait":"stop"},{"x":260,"y":-160,"trait":"stop"},{"x":250,"y":-160,"trait":"stop"},{"x":215,"y":-580,"trait":"line"},{"x":195,"y":-600,"trait":"line"},{"x":215,"y":580,"trait":"line"},{"x":195,"y":600,"trait":"line"},{"x":0,"y":4,"trait":"line","color":"6A8F59","vis":true},{"x":0,"y":-4,"trait":"line"},{"x":0,"y":-257,"trait":"line"},{"x":0,"y":-7,"trait":"line"},{"x":0,"y":7,"trait":"line"},{"x":0,"y":257,"trait":"line"},{"x":0,"y":263,"trait":"line"},{"x":0,"y":597,"trait":"line"},{"x":0,"y":-597,"trait":"line"},{"x":0,"y":-263,"trait":"line"},{"x":215,"y":-600,"bCoef":-.1,"trait":"line","color":"C7E6BD"},{"x":215,"y":600,"bCoef":-.1,"trait":"line","color":"C7E6BD"}],"segments":[{"v0":0,"v1":1,"curve":-10,"trait":"goalNet"},{"v0":2,"v1":3,"curve":10,"trait":"goalNet"},{"v0":0,"v1":2,"curve":10,"trait":"goalNet"},{"v0":2,"v1":4,"trait":"cord"},{"v0":0,"v1":5,"trait":"cord"},{"v0":6,"v1":7,"trait":"line"},{"v0":8,"v1":9,"trait":"line"},{"v0":7,"v1":9,"trait":"line"},{"v0":10,"v1":11,"trait":"line"},{"v0":12,"v1":13,"trait":"line"},{"v0":11,"v1":13,"trait":"line"},{"v0":14,"v1":15,"curve":130,"trait":"line"},{"v0":16,"v1":17,"trait":"hline"},{"v0":18,"v1":19,"trait":"hline"},{"v0":20,"v1":21,"curve":100,"trait":"hline"},{"v0":22,"v1":23,"curve":-100,"trait":"hline"},{"v0":24,"v1":25,"curve":-70,"trait":"cLauncher"},{"v0":25,"v1":26,"trait":"stop"},{"v0":24,"v1":27,"trait":"stop"},{"v0":28,"v1":29,"curve":70,"trait":"cLauncher"},{"v0":29,"v1":30,"trait":"stop"},{"v0":28,"v1":31,"trait":"stop"},{"v0":32,"v1":33,"curve":-30,"trait":"gLauncher"},{"v0":34,"v1":35,"trait":"stop"},{"v0":36,"v1":37,"trait":"stop"},{"v0":38,"v1":39,"curve":30,"trait":"gLauncher"},{"v0":40,"v1":41,"trait":"stop"},{"v0":42,"v1":43,"trait":"stop"},{"v0":44,"v1":45,"curve":90,"trait":"line"},{"v0":46,"v1":47,"curve":-90,"trait":"line"},{"v0":48,"v1":49,"curve":90,"trait":"line"},{"v0":48,"v1":49,"curve":-90,"trait":"line"},{"v0":48,"v1":49,"curve":180,"trait":"line"},{"v0":48,"v1":49,"curve":-180,"trait":"line"},{"v0":45,"v1":47,"trait":"blueLimit"},{"v0":50,"v1":51,"trait":"mline"},{"v0":52,"v1":53,"trait":"mline"},{"v0":54,"v1":55,"trait":"mline"},{"v0":56,"v1":57,"trait":"mline"},{"v0":58,"v1":59,"vis":true,"color":"C7E6BD","bCoef":-.1,"trait":"line"}],"goals":[{"p0":[225,-110],"p1":[225,110],"team":"blue"},{"p0":[215,-112],"p1":[-10,-10],"team":"red"},{"p0":[-10,-10],"p1":[-10,10],"team":"red"},{"p0":[-10,10],"p1":[215,112],"team":"red"}],"discs":[{"pos":[215,-110],"trait":"goalPost"},{"pos":[215,110],"trait":"goalPost"},{"radius":3,"pos":[315,150],"trait":"cord"},{"radius":3,"pos":[315,-150],"trait":"cord"}],"planes":[{"normal":[0,1],"dist":-600,"bCoef":0},{"normal":[0,-1],"dist":-600,"bCoef":0},{"normal":[1,0],"dist":-350,"bCoef":0},{"normal":[-1,0],"dist":-285,"bCoef":0},{"normal":[-1,0],"dist":-20,"bCoef":0,"cMask":["red"]},{"normal":[-1,0],"dist":-250,"trait":"blueLimit"}],"traits":{"ballArea":{"vis":false,"bCoef":-1,"cMask":["ball"]},"goalPost":{"radius":5,"invMass":0,"bCoef":.5,"cMask":["all"],"color":"FFFFFF"},"goalNet":{"vis":true,"bCoef":.1,"cMask":["all"],"color":"FFFFFF"},"kickOffBarrier":{"vis":false,"bCoef":.1,"cGroup":["redKO","blueKO"],"cMask":["red","blue"]},"line":{"vis":true,"cMask":[],"color":"C7E6BD"},"hline":{"vis":true,"cMask":[],"color":"5E844D"},"mline":{"vis":true,"cMask":[],"color":"6A8F59"},"stop":{"vis":true,"cMask":["ball"],"bCoef":-.001,"color":"000000"},"cord":{"vis":true,"cMask":[],"color":"DCDCDC"},"cLauncher":{"color":"BEB86C","vis":true,"bCoef":-2.75,"cMask":["ball"]},"gLauncher":{"color":"BEB86C","vis":true,"bCoef":-4.75,"cMask":["ball"]},"cFlag":{"radius":2,"invMass":0,"color":"FFFF00","bCoef":-.1,"cMask":["ball"]},"blueLimit":{"vis":false,"bCoef":0,"cMask":["blue"]}}}';
- /* OPTIONS */
- var afkLimit = 13;
- var drawTimeLimit = 10;//infinity if you want to use a no penalties
- var maxTeamSize = 4;
- var slowMode = 3;
- /* PLAYERS */
- const Team = { SPECTATORS: 0, RED: 1, BLUE: 2 };
- var extendedP = [];
- const eP = { ID: 0, AUTH: 1, CONN: 2, AFK: 3, ACT: 4, GK: 5, MUTE: 6, WARN: 7, RT: 8 };
- const Ss = { GA: 0, WI: 1, LS: 2, WR: 3, GL: 4, AS: 5, GK: 6, CS: 7, CP: 8, ST: 9, RL: 10, NK: 11};
- var players;
- var teamR;
- var teamB;
- var teamS;
- var teamROrder = [];
- var teamBOrder = [];
- var teamSOrder = [];
- /* GAME */
- var lastTeamTouched;
- var lastPlayersTouched;
- var countAFK = false;
- var activePlay = false;
- var goldenGoal = false;
- var SMSet = new Set();
- var banList = [];
- /* STATS */
- var game;
- var GKList = ["", ""];
- var Rposs = 0;
- var Bposs = 0;
- var ballProperties = [0, { "x": 0, "y": 0 }, { "x": 0, "y": 0 }];
- var lastWinner = Team.SPECTATORS;
- var streak = [0, []];
- var allBlues = [];
- var allReds = [];
- /* BALANCE & CHOOSE */
- var chooseMode = false;
- var redCaptainChoice = "";
- var blueCaptainChoice = "";
- var chooseTime = 20;
- var timeOutCap;
- /* REAL SOCCER */
- var isBallOutsideStadium = false;
- var timeOutside = 0;
- var checkAddTime = false;
- var ballSituation = "O";
- const stadiumW = 1150 + ballRadius;
- const stadiumH = 600 + ballRadius;
- var throwDone = [];
- var playersNotInLine = [];
- const GKLine = 840;
- const distCK = 340;
- const greenLine = 525;
- const throwInterval = 10 * 2 * playerRadius;
- var correctThrowPlace = true;
- var warningChange = false;
- var boostUsedRecent = false;
- var boostTimeout;
- var penaltyMode = false;
- var gamePenalty;
- var turnPenalty = [1, 0];
- var penaltyScores = [-1, -1];
- var ballKickCounter = 0;
- /* AUXILIARY */
- var checkTimeVariable = false;
- var statNumber = 0;
- var endGameVariable = false;
- var resettingTeams = false;
- var capLeft = false;
- var statInterval = 6;
- var discordInterval = 5;
- var logWebhook = "https://discordapp.com/api/webhooks/518539639955390484/Ts13q6bZ5mqMsbePEwO0iTGSxusdbcc_VqORFbVAuOW9BqcZNbdB5eCZmUWVNHpdYw4S";
- var recWebhook = "https://discordapp.com/api/webhooks/536189129290154004/9w81CA4gLHR8VA4Sf1Sl0JJ_FkAb_3K_sJaB-03cUbbDE_S2iEDh6PTQHfbytnux_wpR";
- var randomUrl;
- loadMap(aloneMap, 0, 0);
- if (localStorage.getItem("streak") == null) localStorage.setItem("streak", JSON.stringify(streak));
- /* OBJECTS */
- function Goal(time, team, striker, assist) {
- this.time = time;
- this.team = team;
- this.striker = striker;
- this.assist = assist;
- }
- function Game(date, scores, goals, rec) {
- this.date = date;
- this.scores = scores;
- this.goals = goals;
- this.rec = rec;
- }
- /* FUNCTIONS */
- /* AUXILIARY FUNCTIONS */
- function getRandomInt(max) {
- return Math.floor(Math.random() * Math.floor(max));
- }
- function getTime(scores) {
- return "[" + Math.floor(Math.floor(scores.time / 60) / 10).toString() + Math.floor(Math.floor(scores.time / 60) % 10).toString() + ":" + Math.floor(Math.floor(scores.time - (Math.floor(scores.time / 60) * 60)) / 10).toString() + Math.floor(Math.floor(scores.time - (Math.floor(scores.time / 60) * 60)) % 10).toString() + "]"
- }
- function pointDistance(p1, p2) {
- var d1 = p1.x - p2.x;
- var d2 = p1.y - p2.y;
- return Math.sqrt(d1 * d1 + d2 * d2);
- }
- function setTeam(player, add, team) {
- if (add) room.setPlayerTeam(player.id, team);
- else setRealTeam(player, team);
- }
- /*function saveStats() {
- var a = document.createElement("a");
- document.body.appendChild(a);
- a.style = "display: none";
- a.id = "locSto";
- var d = new Date();
- var s = (("0" + d.getDate()).slice(-2) + "" + ("0" + (d.getMonth() + 1)).slice(-2) + "" + (d.getYear() + 1900).toString().substring(2) + "-" + ("0" + d.getHours()).slice(-2) + "" + ("0" + d.getMinutes()).slice(-2) + "" + ("0" + d.getSeconds()).slice(-2)).toString();
- var data = [];
- Object.keys(localStorage).forEach((key) => {
- if (key.length == 43) data.push([key].concat(JSON.parse(localStorage.getItem(key))));
- });
- data.push(["streak"].concat(JSON.parse(localStorage.getItem('streak'))));
- var fileName = `room1_${s}.json`;
- var json = JSON.stringify(data),
- blob = new Blob([json], { type: "octet/stream" });
- randomUrl = window.URL.createObjectURL(blob);
- a.href = randomUrl;
- a.download = fileName;
- console.log("get_update");
- room.sendChat("✅ Stats were saved successfully !");
- }*/
- /* BUTTONS */
- function topBtn() {
- if (teamS.length > 0) {
- if (teamR.length == teamB.length && teamS.length > 1) {
- setTeam(teamS[0], true, Team.RED);
- if (room.getScores() != null) room.sendChat("@" + teamS[0].name + ", you've entered the field !", teamS[0].id);
- setTeam(teamS[1], true, Team.BLUE);
- }
- else if (teamR.length < teamB.length) setTeam(teamS[0], true, Team.RED);
- else setTeam(teamS[0], true, Team.BLUE);
- }
- }
- function randomBtn() {
- if (teamS.length > 0) {
- if (teamR.length == teamB.length && teamS.length > 1) {
- var r = getRandomInt(teamS.length);
- setTeam(teamS[r], true, Team.RED);
- teamS = teamS.filter((spec) => spec.id != teamS[r].id);
- setTeam(teamS[getRandomInt(teamS.length)], true, Team.BLUE);
- }
- else if (teamR.length < teamB.length) setTeam(teamS[getRandomInt(teamS.length)], true, Team.RED);
- else setTeam(teamS[getRandomInt(teamS.length)], true, Team.BLUE);
- }
- }
- function blueToSpecBtn() {
- resettingTeams = true;
- setTimeout(() => { resettingTeams = false; }, 10);
- for (i = 0; i < teamB.length; i++) {
- setTeam(teamB[teamB.length - 1 - i], true, Team.SPECTATORS);
- setRealTeam(teamB[teamB.length - 1 - i], Team.SPECTATORS);
- }
- }
- function redToSpecBtn() {
- resettingTeams = true;
- setTimeout(() => { resettingTeams = false; }, 10);
- for (i = 0; i < teamR.length; i++) {
- setTeam(teamR[teamR.length - 1 - i], true, Team.SPECTATORS);
- setRealTeam(teamR[teamR.length - 1 - i], Team.SPECTATORS);
- }
- }
- function resetBtn() {
- resettingTeams = true;
- setTimeout(() => { resettingTeams = false; }, 10);
- if (teamR.length <= teamB.length) {
- for (i = 0; i < teamR.length; i++) {
- setTeam(teamB[teamB.length - 1 - i], true, Team.SPECTATORS);
- setTeam(teamR[teamR.length - 1 - i], true, Team.SPECTATORS);
- }
- for (i = teamR.length; i < teamB.length; i++) setTeam(teamB[teamB.length - 1 - i], true, Team.SPECTATORS);
- }
- else {
- for (i = 0; i < teamB.length; i++) {
- setTeam(teamB[teamB.length - 1 - i], true, Team.SPECTATORS);
- setTeam(teamR[teamR.length - 1 - i], true, Team.SPECTATORS);
- }
- for (i = teamB.length; i < teamR.length; i++) setTeam(teamR[teamR.length - 1 - i], true, Team.SPECTATORS);
- }
- }
- function blueToRedBtn() {
- resettingTeams = true;
- setTimeout(() => { resettingTeams = false; }, 10);
- for (i = 0; i < teamB.length; i++) setTeam(teamB[i], true, Team.RED);
- }
- function orderTeamsBtn() {
- resettingTeams = true;
- setTimeout(() => { resettingTeams = false; }, 10);
- resetBtn();
- for (i = 0; i < teamROrder.length; i++) setTeam(teamROrder[i], true, Team.RED);
- for (i = 0; i < teamBOrder.length; i++) setTeam(teamBOrder[i], true, Team.BLUE);
- }
- /* GAME FUNCTIONS */
- function checkTime() {
- const scores = room.getScores();
- game.scores = scores;
- if (Math.abs(scores.time - scores.timeLimit) <= 0.01 && scores.timeLimit != 0) {
- if (scores.red != scores.blue) {
- if (checkTimeVariable == false) {
- checkTimeVariable = true;
- setTimeout(() => { checkTimeVariable = false; }, 3000);
- scores.red > scores.blue ? endGame(Team.RED) : endGame(Team.BLUE);
- setTimeout(() => { room.stopGame(); }, 2000);
- }
- return;
- }
- goldenGoal = true;
- room.sendChat("⚽ First goal wins !");
- }
- if (Math.abs(drawTimeLimit * 60 - scores.time - 60) <= 0.01 && players.length > 2) {
- if (checkTimeVariable == false) {
- checkTimeVariable = true;
- setTimeout(() => { checkTimeVariable = false; }, 10);
- room.sendChat("⌛ 60 seconds left until draw !");
- }
- }
- if (Math.abs(scores.time - drawTimeLimit * 60) <= 0.01 && players.length > 2) {
- if (checkTimeVariable == false) {
- checkTimeVariable = true;
- setTimeout(() => { checkTimeVariable = false; }, 10);
- if (teamR.length == maxTeamSize && teamB.length == maxTeamSize) penaltyMode = false;//estaba en true
- endGame(Team.SPECTATORS);
- room.stopGame();
- // if (teamR.length == maxTeamSize && teamB.length == maxTeamSize) loadMap(penaltyMap, 0, 0);
- goldenGoal = false;
- }
- }
- }
- function endGame(winner) {
- Rposs = Rposs / (Rposs + Bposs);
- Bposs = 1 - Rposs;
- var scores;
- endGameVariable = true;
- lastWinner = winner;
- if (!penaltyMode) {
- if (players.length >= 2 * maxTeamSize - 1) activateChooseMode();
- if (penaltyScores[0] == -1) {
- scores = room.getScores();
- game.scores = scores;
- }
- }
- if (winner == Team.RED) {
- (!penaltyMode && players.length >= 2 * maxTeamSize && (game.scores.time >= (5 / 6) * game.scores.timeLimit || game.scores.red == game.scores.scoreLimit || game.scores.blue == game.scores.scoreLimit) && allReds.length >= maxTeamSize && allBlues.length >= maxTeamSize) ? streak[0]++ : streak = [0, []];
- room.sendChat("🔴 Red Team won " + game.scores.red + "-" + game.scores.blue + "" + (penaltyScores[0] != -1 || penaltyScores[1] != -1 ? "[" + penaltyScores[0] + "-" + penaltyScores[1] + "]" : "") + " ! Current streak : " + streak[0] + " 🏆");
- }
- else if (winner == Team.BLUE) {
- (!penaltyMode && players.length >= 2 * maxTeamSize && (game.scores.time >= (5 / 6) * game.scores.timeLimit || game.scores.red == game.scores.scoreLimit || game.scores.blue == game.scores.scoreLimit) && allReds.length >= maxTeamSize && allBlues.length >= maxTeamSize) ? streak = [1, []] : streak = [0, []];
- room.sendChat("🔵 Blue Team won " + game.scores.blue + "-" + game.scores.red + "" + (penaltyScores[0] != -1 || penaltyScores[1] != -1 ? "[" + penaltyScores[1] + "-" + penaltyScores[0] + "]" : "") + " ! Current streak : " + streak[0] + " 🏆");
- }
- else {
- /* if (teamR.length == maxTeamSize && teamB.length == maxTeamSize && penaltyScores[0] == penaltyScores[1]) {
- gamePenalty = game;
- penaltyScores = [0, 0];
- endGameVariable = false;
- turnPenalty = [Team.RED, 0];
- room.sendChat("Penalty Time !");
- return;
- }*/
- //else {
- streak = [0, []];
- room.sendChat("💤 Draw ! 💤");
- //}
- }
- room.sendChat("⭐ Possession : 🔴 " + (Rposs * 100).toPrecision(3).toString() + "% : " + (Bposs * 100).toPrecision(3).toString() + "% 🔵");
- game.scores.red == 0 ? (game.scores.blue == 0 ? room.sendChat("🏆 " + GKList[0].name + " and " + GKList[1].name + " kept a CS ! ") : room.sendChat("🏆 " + GKList[1].name + " kept a CS ! ")) : game.scores.blue == 0 ? room.sendChat("🏆 " + GKList[0].name + " kept a CS ! ") : null;
- updateStats();
- }
- function quickRestart() {
- room.stopGame();
- setTimeout(() => { room.startGame(); }, 2000);
- }
- function resumeGame() {
- setTimeout(() => { room.startGame(); }, 2000);
- setTimeout(() => { room.pauseGame(false); }, 1000);
- }
- function activateChooseMode() {
- chooseMode = true;
- }
- function deactivateChooseMode() {
- if (chooseMode) room.sendChat("Choose Mode ended !");
- chooseMode = false;
- clearTimeout(timeOutCap);
- redCaptainChoice = "";
- blueCaptainChoice = "";
- }
- function loadMap(map, scoreLim, timeLim) {
- if (map == classicMap) {
- (classicMap != '') ? room.setCustomStadium(classicMap) : room.setDefaultStadium("Classic");
- }
- else if (map == bigMap) {
- (bigMap != '.') ? room.setCustomStadium(bigMap) : room.setDefaultStadium("Big");
- }
- else {
- room.setCustomStadium(map);
- }
- room.setScoreLimit(scoreLim);
- room.setTimeLimit(timeLim);
- }
- /* PLAYER FUNCTIONS */
- function updateTeams() {
- players = room.getPlayerList().filter((player) => player.id != 0 && !getAFK(player));
- teamR = players.filter(p => p.team == Team.RED && getRealTeam(p) == Team.RED).concat(players.filter(p => getRealTeam(p) == Team.RED && p.team != Team.RED));
- teamROrder = teamROrder.filter((player) => teamR.find((p) => p.id == player.id) != null).concat(teamR.filter((player) => teamROrder.find((p) => p.id == player.id) == null));
- teamB = players.filter(p => p.team == Team.BLUE && getRealTeam(p) == Team.BLUE).concat(players.filter(p => getRealTeam(p) == Team.BLUE && p.team != Team.BLUE));
- teamBOrder = teamBOrder.filter((player) => teamB.find((p) => p.id == player.id) != null).concat(teamB.filter((player) => teamBOrder.find((p) => p.id == player.id) == null));
- teamS = players.filter(p => p.team == Team.SPECTATORS && getRealTeam(p) == Team.SPECTATORS);
- }
- function handleInactivity() {
- if (countAFK && (teamR.length + teamB.length) > 1) {
- for (i = 0; i < teamR.length; i++) {
- if (teamR[i].team == Team.RED) setActivity(teamR[i], getActivity(teamR[i]) + 1);
- }
- for (i = 0; i < teamB.length; i++) {
- if (teamB[i].team == Team.BLUE) setActivity(teamB[i], getActivity(teamB[i]) + 1);
- }
- }
- for (i = 0; i < extendedP.length; i++) {
- if (extendedP[i][eP.ACT] == 60 * (2 / 3 * afkLimit)) room.sendChat("[PV] ⛔ @" + room.getPlayer(extendedP[i][eP.ID]).name + ", if you don't move or send a message in the next " + Math.floor(afkLimit / 3) + " seconds, you will be kicked !", extendedP[i][eP.ID]);
- if (extendedP[i][eP.ACT] >= 60 * afkLimit) {
- extendedP[i][eP.ACT] = 0;
- if (room.getScores().time <= afkLimit - 0.5) setTimeout(() => { !chooseMode ? quickRestart() : room.stopGame(); }, 10);
- room.kickPlayer(extendedP[i][eP.ID], "AFK", false);
- }
- }
- }
- function getAuth(player) {
- return extendedP.filter((a) => a[0] == player.id) != null ? extendedP.filter((a) => a[0] == player.id)[0][eP.AUTH] : null;
- }
- function getAFK(player) {
- return extendedP.filter((a) => a[0] == player.id) != null ? extendedP.filter((a) => a[0] == player.id)[0][eP.AFK] : null;
- }
- function setAFK(player, value) {
- extendedP.filter((a) => a[0] == player.id).forEach((player) => player[eP.AFK] = value);
- }
- function getActivity(player) {
- return extendedP.filter((a) => a[0] == player.id) != null ? extendedP.filter((a) => a[0] == player.id)[0][eP.ACT] : null;
- }
- function setActivity(player, value) {
- extendedP.filter((a) => a[0] == player.id).forEach((player) => player[eP.ACT] = value);
- }
- function getGK(player) {
- return extendedP.filter((a) => a[0] == player.id) != null ? extendedP.filter((a) => a[0] == player.id)[0][eP.GK] : null;
- }
- function setGK(player, value) {
- extendedP.filter((a) => a[0] == player.id).forEach((player) => player[eP.GK] = value);
- }
- function getMute(player) {
- return extendedP.filter((a) => a[0] == player.id) != null ? extendedP.filter((a) => a[0] == player.id)[0][eP.MUTE] : null;
- }
- function setMute(player, value) {
- extendedP.filter((a) => a[0] == player.id).forEach((player) => player[eP.MUTE] = value);
- }
- function getWarning(player) {
- return extendedP.filter((a) => a[0] == player.id) != null && extendedP.filter((a) => a[0] == player.id).length > 0 ? extendedP.filter((a) => a[0] == player.id)[0][eP.WARN] : null;
- }
- function setWarning(player, value) {
- extendedP.filter((a) => a[0] == player.id).forEach((player) => player[eP.WARN] = value);
- }
- function getRealTeam(player) {
- return extendedP.filter((a) => a[0] == player.id) != null ? extendedP.filter((a) => a[0] == player.id)[0][eP.RT] : null;
- }
- function setRealTeam(player, value) {
- extendedP.filter((a) => a[0] == player.id).forEach((player) => player[eP.RT] = value);
- }
- /* BALANCE & CHOOSE FUNCTIONS */
- function updateRoleOnPlayerIn() {
- updateTeams();
- if (chooseMode) {
- if (players.length == 6) loadMap(bigMap, scoreLimitBig, timeLimitBig);
- getSpecList(teamR.length <= teamB.length ? Team.RED : Team.BLUE);
- }
- balanceTeams();
- }
- function updateRoleOnPlayerOut() {
- updateTeams();
- if (room.getScores() != null && !penaltyMode) {
- var scores = room.getScores();
- if (players.length >= 2 * maxTeamSize && scores.time >= (5 / 6) * game.scores.timeLimit && teamR.length != teamB.length) {
- if ((teamR.length < teamB.length && scores.blue - scores.red == 2) || (teamB.length < teamR.length && scores.red - scores.blue == 2)) {
- endGame((teamR.length < teamB.length && scores.blue - scores.red == 2) ? Team.BLUE : Team.RED);
- room.sendChat("🤖 Ragequit detected. Game ended 🤖");
- setTimeout(() => { room.stopGame(); }, 100);
- return;
- }
- }
- }
- if (penaltyMode && !chooseMode) {
- if (players.length <= 2 * maxTeamSize - 1) {
- penaltyMode = false;
- game = gamePenalty;
- resetBtn();
- penaltyScores = [-1, 0];
- setTimeout(() => { penaltyScores = [-1, -1]; }, 110);
- teamROrder.forEach((p) => setTeam(p, true, Team.RED));
- teamBOrder.forEach((p) => setTeam(p, true, Team.BLUE));
- extendedP.forEach((p) => { if (room.getPlayer(p[eP.ID]) != null) p[eP.RT] = room.getPlayer(p[eP.ID]).team });
- endGame(Team.SPECTATORS);
- setTimeout(() => { room.stopGame(); }, 100);
- return;
- }
- if (teamR.length < maxTeamSize || teamB.length < maxTeamSize) {
- activateChooseMode();
- room.stopGame();
- }
- }
- if (chooseMode) {
- if (players.length == 5) loadMap(classicMap, scoreLimitClassic, timeLimitClassic);
- if (teamR.length == 0 || teamB.length == 0) {
- teamR.length == 0 ? setTeam(teamS[0], true, Team.RED) : setTeam(teamS[0], true, Team.BLUE);
- return;
- }
- if (Math.abs(teamR.length - teamB.length) == teamS.length) {
- room.sendChat("🤖 No choices left, let me handle this situation... 🤖");
- deactivateChooseMode();
- var b = teamS.length;
- if (teamR.length > teamB.length) {
- for (i = 0; i < b; i++) setTeam(teamS[i], !penaltyMode, Team.BLUE);
- }
- else {
- for (i = 0; i < b; i++) setTeam(teamS[i], !penaltyMode, Team.RED);
- }
- if (penaltyMode) setTimeout(() => { penaltyPutPlayers(); }, 5);
- resumeGame();
- return;
- }
- if (streak[0] == 0 && room.getScores() == null && !penaltyMode && Math.abs(teamR.length - teamB.length) == 2) {
- room.sendChat("🤖 Balancing teams... 🤖");
- teamR.length > teamB.length ? setTeam(teamR[teamR.length - 1], true, Team.SPECTATORS) : setTeam(teamB[teamB.length - 1], true, Team.SPECTATORS);
- }
- if (teamR.length == teamB.length && teamS.length < 2) {
- deactivateChooseMode();
- resumeGame();
- return;
- }
- if (capLeft >= 1) {
- choosePlayer();
- capLeft == Team.RED ? redCaptainChoice = "" : blueCaptainChoice = "";
- }
- else {
- if (teamR.length <= teamB.length && redCaptainChoice != "") {
- if (redCaptainChoice == "top") {
- setTeam(teamS[0], !penaltyMode, Team.RED);
- if (penaltyMode) updateOnTeamChange(teamS[0], room.getPlayer(0));
- }
- else if (redCaptainChoice == "random") {
- var r = getRandomInt(teamS.length);
- setTeam(teamS[r], !penaltyMode, Team.RED);
- if (penaltyMode) updateOnTeamChange(teamS[r], room.getPlayer(0));
- }
- else {
- setTeam(teamS[teamS.length - 1], !penaltyMode, Team.RED);
- if (penaltyMode) updateOnTeamChange(teamS[teamS.length - 1], room.getPlayer(0));
- }
- return;
- }
- else if (teamB.length < teamR.length && blueCaptainChoice != "") {
- if (blueCaptainChoice == "top") {
- setTeam(teamS[0], !penaltyMode, Team.BLUE);
- if (penaltyMode) updateOnTeamChange(teamS[0], room.getPlayer(0));
- }
- else if (blueCaptainChoice == "random") {
- var r = getRandomInt(teamS.length);
- setTeam(teamS[r], !penaltyMode, Team.BLUE);
- if (penaltyMode) updateOnTeamChange(teamS[r], room.getPlayer(0));
- }
- else {
- setTeam(teamS[teamS.length - 1], !penaltyMode, Team.BLUE);
- if (penaltyMode) updateOnTeamChange(teamS[teamS.length - 1], room.getPlayer(0));
- }
- return;
- }
- getSpecList(teamR.length <= teamB.length ? Team.RED : Team.BLUE);
- }
- }
- balanceTeams();
- }
- function updateOnTeamChange(changedPlayer, byPlayer) {
- if (changedPlayer.id == 0) {
- room.setPlayerTeam(0, Team.SPECTATORS);
- return;
- }
- if (getAFK(changedPlayer) && changedPlayer.team != Team.SPECTATORS) {
- setTeam(changedPlayer, true, Team.SPECTATORS);
- room.sendChat(changedPlayer.name + " is AFK !");
- return;
- }
- if (warningChange) return;
- if (penaltyMode && teamROrder.concat(teamBOrder).map(x => x.id).includes(changedPlayer.id)) return;
- if (!penaltyMode) setRealTeam(changedPlayer, changedPlayer.team);
- updateTeams();
- if (room.getScores() != null && !penaltyMode) {
- var scores = room.getScores();
- if (changedPlayer.team != Team.SPECTATORS && scores.time <= (3 / 4) * scores.timeLimit && Math.abs(scores.blue - scores.red) < 2) {
- (changedPlayer.team == Team.RED) ? allReds.push(changedPlayer) : allBlues.push(changedPlayer);
- }
- }
- if (changedPlayer.team == Team.SPECTATORS) setActivity(changedPlayer, 0);
- if (chooseMode && resettingTeams == false && byPlayer.id == 0) {
- if (Math.abs(teamR.length - teamB.length) == teamS.length) {
- deactivateChooseMode();
- var b = teamS.length;
- if (teamR.length > teamB.length) {
- for (i = 0; i < b; i++) setTeam(teamS[i], true, Team.BLUE);
- }
- else {
- for (i = 0; i < b; i++) setTeam(teamS[i], true, Team.RED);
- }
- if (penaltyMode) setTimeout(() => { penaltyPutPlayers(); }, 5);
- resumeGame();
- return;
- }
- else if ((teamR.length == maxTeamSize && teamB.length == maxTeamSize) || (teamR.length == teamB.length && teamS.length < 2)) {
- deactivateChooseMode();
- if (penaltyMode) setTimeout(() => { penaltyPutPlayers(); }, 5);
- resumeGame();
- }
- else if (teamR.length <= teamB.length && redCaptainChoice != "") {
- if (redCaptainChoice == "top") {
- setTeam(teamS[0], !penaltyMode, Team.RED);
- if (penaltyMode) updateOnTeamChange(teamS[0], room.getPlayer(0));
- }
- else if (redCaptainChoice == "random") {
- var r = getRandomInt(teamS.length);
- setTeam(teamS[r], !penaltyMode, Team.RED);
- if (penaltyMode) updateOnTeamChange(teamS[r], room.getPlayer(0));
- }
- else {
- setTeam(teamS[teamS.length - 1], !penaltyMode, Team.RED);
- if (penaltyMode) updateOnTeamChange(teamS[teamS.length - 1], room.getPlayer(0));
- }
- }
- else if (teamB.length < teamR.length && blueCaptainChoice != "") {
- if (blueCaptainChoice == "top") {
- setTeam(teamS[0], !penaltyMode, Team.BLUE);
- if (penaltyMode) updateOnTeamChange(teamS[0], room.getPlayer(0));
- }
- else if (blueCaptainChoice == "random") {
- var r = getRandomInt(teamS.length);
- setTeam(teamS[r], !penaltyMode, Team.BLUE);
- if (penaltyMode) updateOnTeamChange(teamS[r], room.getPlayer(0));
- }
- else {
- setTeam(teamS[teamS.length - 1], !penaltyMode, Team.BLUE);
- if (penaltyMode) updateOnTeamChange(teamS[teamS.length - 1], room.getPlayer(0));
- }
- }
- else choosePlayer();
- }
- }
- function balanceTeams() {
- if (!chooseMode) {
- if (players.length == 1) {
- quickRestart();
- loadMap(aloneMap, 0, 0);
- if (teamR.length == 0) setTeam(players[0], true, Team.RED);
- }
- else if (Math.abs(teamR.length - teamB.length) == teamS.length && teamS.length > 0) {
- const n = Math.abs(teamR.length - teamB.length);
- if (players.length == 2) {
- quickRestart();
- loadMap(classicMap, scoreLimitClassic, timeLimitClassic);
- }
- if (teamR.length > teamB.length) {
- for (i = 0; i < n; i++) setTeam(teamS[i], true, Team.BLUE);
- }
- else {
- for (i = 0; i < n; i++) setTeam(teamS[i], true, Team.RED);
- }
- }
- else if (Math.abs(teamR.length - teamB.length) > teamS.length) {
- const n = Math.abs(teamR.length - teamB.length);
- if (players.length == 1) {
- quickRestart();
- loadMap(aloneMap, 0, 0);
- setTeam(players[0], true, Team.RED);
- return;
- }
- else if (players.length == 5) {
- quickRestart();
- loadMap(classicMap, scoreLimitClassic, timeLimitClassic);
- }
- if (players.length == maxTeamSize * 2 - 1) {
- allReds = [];
- allBlues = [];
- }
- if (teamR.length > teamB.length) {
- for (i = 0; i < n; i++) setTeam(teamR[teamR.length - 1 - i], true, Team.SPECTATORS);
- }
- else {
- for (i = 0; i < n; i++) setTeam(teamB[teamB.length - 1 - i], true, Team.SPECTATORS);
- }
- }
- else if (Math.abs(teamR.length - teamB.length) < teamS.length && teamR.length != teamB.length) {
- room.pauseGame(true);
- activateChooseMode();
- choosePlayer();
- }
- else if (teamS.length >= 2 && teamR.length == teamB.length && teamR.length < maxTeamSize) {
- if (teamR.length == 2) {
- quickRestart();
- loadMap(bigMap, scoreLimitBig, timeLimitBig);
- }
- setTimeout (() => { topBtn(); }, 10);
- }
- }
- }
- function choosePlayer() {
- clearTimeout(timeOutCap);
- if (teamR.length <= teamB.length && teamR.length != 0) {
- if (teamROrder[0].id != teamR[0].id || penaltyMode) room.sendChat(teamROrder[0].name + " is currently choosing a player !");
- room.sendChat("[PV] To choose a player, enter his number in the list given or use 'top', 'random' or 'bottom'.", teamROrder[0].id);
- timeOutCap = setTimeout(function (player) { room.sendChat("[PV] Hurry up @" + player.name + ", only " + Number.parseInt(chooseTime / 2) + " seconds left to choose !", player.id); timeOutCap = setTimeout(function (player) { room.kickPlayer(player.id, "You didn't choose in time !", false); }, chooseTime * 500, teamROrder[0]); }, chooseTime * 1000, teamROrder[0]);
- }
- else if (teamB.length < teamR.length && teamB.length != 0) {
- if (teamBOrder[0].id != teamB[0].id || penaltyMode) room.sendChat(teamBOrder[0].name + " is currently choosing a player !");
- room.sendChat("[PV] To choose a player, enter his number in the list given or use 'top', 'random' or 'bottom'.", teamBOrder[0].id);
- timeOutCap = setTimeout(function (player) { room.sendChat("[PV] Hurry up @" + player.name + ", only " + Number.parseInt(chooseTime / 2) + " seconds left to choose !", player.id); timeOutCap = setTimeout(function (player) { room.kickPlayer(player.id, "You didn't choose in time !", false); }, chooseTime * 500, teamBOrder[0]); }, chooseTime * 1000, teamBOrder[0]);
- }
- if (teamR.length != 0 && teamB.length != 0) getSpecList(teamR.length <= teamB.length ? Team.RED : Team.BLUE);
- }
- function getSpecList(team, player = null) {
- var cstm = "[PV] Spectators : ";
- for (i = 0; i < teamS.length; i++) {
- if (140 - cstm.length < (teamS[i].name + "[" + (i + 1) + "], ").length) {
- if (team == Team.RED && teamR.length > 0) room.sendChat(cstm, teamROrder[0].id);
- else if (team == Team.BLUE && teamB.length > 0) room.sendChat(cstm, teamBOrder[0].id);
- else if (team == Team.SPECTATORS && player != null) room.sendChat(cstm, player.id);
- cstm = "... ";
- }
- cstm += teamS[i].name + "[" + (i + 1) + "], ";
- }
- if (cstm == "[PV] Spectators : ") {
- if (team == Team.RED && teamR.length > 0) room.sendChat(cstm, teamROrder[0].id);
- else if (team == Team.BLUE && teamB.length > 0) room.sendChat(cstm, teamBOrder[0].id);
- else if (team == Team.SPECTATORS && player != null) room.sendChat(cstm, player.id);
- return;
- }
- cstm = cstm.substring(0, cstm.length - 2) + ".";
- if (team == Team.RED && teamR.length > 0) room.sendChat(cstm, teamROrder[0].id);
- else if (team == Team.BLUE && teamB.length > 0) room.sendChat(cstm, teamBOrder[0].id);
- else if (team == Team.SPECTATORS && player != null) room.sendChat(cstm, player.id);
- }
- /* STATS FUNCTIONS */
- function getLastTouchOfTheBall() {
- updateTeams();
- for (i = 0; i < players.length; i++) {
- if (players[i].position != null) {
- if (pointDistance(players[i].position, room.getBallPosition()) < triggerDistance) {
- if (!activePlay) activePlay = true;
- if (lastPlayersTouched[0] == null || (lastTeamTouched == players[i].team && lastPlayersTouched[0] != null && lastPlayersTouched[0].id != players[i].id)) {
- if (lastPlayersTouched[0] != null) lastPlayersTouched[1] = lastPlayersTouched[0];
- lastPlayersTouched[0] = players[i];
- }
- lastTeamTouched = players[i].team;
- }
- }
- }
- }
- function getStats() {
- if (activePlay) {
- updateTeams();
- if (!penaltyMode && !isBallOutsideStadium) lastTeamTouched == Team.RED ? Rposs++ : Bposs++;
- ballProperties[2] = ballProperties[1];
- ballProperties[1] = room.getBallPosition();
- ballProperties[0] = (pointDistance(ballProperties[1], ballProperties[2]) * 60 * 60 * 60) / 15000;
- var k = [-1, Infinity];
- for (i = 0; i < teamR.length; i++) {
- if (teamR[i].position != null && teamR[i].position.x < k[1]) {
- k[0] = teamR[i];
- k[1] = teamR[i].position.x;
- }
- }
- if (k[0] != -1 && !penaltyMode) setGK(k[0], getGK(k[0]) + 1);
- k = [-1, -Infinity];
- for (i = 0; i < teamB.length; i++) {
- if (teamB[i].position != null && teamB[i].position.x > k[1]) {
- k[0] = teamB[i];
- k[1] = teamB[i].position.x;
- }
- }
- if (k[0] != -1 && !penaltyMode) setGK(k[0], getGK(k[0]) + 1);
- findGK();
- }
- }
- function updateStats() {
- if (!penaltyMode && players.length >= 2 * maxTeamSize && (game.scores.time >= (5 / 6) * game.scores.timeLimit || game.scores.red == game.scores.scoreLimit || game.scores.blue == game.scores.scoreLimit) && allReds.length >= maxTeamSize && allBlues.length >= maxTeamSize) {
- var stats;
- var streakTime = JSON.parse(localStorage.getItem("streak"));
- if (lastWinner == Team.RED) {
- var k = true;
- for (i = 0; i < allReds.length; i++) {
- for (j = 0; j < streak[1].length; j++) {
- if (allReds[i].id == streak[1][j][1]) {
- streak[1][j][2]++;
- k = false;
- break;
- }
- }
- if (k) streak[1].push([allReds[i].name, allReds[i].id, 1]);
- }
- streak[1].sort((a, b) => { return b[2] - a[2]; });
- }
- else if (lastWinner == Team.BLUE) {
- for (i = 0; i < allBlues.length; i++) streak[1].push([allBlues[i].name, allBlues[i].id, 1]);
- }
- if (streak[0] > streakTime[0]) {
- room.sendChat(`🔥 New streak record ! It is now ${streak[0]} with team [${streak[1][0][0]}, ${streak[1][1][0]}, ${streak[1][2][0]}, ${streak[1][3][0]}]`);
- localStorage.setItem("streak", JSON.stringify(streak));
- }
- for (i = 0; i < allReds.length; i++) {
- localStorage.getItem(getAuth(allReds[i])) ? stats = JSON.parse(localStorage.getItem(getAuth(allReds[i]))) : stats = [0, 0, 0, "0.00", 0, 0, 0, 0, "0.00", 0, "player", allReds[i].name];
- stats[Ss.GA]++;
- lastWinner == Team.RED ? stats[Ss.WI]++ : lastWinner == Team.BLUE ? stats[Ss.LS]++ : stats[Ss.DR]++;
- stats[Ss.WR] = (100 * stats[Ss.WI] / stats[Ss.GA]).toPrecision(3);
- if (lastWinner == Team.RED) {
- var index = 0;
- for (j = 0; j < streak[1].length; j++) {
- if (streak[1][j][1] == allReds[i].id) index = j;
- }
- if (streak[1][index][2] > stats[Ss.ST]) stats[Ss.ST] = streak[1][index][2];
- }
- localStorage.setItem(getAuth(allReds[i]), JSON.stringify(stats));
- }
- for (i = 0; i < allBlues.length; i++) {
- localStorage.getItem(getAuth(allBlues[i])) ? stats = JSON.parse(localStorage.getItem(getAuth(allBlues[i]))) : stats = [0, 0, 0, "0.00", 0, 0, 0, 0, "0.00", 0, "player", allBlues[i].name];
- stats[Ss.GA]++;
- lastWinner == Team.BLUE ? stats[Ss.WI]++ : lastWinner == Team.RED ? stats[Ss.LS]++ : stats[Ss.DR]++;
- stats[Ss.WR] = (100 * stats[Ss.WI] / stats[Ss.GA]).toPrecision(3);
- if (lastWinner == Team.BLUE) {
- if (stats[Ss.ST] == 0) stats[Ss.ST] = 1;
- }
- localStorage.setItem(getAuth(allBlues[i]), JSON.stringify(stats));
- }
- for (i = 0; i < game.goals.length; i++) {
- if (game.goals[i].striker != null) {
- if ((allBlues.concat(allReds)).findIndex((player) => player.id == game.goals[i].striker.id) != -1) {
- stats = JSON.parse(localStorage.getItem(getAuth(game.goals[i].striker)));
- stats[Ss.GL]++;
- localStorage.setItem(getAuth(game.goals[i].striker), JSON.stringify(stats));
- }
- }
- if (game.goals[i].assist != null) {
- if ((allBlues.concat(allReds)).findIndex((player) => player.name == game.goals[i].assist.name) != -1) {
- stats = JSON.parse(localStorage.getItem(getAuth(game.goals[i].assist)));
- stats[Ss.AS]++;
- localStorage.setItem(getAuth(game.goals[i].assist), JSON.stringify(stats));
- }
- }
- }
- if (allReds.findIndex((player) => player.id == GKList[0].id) != -1) {
- stats = JSON.parse(localStorage.getItem(getAuth(GKList[0])));
- stats[Ss.GK]++;
- if (game.scores.blue == 0) stats[Ss.CS]++;
- stats[Ss.CP] = (100 * stats[Ss.CS] / stats[Ss.GK]).toPrecision(3);
- localStorage.setItem(getAuth(GKList[0]), JSON.stringify(stats));
- }
- if (allBlues.findIndex((player) => player.id == GKList[1].id) != -1) {
- stats = JSON.parse(localStorage.getItem(getAuth(GKList[1])));
- stats[Ss.GK]++;
- if (game.scores.red == 0) stats[Ss.CS]++;
- stats[Ss.CP] = (100 * stats[Ss.CS] / stats[Ss.GK]).toPrecision(3);
- localStorage.setItem(getAuth(GKList[1]), JSON.stringify(stats));
- }
- }
- }
- function findGK() {
- var tab = [[-1, ""], [-1, ""]];
- for (i = 0; i < extendedP.length; i++) {
- if (room.getPlayer(extendedP[i][eP.ID]) != null && extendedP[i][eP.RT] == Team.RED) {
- if (tab[0][0] < extendedP[i][eP.GK]) {
- tab[0][0] = extendedP[i][eP.GK];
- tab[0][1] = room.getPlayer(extendedP[i][eP.ID]);
- }
- }
- else if (room.getPlayer(extendedP[i][eP.ID]) != null && extendedP[i][eP.RT] == Team.BLUE) {
- if (tab[1][0] < extendedP[i][eP.GK]) {
- tab[1][0] = extendedP[i][eP.GK];
- tab[1][1] = room.getPlayer(extendedP[i][eP.ID]);
- }
- }
- }
- GKList = [tab[0][1], tab[1][1]];
- }
- function showRankings(stat, text, player = null) {
- var tableau = [];
- Object.keys(localStorage).forEach(function (key) {
- if (key.length == 43) tableau.push([(JSON.parse(localStorage.getItem(key))[Ss.NK]), (JSON.parse(localStorage.getItem(key))[stat])]);
- });
- if (tableau.length < 5) {
- if (player != null) room.sendChat("[PV] Not enough games played yet !", player.id);
- return;
- }
- tableau.sort(function (a, b) {
- return b[1] - a[1];
- });
- if (player == null) room.sendChat(text + "> #1 " + tableau[0][0] + ": " + tableau[0][1] + " #2 " + tableau[1][0] + ": " + tableau[1][1] + " #3 " + tableau[2][0] + ": " + tableau[2][1] + " #4 " + tableau[3][0] + ": " + tableau[3][1] + " #5 " + tableau[4][0] + ": " + tableau[4][1]);
- else room.sendChat("[PV] " + text + "> #1 " + tableau[0][0] + ": " + tableau[0][1] + " #2 " + tableau[1][0] + ": " + tableau[1][1] + " #3 " + tableau[2][0] + ": " + tableau[2][1] + " #4 " + tableau[3][0] + ": " + tableau[3][1] + " #5 " + tableau[4][0] + ": " + tableau[4][1], player.id);
- }
- setInterval(() => {
- if (statNumber % 5 == 0) showRankings(Ss.GA, "Games");
- if (statNumber % 5 == 1) showRankings(Ss.WI, "Wins");
- if (statNumber % 5 == 2) showRankings(Ss.GL, "Goals");
- if (statNumber % 5 == 3) showRankings(Ss.AS, "Assists");
- if (statNumber % 5 == 4) showRankings(Ss.CS, "CS");
- statNumber++;
- }, statInterval * 60 * 1000);
- setTimeout(() => {
- setInterval(() => {
- //room.sendChat("💬 This host was created by Gouiri[FR] and edited by Gimenez20[GI] 👊");
- //room.sendChat("💬 Do you search team to play our leagues? You can enjoy with our leagues (Big 4v4-3def | Real Soccer) 👊");
- //room.sendChat("💬 TS3: hbpt.ts.io, Forum: https://haxball.pt/ , Discord: https://discord.gg/3MhhZPN 👊");
- room.sendChat("💬 Join our Discord: https://discord.gg/3MhhZPN 👊");
- }, discordInterval * 60 * 1000); }, 10000);
- /*setInterval(() => {
- saveStats();
- }, 60 * 60 * 1000);*/
- /* RS FUNCTIONS */
- function isOutsideStadium(ballPosition) {
- return (ballPosition.x > stadiumW || ballPosition.x < -stadiumW || ballPosition.y > stadiumH || ballPosition.y < -stadiumH);
- }
- function boostUsed(ballPosition) {
- return ((Math.abs(ballPosition.x) > 1175 - ballRadius && Math.abs(ballPosition.x) < 1195 + ballRadius && Math.abs(ballPosition.y) > 155 - ballRadius && Math.abs(ballPosition.y) < 255 + ballRadius) || ((Math.abs(ballPosition.x) > 1158 - ballRadius && Math.abs(ballPosition.x) < 1187 + ballRadius && Math.abs(ballPosition.y) > 578 - ballRadius && Math.abs(ballPosition.y) < 607 + ballRadius)))
- }
- function checkBallPosition() {
- if (activePlay) {
- var ballPosition = room.getBallPosition();
- if (boostUsed(ballPosition)) {
- clearTimeout(boostTimeout);
- boostUsedRecent = true;
- boostTimeout = setTimeout(() => { boostUsedRecent = false; }, 300);
- }
- if (isOutsideStadium(ballPosition)) {
- if (!isBallOutsideStadium) {
- isBallOutsideStadium = true;
- if (ballPosition.y > -127 && ballPosition.y < 127) return;
- if (ballPosition.x > stadiumW && lastTeamTouched == Team.RED || ballPosition.x < -stadiumW && lastTeamTouched == Team.BLUE) {
- room.sendChat("GK");
- ballSituation = "G";
- }
- else if (ballPosition.x > stadiumW && lastTeamTouched == Team.BLUE || ballPosition.x < -stadiumW && lastTeamTouched == Team.RED) {
- room.sendChat("CK");
- ballSituation = "C";
- }
- else {
- if (lastTeamTouched == Team.RED) {
- room.sendChat("B");
- ballSituation = Team.BLUE;
- throwDone = [false, ballPosition, null];
- }
- if (lastTeamTouched == Team.BLUE) {
- room.sendChat("R");
- ballSituation = Team.RED;
- throwDone = [false, ballPosition, null];
- }
- }
- }
- else {
- if ((ballSituation == Team.RED || ballSituation == Team.BLUE) && pointDistance(ballPosition, throwDone[1]) > throwInterval && !throwDone[0] && correctThrowPlace) {
- correctThrowPlace = false;
- if (ballPosition.x > throwDone[1].x) {
- if (ballSituation == Team.RED) room.sendChat("BACK");
- if (ballSituation == Team.BLUE) room.sendChat("FURTHER");
- }
- else {
- if (ballSituation == Team.RED) room.sendChat("FURTHER");
- if (ballSituation == Team.BLUE) room.sendChat("BACK");
- }
- }
- if ((ballSituation == Team.RED || ballSituation == Team.BLUE) && pointDistance(ballPosition, throwDone[1]) < throwInterval && !correctThrowPlace) {
- room.sendChat("OK");
- correctThrowPlace = true;
- }
- }
- }
- else {
- if (isBallOutsideStadium) {
- playersNotInLine.forEach((p) => { if (room.getPlayer(p.id) != null) setWarning(p, getWarning(p) + 1); warningHandle(p); });
- playersNotInLine = [];
- correctThrowPlace = true;
- ballSituation = "O";
- }
- isBallOutsideStadium = false;
- }
- }
- }
- function warningHandle(player) {
- if (getWarning(player) == 1) room.sendChat("First line violation : Warning to " + player.name);
- else if (getWarning(player) == 2) {
- warningChange = true;
- setTimeout(() => { warningChange = false; }, 10);
- room.sendChat("Second line violation : 3 seconds suspension to " + player.name);
- setTeam(player, true, Team.SPECTATORS);
- setTimeout((p) => { warningChange = true; setTimeout(() => { warningChange = false; }, 10); setTeam(p, true, getRealTeam(p)); }, 3 * 1000, player);
- }
- else {
- warningChange = true;
- setTimeout(() => { warningChange = false; }, 10);
- room.sendChat("Multiple line violations : 5 seconds suspension to " + player.name);
- setTeam(player, true, Team.SPECTATORS);
- setTimeout((p) => { warningChange = true; setTimeout(() => { warningChange = false; }, 10); setTeam(p, true, getRealTeam(p)); }, 5 * 1000, player);
- }
- }
- function checkPlayersLine() {
- playersNotInLine = [];
- updateTeams();
- var ballPosition = room.getBallPosition();
- if (ballSituation == Team.RED || ballSituation == Team.BLUE) {
- for (i = 0; i < players.length; i++) {
- if (throwDone[0] && players[i].team != lastTeamTouched && players[i].team != ballSituation && players[i].team != Team.SPECTATORS) {
- if ((players[i].position.y > greenLine - playerRadius || players[i].position.y < -greenLine + playerRadius) && pointDistance(ballPosition, players[i].position) < 270) {
- playersNotInLine.push(players[i]);
- }
- }
- }
- }
- else {
- if (ballPosition.x < 0) {
- if (ballSituation == "G" && lastTeamTouched == Team.RED && boostUsedRecent && Math.abs(ballPosition.y) < 350) {
- for (i = 0; i < players.length; i++) {
- if (players[i].team == Team.BLUE && Math.abs(players[i].position.x) > 840 - playerRadius && players[i].position.x * ballPosition.x > 0) playersNotInLine.push(players[i]);
- }
- }
- else if (ballSituation == "C" && lastTeamTouched == Team.BLUE && boostUsedRecent && Math.abs(ballPosition.y) > 350) {
- for (i = 0; i < players.length; i++) {
- if (players[i].team == Team.RED && pointDistance({ "x": 1150, "y": 600 }, { "x": Math.abs(players[i].position.x), "y": Math.abs(players[i].position.y) }) < 340 + playerRadius) {
- playersNotInLine.push(players[i]);
- }
- }
- }
- }
- else {
- if (ballSituation == "G" && lastTeamTouched == Team.BLUE && boostUsedRecent && Math.abs(ballPosition.y) < 350) {
- for (i = 0; i < players.length; i++) {
- if (players[i].team == Team.RED && Math.abs(players[i].position.x) > 840 - playerRadius && players[i].position.x * ballPosition.x > 0) playersNotInLine.push(players[i]);
- }
- }
- else if (ballSituation == "C" && lastTeamTouched == Team.RED && boostUsedRecent && Math.abs(ballPosition.y) > 350) {
- for (i = 0; i < players.length; i++) {
- if (players[i].team == Team.BLUE && pointDistance({ "x": 1150, "y": 600 }, { "x": Math.abs(players[i].position.x), "y": Math.abs(players[i].position.y) }) < 340 + playerRadius) {
- playersNotInLine.push(players[i]);
- }
- }
- }
- }
- }
- }
- function checkPenalty() {
- if (penaltyMode && room.getScores().red + room.getScores().blue == 0) {
- var ballPosition = room.getBallPosition();
- if (ballPosition.x > 10 && ballProperties[0] < 2 || ballKickCounter > 1) {
- if (!checkTimeVariable) {
- checkTimeVariable = true;
- ballKickCounter = 0;
- setTimeout(() => { checkTimeVariable = false; }, 510);
- if (turnPenalty[1] == 3) {
- if (turnPenalty[0] == Team.RED) {
- turnPenalty[0] = Team.BLUE;
- turnPenalty[1] = 0;
- room.sendChat("Blue Turn ! Score : " + penaltyScores[0] + "-" + penaltyScores[1]);
- }
- else if (turnPenalty[0] == Team.BLUE) {
- if (penaltyScores[0] == penaltyScores[1]) {
- room.sendChat("Draw ! Restarting another series.");
- turnPenalty[0] = Team.RED;
- turnPenalty[1] = 0;
- }
- else endPenaltyMode();
- }
- }
- else {
- turnPenalty[1]++;
- if (penaltyScores[1] > penaltyScores[0] || (turnPenalty[0] == Team.BLUE && penaltyScores[0] - penaltyScores[1] > maxTeamSize - turnPenalty[1])) {
- endPenaltyMode();
- }
- room.sendChat("Score : " + penaltyScores[0] + "-" + penaltyScores[1]);
- }
- setTimeout(() => { room.stopGame(); }, 100);
- }
- }
- }
- }
- function endPenaltyMode() {
- penaltyMode = false;
- game = gamePenalty;
- resetBtn();
- penaltyScores[0] > penaltyScores[1] ? teamROrder.forEach((p) => setTeam(p, true, Team.RED)) : teamBOrder.forEach((p) => setTeam(p, true, Team.BLUE));
- extendedP.forEach((p) => { if (room.getPlayer(p[eP.ID]) != null) p[eP.RT] = room.getPlayer(p[eP.ID]).team });
- endGame((penaltyScores[0] > penaltyScores[1] ? Team.RED : Team.BLUE));
- setTimeout(() => { room.stopGame(); }, 1500);
- }
- function penaltyPutPlayers() {
- findGK();
- resetBtn();
- if (turnPenalty[0] == Team.RED) {
- setTeam(teamROrder[turnPenalty[1]], true, Team.RED);
- setTeam(GKList[1], true, Team.BLUE);
- }
- else {
- setTeam(teamBOrder[turnPenalty[1]], true, Team.RED);
- setTeam(GKList[0], true, Team.BLUE);
- }
- }
- /* EVENTS */
- /* PLAYER MOVEMENT */
- room.onPlayerJoin = function (player) {
- if (player.conn && extendedP) {
- extendedP.forEach(p => {
- if (player.conn === p[2]) {
- room.kickPlayer(p[0], 'No entres dos veces a la sala', false);
- }
- });
- }
- fetch(logWebhook, { method: 'POST', body: JSON.stringify({ "content": "JOIN\n" + player.name + "[" + player.auth + "]", "username": roomName.replace(/[\W_]+/g, " ").substring(1,33) }), headers: { 'Content-Type': 'application/json' } }).then(res => res);
- extendedP.push([player.id, player.auth, player.conn, false, 0, 0, false, 0, Team.SPECTATORS]);
- updateRoleOnPlayerIn();
- //room.sendChat("[PV] 👋 Welcome " + player.name + " ! Type '!help' to see the commands. Join our TS3: hbpt.ts.io, Discord: https://discord.gg/3MhhZPN ", player.id);
- //room.sendChat("[PV] 👋 Register in our forum and get informed to our leagues (Big 4v4-3def ::: Real Soccer): https://haxball.pt/ ", player.id);
- room.sendChat("[PV] 👋 Welcome " + player.name + " ! Type '!help' to see the commands. Join our Discord: https://discord.gg/3MhhZPN ", player.id);
- room.sendChat("[PV] 👋 Discord Support: https://discord.gg/3MhhZPN ", player.id);
- if (localStorage.getItem(player.auth) != null && JSON.parse(localStorage.getItem(player.auth))[Ss.RL] != "player") {
- room.setPlayerAdmin(player.id, true);
- room.sendChat((JSON.parse(localStorage.getItem(player.auth))[Ss.RL] == "master" ? "Master " : "Admin ") + player.name + " has connected to the room !");
- }
- if (players.length == maxPlayers - 2) { // Poner contraseña
- room.setPassword(password)
- }
- }
- room.onPlayerTeamChange = function (changedPlayer, byPlayer) {
- updateOnTeamChange(changedPlayer, byPlayer);
- }
- room.onPlayerLeave = function (player) {
- fetch(logWebhook, { method: 'POST', body: JSON.stringify({ "content": "LEAVE\n" + player.name + "[" + getAuth(player) + "]", "username": roomName.replace(/[\W_]+/g, " ").substring(1, 33) }), headers: { 'Content-Type': 'application/json' } }).then(res => res);
- if ((teamR.findIndex((red) => red.id == player.id) == 0 && chooseMode && teamR.length <= teamB.length) || (teamB.findIndex((blue) => blue.id == player.id) == 0 && chooseMode && teamB.length < teamR.length)) {
- choosePlayer();
- capLeft = (teamR.findIndex((red) => red.id == player.id) == 0 && chooseMode && teamR.length <= teamB.length) ? Team.RED : Team.BLUE;
- setTimeout(() => { capLeft = false; }, 10);
- }
- setActivity(player, 0);
- setRealTeam(player, Team.SPECTATORS);
- updateRoleOnPlayerOut();
- if (players.length == maxPlayers - 3) { // Quitar contraseña
- room.setPassword(null)
- }
- }
- room.onPlayerKicked = function (kickedPlayer, reason, ban, byPlayer) {
- if (ban) banList.push([kickedPlayer.name, kickedPlayer.id]);
- }
- /* PLAYER ACTIVITY */
- room.onPlayerChat = function (player, message) {
- // fetch(logWebhook, { method: 'POST', body: JSON.stringify({ "content": "CHAT\n" + player.name + " : " + message, "username": roomName.replace(/[\W_]+/g, " ") }), headers: { 'Content-Type': 'application/json' } }).then(res => res);
- adminMessage = message;
- message = message.split(/ +/);
- if (player.team != Team.SPECTATORS) {
- setActivity(player, 0);
- }
- if (["!help"].includes(message[0].toLowerCase())) {
- room.sendChat("[PV] Player commands : !me, !discord, !ts3, !streak, !games, !wins, !goals, !assists, !cs, !mutes, !bans, !spec.", player.id);
- if (player.admin) room.sendChat("[PV] Admin : !mute <duration = 3> #<id>, !unmute all/#<id>, !clearbans <number>, !slow <duration>, !endslow", player.id);
- }
- else if (["!afk"].includes(message[0].toLowerCase())) {
- if (player.admin) {
- if (players.length != 1 && player.team != Team.SPECTATORS) {
- if (player.team == Team.RED && streak[0] > 0 && room.getScores() == null) setTeam(player, true,Team.SPECTATORS);
- else {
- room.sendChat("[PV] You can't go AFK while you're in a team !", player.id);
- return false;
- }
- }
- else if (players.length == 1 && !getAFK(player)) setTeam(player, true, Team.SPECTATORS);
- setAFK(player, !getAFK(player));
- room.sendChat(player.name + (getAFK(player) ? " is now AFK !" : " is not AFK anymore !"));
- getAFK(player) ? updateRoleOnPlayerOut() : updateRoleOnPlayerIn();
- }
- }
- else if (["!ts3"].includes(message[0].toLowerCase())) {
- room.sendChat("Join our TS3: hbpt.ts.io , to play in our leagues (Big 4v4-3def ::: Real Soccer) ");
- }
- else if (["!discord"].includes(message[0].toLowerCase())) {
- room.sendChat("Join our discord: https://discord.gg/3MhhZPN , to support/suggestions");
- }
- else if (["!save"].includes(message[0].toLowerCase())) {
- if (player.admin) {
- saveStats();
- }
- }
- else if (["!afks", "!afklist"].includes(message[0].toLowerCase())) {
- var cstm = "[PV] AFK List : ";
- for (i = 0; i < extendedP.length; i++) {
- if (room.getPlayer(extendedP[i][eP.ID]) != null && getAFK(room.getPlayer(extendedP[i][eP.ID]))) {
- if (140 - cstm.length < (room.getPlayer(extendedP[i][eP.ID]).name + ", ").length) {
- room.sendChat(cstm, player.id);
- cstm = "... ";
- }
- cstm += room.getPlayer(extendedP[i][eP.ID]).name + ", ";
- }
- }
- if (cstm == "[PV] AFK List : ") {
- room.sendChat("[PV] There's nobody in the AFK List !", player.id);
- return false;
- }
- cstm = cstm.substring(0, cstm.length - 2) + ".";
- room.sendChat(cstm, player.id);
- }
- else if (["!streak"].includes(message[0].toLowerCase())) {
- var streakTime = JSON.parse(localStorage.getItem("streak"));
- room.sendChat(`[PV] ⭐ Current streak is ${streak[0]}` + (streak[1].length != 0 ? ` : [${streak[1][0][0]}, ${streak[1][1][0]}, ${streak[1][2][0]}, ${streak[1][3][0]}] |` : " |") + ` 👑 Best streak is ${streakTime[0]}` + (streakTime[1].length != 0 ? ` : [${streakTime[1][0][0]}, ${streakTime[1][1][0]}, ${streakTime[1][2][0]}, ${streakTime[1][3][0]}]` : "."), player.id);
- }
- else if (["!me"].includes(message[0].toLowerCase())) {
- var stats;
- localStorage.getItem(getAuth(player)) ? stats = JSON.parse(localStorage.getItem(getAuth(player))) : stats = [0, 0, 0, "0.00", 0, 0, 0, 0, "0.00", 0];
- room.sendChat("[PV] " + player.name + "> Game: " + stats[Ss.GA] + ", Win: " + stats[Ss.WI] + ", Loss: " + stats[Ss.LS] + ", WR: " + stats[Ss.WR] + "%, Goal: " + stats[Ss.GL] + ", Assist: " + stats[Ss.AS] + ", GK: " + stats[Ss.GK] + ", CS: " + stats[Ss.CS] + ", CS%: " + stats[Ss.CP] + "%, Streak: " + stats[Ss.ST], player.id);
- }
- else if (["!spec", "!specs"].includes(message[0].toLowerCase())) {
- getSpecList(Team.SPECTATORS, player);
- }
- else if (["!games"].includes(message[0].toLowerCase())) {
- showRankings(Ss.GA, "Games", player);
- }
- else if (["!wins"].includes(message[0].toLowerCase())) {
- showRankings(Ss.WI, "Wins", player);
- }
- else if (["!goals"].includes(message[0].toLowerCase())) {
- showRankings(Ss.GL, "Goals", player);
- }
- else if (["!assists"].includes(message[0].toLowerCase())) {
- showRankings(Ss.AS, "Assists", player);
- }
- else if (["!cs"].includes(message[0].toLowerCase())) {
- showRankings(Ss.CS, "CS", player);
- }
- else if (["!claim"].includes(message[0].toLowerCase())) {
- if (message[1] == masterPassword || message[1] == adminPassword) {
- room.setPlayerAdmin(player.id, true);
- var stats;
- localStorage.getItem(getAuth(player)) ? stats = JSON.parse(localStorage.getItem(getAuth(player))) : stats = [0, 0, 0, "0.00", 0, 0, 0, 0, "0.00", 0, "player", player.name];
- if (message[1] == masterPassword && stats[Ss.RL] != "master") {
- stats[Ss.RL] = "master";
- room.sendChat(player.name + " is now a room master !");
- localStorage.setItem(getAuth(player), JSON.stringify(stats));
- }
- else if (message[1] == adminPassword && stats[Ss.RL] == "player") {
- stats[Ss.RL] = "admin";
- room.sendChat(player.name + " is now a room admin !");
- localStorage.setItem(getAuth(player), JSON.stringify(stats));
- }
- }
- }
- else if (["!setadmin", "!admin"].includes(message[0].toLowerCase())) {
- if (localStorage.getItem(getAuth(player)) && JSON.parse(localStorage.getItem(getAuth(player)))[Ss.RL] == "master") {
- if (message.length >= 2 && message[1][0] == "#") {
- message[1] = message[1].substring(1, message[1].length);
- if (!Number.isNaN(Number.parseInt(message[1])) && room.getPlayer(Number.parseInt(message[1])) != null) {
- var stats;
- localStorage.getItem(getAuth(room.getPlayer(Number.parseInt(message[1])))) ? stats = JSON.parse(localStorage.getItem(getAuth(room.getPlayer(Number.parseInt(message[1]))))) : stats = [0, 0, 0, "0.00", 0, 0, 0, 0, "0.00", 0, "player", room.getPlayer(Number.parseInt(message[1])).name];
- if (stats[Ss.RL] == "player") {
- stats[Ss.RL] = "admin";
- localStorage.setItem(getAuth(room.getPlayer(Number.parseInt(message[1]))), JSON.stringify(stats));
- room.setPlayerAdmin(room.getPlayer(Number.parseInt(message[1])).id, true);
- room.sendChat(room.getPlayer(Number.parseInt(message[1])).name + " is now an administrator of the room !");
- }
- }
- }
- }
- }
- else if (["!setplayer", "!removeadmin"].includes(message[0].toLowerCase())) {
- if (localStorage.getItem(getAuth(player)) && JSON.parse(localStorage.getItem(getAuth(player)))[Ss.RL] == "master") {
- if (message.length >= 2 && message[1][0] == "#") {
- message[1] = message[1].substring(1, message[1].length);
- if (!Number.isNaN(Number.parseInt(message[1])) && room.getPlayer(Number.parseInt(message[1])) != null) {
- var stats;
- localStorage.getItem(getAuth(room.getPlayer(Number.parseInt(message[1])))) ? stats = JSON.parse(localStorage.getItem(getAuth(room.getPlayer(Number.parseInt(message[1]))))) : stats = [0, 0, 0, "0.00", 0, 0, 0, 0, "0.00", 0, "player", room.getPlayer(Number.parseInt(message[1])).name];
- if (stats[Ss.RL] == "admin") {
- room.sendChat(room.getPlayer(Number.parseInt(message[1])).name + " is not an administrator of the room anymore !");
- stats[Ss.RL] = "player";
- localStorage.setItem(getAuth(room.getPlayer(Number.parseInt(message[1]))), JSON.stringify(stats));
- room.setPlayerAdmin(room.getPlayer(Number.parseInt(message[1])).id, false);
- }
- }
- }
- }
- }
- else if (["!mutes", "!mutelist"].includes(message[0].toLowerCase())) {
- var cstm = "[PV] Mute List : ";
- for (i = 0; i < extendedP.length; i++) {
- if (room.getPlayer(extendedP[i][eP.ID]) != null && getMute(room.getPlayer(extendedP[i][eP.ID]))) {
- if (140 - cstm.length < (room.getPlayer(extendedP[i][eP.ID]).name + "[" + (extendedP[i][eP.ID]) + "], ").length) {
- room.sendChat(cstm, player.id);
- cstm = "... ";
- }
- cstm += room.getPlayer(extendedP[i][eP.ID]).name + "[" + (extendedP[i][eP.ID]) + "], ";
- }
- }
- if (cstm == "[PV] Mute List : ") {
- room.sendChat("[PV] There's nobody in the Mute List !", player.id);
- return false;
- }
- cstm = cstm.substring(0, cstm.length - 2) + ".";
- room.sendChat(cstm, player.id);
- }
- else if (["!mute"].includes(message[0].toLowerCase())) {
- if (player.admin) {
- updateTeams();
- var timeOut;
- if (!Number.isNaN(Number.parseInt(message[1])) && message.length > 1) {
- if (Number.parseInt(message[1]) > 0) timeOut = Number.parseInt(message[1]) * 60 * 1000;
- else timeOut = 3 * 60 * 1000;
- if (message[2].length > 1 && message[2][0] == "#") {
- message[2] = message[2].substring(1, message[2].length);
- if (!Number.isNaN(Number.parseInt(message[2])) && room.getPlayer(Number.parseInt(message[2])) != null) {
- if (room.getPlayer(Number.parseInt(message[2])).admin || getMute(room.getPlayer(Number.parseInt(message[2])))) return false;
- setTimeout(function (player) {
- setMute(player, false);
- }, timeOut, room.getPlayer(Number.parseInt(message[2])));
- setMute(room.getPlayer(Number.parseInt(message[2])), true);
- room.sendChat(room.getPlayer(Number.parseInt(message[2])).name + " has been muted for " + (timeOut / 60000) + " minutes!");
- }
- }
- }
- else if (Number.isNaN(Number.parseInt(message[1]))) {
- if (message[1].length > 1 && message[1][0] == "#") {
- message[1] = message[1].substring(1, message[1].length);
- if (!Number.isNaN(Number.parseInt(message[1])) && room.getPlayer(Number.parseInt(message[1])) != null) {
- if (room.getPlayer(Number.parseInt(message[1])).admin || getMute(room.getPlayer(Number.parseInt(message[1])))) return false;
- setTimeout(function (player) {
- setMute(player, false);
- }, 3 * 60 * 1000, room.getPlayer(Number.parseInt(message[1])));
- setMute(room.getPlayer(Number.parseInt(message[1])), true);
- room.sendChat(room.getPlayer(Number.parseInt(message[1])).name + " has been muted for 3 minutes!");
- }
- }
- }
- }
- }
- else if (["!unmute"].includes(message[0].toLowerCase())) {
- if (player.admin && message.length >= 2) {
- if (message[1] == "all") {
- extendedP.forEach((ePlayer) => {
- ePlayer[eP.MUTE] = false;
- });
- room.sendChat("Mutes cleared.");
- }
- else if (!Number.isNaN(Number.parseInt(message[1])) && room.getPlayer(Number.parseInt(message[1])) != null && getMute(room.getPlayer(Number.parseInt(message[1])))) {
- setMute(room.getPlayer(Number.parseInt(message[1])), false);
- room.sendChat(room.getPlayer(Number.parseInt(message[1])).name + " has been unmuted !");
- }
- else if (Number.isNaN(Number.parseInt(message[1]))) {
- if (message[1].length > 1 && message[1][0] == "#") {
- message[1] = message[1].substring(1, message[1].length);
- if (!Number.isNaN(Number.parseInt(message[1])) && room.getPlayer(Number.parseInt(message[1])) != null && getMute(room.getPlayer(Number.parseInt(message[1])))) {
- setMute(room.getPlayer(Number.parseInt(message[1])), false);
- room.sendChat(room.getPlayer(Number.parseInt(message[1])).name + " has been unmuted !");
- }
- }
- }
- }
- }
- else if (["!slow"].includes(message[0].toLowerCase())) {
- if (player.admin) {
- if (message.length == 1) {
- slowMode = 2;
- room.sendChat("2 seconds slow mode enabled !");
- }
- else if (message.length == 2) {
- if (!Number.isNaN(Number.parseInt(message[1]))) {
- if (Number.parseInt(message[1]) > 0) {
- slowMode = Number.parseInt(message[1]);
- room.sendChat(slowMode + " seconds slow mode enabled !");
- return false;
- }
- }
- slowMode = 2;
- room.sendChat("2 seconds slow mode enabled !");
- }
- }
- }
- else if (["!endslow"].includes(message[0].toLowerCase())) {
- if (player.admin) {
- if (slowMode != 0) room.sendChat("Slow mode terminated.");
- slowMode = 0;
- }
- }
- else if (["!banlist", "!bans"].includes(message[0].toLowerCase())) {
- if (banList.length == 0) {
- room.sendChat("[PV] There's nobody in the Ban List !", player.id);
- return false;
- }
- var cstm = "[PV] Ban List : ";
- for (i = 0; i < banList.length; i++) {
- if (140 - cstm.length < (banList[i][0] + "[" + (banList[i][1]) + "], ").length) {
- room.sendChat(cstm, player.id);
- cstm = "... ";
- }
- cstm += banList[i][0] + "[" + (banList[i][1]) + "], ";
- }
- cstm = cstm.substring(0, cstm.length - 2) + ".";
- room.sendChat(cstm, player.id);
- }
- else if (["!clearbans"].includes(message[0].toLowerCase())) {
- if (player.admin) {
- /*if (message.length == 1) {
- room.clearBans();
- room.sendChat("Bans cleared !");
- banList = [];
- }*/
- if (message.length == 2) {
- if (!Number.isNaN(Number.parseInt(message[1]))) {
- if (Number.parseInt(message[1]) > 0) {
- ID = Number.parseInt(message[1]);
- room.clearBan(ID);
- if (banList.length != banList.filter((array) => array[1] != ID)) room.sendChat(banList.filter((array) => array[1] == ID)[0][0] + " has been unbanned from the room !");
- setTimeout(() => {
- banList = banList.filter((array) => array[1] != ID);
- }, 20);
- }
- }
- }
- }
- }
- else if (["!bb", "!bye", "!cya", "!gn"].includes(message[0].toLowerCase())) room.kickPlayer(player.id, "Bye !", false);
- if (teamR.length != 0 && teamB.length != 0 && chooseMode) {
- if (player.id == teamROrder[0].id || player.id == teamBOrder[0].id) {
- var playerChosen;
- if (teamR.length <= teamB.length && player.id == teamROrder[0].id) {
- if (["top", "auto"].includes(message[0].toLowerCase())) {
- setTeam(teamS[0], true, Team.RED);
- redCaptainChoice = "top";
- clearTimeout(timeOutCap);
- room.sendChat(player.name + " chose Top !");
- return false;
- }
- else if (["random", "rand"].includes(message[0].toLowerCase())) {
- setTeam(teamS[getRandomInt(teamS.length)], true, Team.RED);
- redCaptainChoice = "random";
- clearTimeout(timeOutCap);
- room.sendChat(player.name + " chose Random !");
- return false;
- }
- else if (["bottom", "bot"].includes(message[0].toLowerCase())) {
- setTeam(teamS[teamS.length - 1], true, Team.RED);
- redCaptainChoice = "bottom";
- clearTimeout(timeOutCap);
- room.sendChat(player.name + " chose Bottom !");
- return false;
- }
- else if (!Number.isNaN(Number.parseInt(message[0]))) {
- if (Number.parseInt(message[0]) > teamS.length || Number.parseInt(message[0]) < 1) {
- room.sendChat("[PV] Your number is invalid !", player.id);
- return false;
- }
- else {
- playerChosen = teamS[Number.parseInt(message[0]) - 1];
- setTeam(playerChosen, true, Team.RED);
- room.sendChat(player.name + " chose " + playerChosen.name + " !");
- return false;
- }
- }
- }
- if (teamR.length > teamB.length && player.id == teamBOrder[0].id) {
- if (["top", "auto"].includes(message[0].toLowerCase())) {
- setTeam(teamS[0], true, Team.BLUE);
- blueCaptainChoice = "top";
- clearTimeout(timeOutCap);
- room.sendChat(player.name + " chose Top !");
- return false;
- }
- else if (["random", "rand"].includes(message[0].toLowerCase())) {
- setTeam(teamS[getRandomInt(teamS.length)], true, Team.BLUE);
- blueCaptainChoice = "random";
- clearTimeout(timeOutCap);
- room.sendChat(player.name + " chose Random !");
- return false;
- }
- else if (["bottom", "bot"].includes(message[0].toLowerCase())) {
- setTeam(teamS[teamS.length - 1], true, Team.BLUE);
- blueCaptainChoice = "bottom";
- clearTimeout(timeOutCap);
- room.sendChat(player.name + " chose Bottom !");
- return false;
- }
- else if (!Number.isNaN(Number.parseInt(message[0]))) {
- if (Number.parseInt(message[0]) > teamS.length || Number.parseInt(message[0]) < 1) {
- room.sendChat("[PV] Your number is invalid !", player.id);
- return false;
- }
- else {
- playerChosen = teamS[Number.parseInt(message[0]) - 1];
- setTeam(playerChosen, true, Team.BLUE);
- room.sendChat(player.name + " chose " + playerChosen.name + " !");
- return false;
- }
- }
- }
- }
- }
- if (message[0][0] == "!") return false;
- if (getMute(player)) {
- room.sendChat("[PV] You are muted.", player.id);
- return false;
- }
- if (slowMode > 0) {
- if (!player.admin) {
- if (!SMSet.has(player.id)) {
- SMSet.add(player.id);
- setTimeout((number) => {
- SMSet.delete(number);
- }, slowMode * 1000, player.id);
- }
- else {
- room.sendChat("[PV] " + slowMode + " seconds slow mode enabled ! Don't spam chat.", player.id)
- return false;
- }
- }
- }
- if (player.admin) {
- // Si el usuario es admin, mandar un announcement
- var adminChatColor = 0x33FFE0; // Formato: 0xCOLOR (sustituye COLOR por el color en HEXADECIMAL, ejemplo azul es 33FFE0)
- room.sendAnnouncement(`${player.name}: ${adminMessage}`, null, adminChatColor, 'bold', null);
- return false;
- }
- }
- room.onPlayerActivity = function (player) {
- setActivity(player, 0);
- }
- room.onPlayerBallKick = function (player) {
- if (lastPlayersTouched[0] == null || player.id != lastPlayersTouched[0].id) {
- if (!activePlay) activePlay = true;
- lastTeamTouched = player.team;
- lastPlayersTouched[1] = lastPlayersTouched[0];
- lastPlayersTouched[0] = player;
- }
- if (isBallOutsideStadium) {
- var ballPosition = room.getBallPosition();
- if (ballPosition.y > 0) {
- if (player.position.y > ballPosition.y) {
- throwDone[0] = true;
- throwDone[2] = ballPosition;
- correctThrowPlace = true;
- }
- }
- if (ballPosition.y < 0) {
- if (player.position.y < ballPosition.y) {
- throwDone[0] = true;
- throwDone[2] = ballPosition;
- correctThrowPlace = true;
- }
- }
- checkPlayersLine();
- }
- if (penaltyMode && player.team == Team.RED) ballKickCounter++;
- }
- /* GAME MANAGEMENT */
- room.onGameStart = function (byPlayer) {
- if (!penaltyMode) {
- endGameVariable = false;
- if (teamR.length != teamB.length && players.length > 1) {
- room.stopGame();
- balanceTeams();
- return;
- }
- game = new Game(Date.now(), room.getScores(), [], []);
- playersNotInLine = [];
- countAFK = true;
- activePlay = false;
- goldenGoal = false;
- lastPlayersTouched = [null, null];
- teamROrder = teamR;
- teamBOrder = teamB;
- Rposs = 0;
- Bposs = 0;
- GKList = [];
- allReds = [];
- allBlues = [];
- timeOutside = 0;
- isTimeAddedShown = false;
- throwDone = [];
- correctThrowPlace = true;
- penaltyScores = [-1, -1];
- turnPenalty = [1, 0];
- if (teamR.length == maxTeamSize && teamB.length == maxTeamSize) {
- for (i = 0; i < maxTeamSize; i++) {
- allReds.push(teamR[i]);
- allBlues.push(teamB[i]);
- }
- }
- for (i = 0; i < extendedP.length; i++) {
- extendedP[i][eP.GK] = 0;
- extendedP[i][eP.ACT] = 0;
- extendedP[i][eP.WARN] = 0;
- if (room.getPlayer(extendedP[i][eP.ID]) == null) extendedP.splice(i, 1);
- }
- deactivateChooseMode();
- }
- ballKickCounter = 0;
- }
- room.onGameStop = function (byPlayer) {
- if (players.length > 5) orderTeamsBtn();
- if (byPlayer.id == 0 && endGameVariable) {
- updateTeams();
- if (penaltyScores[0] != penaltyScores[1]) {
- if (players.length < 6) setTimeout(() => { loadMap(classicMap, scoreLimitClassic, timeLimitClassic); }, 10);
- else setTimeout(() => { loadMap(bigMap, scoreLimitBig, timeLimitBig); }, 10);
- }
- if (chooseMode) {
- if (players.length == 2 * maxTeamSize) {
- chooseMode = false;
- streak = [0, []];
- resetBtn();
- for (i = 0; i < maxTeamSize; i++) setTimeout(() => { randomBtn(); }, 450 * i);
- setTimeout(() => { room.startGame(); }, 2000);
- }
- else {
- if (lastWinner == Team.RED) blueToSpecBtn();
- else if (lastWinner == Team.BLUE) {
- redToSpecBtn();
- blueToRedBtn();
- }
- else resetBtn();
- setTimeout(() => { topBtn(); }, 25);
- }
- }
- else {
- if (players.length == 2) {
- if (lastWinner == Team.BLUE) {
- setTeam(teamB[0], true, Team.RED);
- setTeam(teamR[0], true, Team.BLUE);
- }
- setTimeout(() => { room.startGame(); }, 2000);
- }
- else if (players.length == 3 || players.length >= 2 * maxTeamSize + 1) {
- if (lastWinner == Team.RED) blueToSpecBtn();
- else {
- redToSpecBtn();
- blueToRedBtn();
- }
- setTimeout(() => { topBtn(); }, 25);
- setTimeout(() => { room.startGame(); }, 2000);
- }
- else if (players.length == 4) {
- resetBtn();
- setTimeout(() => { randomBtn(); setTimeout(() => { randomBtn(); }, 500); }, 500);
- setTimeout(() => { room.startGame(); }, 2000);
- }
- else if (players.length == 5 || players.length >= 2 * maxTeamSize + 1) {
- if (lastWinner == Team.RED) blueToSpecBtn();
- else {
- redToSpecBtn();
- blueToRedBtn();
- }
- setTimeout(() => { topBtn(); }, 25);
- activateChooseMode();
- }
- else if (players.length == 6) {
- resetBtn();
- setTimeout(() => { randomBtn(); setTimeout(() => { randomBtn(); setTimeout(() => { randomBtn(); }, 500); }, 500); }, 500);
- setTimeout(() => { room.startGame(); }, 2000);
- }
- }
- }
- else if (byPlayer.id == 0 && penaltyMode && !chooseMode) {
- penaltyPutPlayers();
- setTimeout(() => { room.startGame(); }, 2000);
- }
- }
- room.onGamePause = function (byPlayer) {
- }
- room.onGameUnpause = function (byPlayer) {
- if (teamR.length == maxTeamSize && teamB.length == maxTeamSize && chooseMode || (teamR.length == teamB.length && teamS.length < 2 && chooseMode)) {
- deactivateChooseMode();
- }
- }
- room.onTeamGoal = function (team) {
- if (!penaltyMode) {
- activePlay = false;
- countAFK = false;
- const scores = room.getScores();
- game.scores = scores;
- if (lastPlayersTouched[0] != null && lastPlayersTouched[0].team == team) {
- if (lastPlayersTouched[1] != null && lastPlayersTouched[1].team == team) {
- room.sendChat("⚽ " + getTime(scores) + " Goal by " + lastPlayersTouched[0].name + " ! Assist by " + lastPlayersTouched[1].name + ". Goal speed : " + ballProperties[0].toPrecision(4).toString() + "km/h " + (team == Team.RED ? "🔴" : "🔵"));
- game.goals.push(new Goal(scores.time, team, lastPlayersTouched[0], lastPlayersTouched[1]));
- }
- else {
- room.sendChat("⚽ " + getTime(scores) + " Goal by " + lastPlayersTouched[0].name + " ! Goal speed : " + ballProperties[0].toPrecision(4).toString() + "km/h " + (team == Team.RED ? "🔴" : "🔵"));
- game.goals.push(new Goal(scores.time, team, lastPlayersTouched[0], null));
- }
- }
- else {
- room.sendChat("😂 " + getTime(scores) + " Own Goal by " + lastPlayersTouched[0].name + " ! Goal speed : " + ballProperties[0].toPrecision(4).toString() + "km/h " + (team == Team.RED ? "🔴" : "🔵"));
- game.goals.push(new Goal(scores.time, team, null, null));
- }
- if (scores.scoreLimit != 0 && (scores.red == scores.scoreLimit || scores.blue == scores.scoreLimit && scores.blue > 0 || goldenGoal == true)) {
- endGame(team);
- goldenGoal = false;
- setTimeout(() => { room.stopGame(); }, 1000);
- }
- }
- else {
- if (team == Team.RED) {
- if (turnPenalty[0] == Team.RED) penaltyScores[0]++;
- else penaltyScores[1]++;
- }
- if (turnPenalty[1] == 3) {
- if (turnPenalty[0] == Team.RED) {
- turnPenalty[0] = Team.BLUE;
- turnPenalty[1] = 0;
- room.sendChat("Blue Turn ! Score : " + penaltyScores[0] + "-" + penaltyScores[1]);
- }
- else if (turnPenalty[0] == Team.BLUE) {
- if (penaltyScores[0] == penaltyScores[1]) {
- room.sendChat("Draw ! Restarting another series.");
- turnPenalty[0] = Team.RED;
- turnPenalty[1] = 0;
- }
- else endPenaltyMode();
- }
- }
- else {
- turnPenalty[1]++;
- if (penaltyScores[1] > penaltyScores[0] || (turnPenalty[0] == Team.BLUE && penaltyScores[0] - penaltyScores[1] > maxTeamSize - turnPenalty[1])) {
- endPenaltyMode();
- }
- room.sendChat("Score : " + penaltyScores[0] + "-" + penaltyScores[1]);
- }
- setTimeout(() => { room.stopGame(); }, 500);
- }
- }
- room.onPositionsReset = function () {
- countAFK = true;
- lastPlayersTouched = [null, null];
- playersNotInLine = [];
- }
- /* MISCELLANEOUS */
- room.onRoomLink = function (url) {
- console.log(url);
- console.log("masterPassword : " + masterPassword);
- console.log("adminPassword : " + adminPassword);
- }
- room.onPlayerAdminChange = function (changedPlayer, byPlayer) {
- if (getMute(changedPlayer) && changedPlayer.admin) {
- room.sendChat(changedPlayer.name + " has been unmuted.");
- setMute(changedPlayer, false);
- }
- if (byPlayer.id != 0 && localStorage.getItem(getAuth(byPlayer)) && JSON.parse(localStorage.getItem(getAuth(byPlayer)))[Ss.RL] == "admin") {
- room.sendChat("You don't have permission to name a player admin !", byPlayer.id);
- room.setPlayerAdmin(changedPlayer.id, false);
- }
- if (byPlayer.id != 0 && localStorage.getItem(getAuth(changedPlayer)) && (JSON.parse(localStorage.getItem(getAuth(changedPlayer)))[Ss.RL] == "admin" || JSON.parse(localStorage.getItem(getAuth(byPlayer)))[Ss.RL] == "master") && changedPlayer.admin == false) {
- room.sendChat("You don't have permission to change rights !", byPlayer.id);
- room.setPlayerAdmin(changedPlayer.id, true);
- }
- }
- room.onStadiumChange = function (newStadiumName, byPlayer) {
- }
- room.onGameTick = function () {
- if (!penaltyMode) {
- checkTime();
- checkBallPosition();
- }
- getStats();
- handleInactivity();
- getLastTouchOfTheBall();
- checkPenalty();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement