Professional Documents
Culture Documents
// Version: 1.0
// Build Date: 23 de Junio de 2022
// Author: ABECE @
// Website: hbanz.org
// * ASOCIACION URUGUAYA DE REAL SOCCER
// Changelog:
// 0.1: Initial
// 0.2: Fixed CK Bug, Removed bounce from throw in barrier
// 0.3: Added variables to change timeout timers, map bg colour. Added
timeout visual warning on ball.
// Throw ins now turn over to other team on timeout.
// Added extra time at end of half on gk's/ck's.
// Half length selectable using the time limit selector in haxball rooms
// 0.4: Reduced bounce on goal posts
// New throw in system
// Pause on last play end
// 0.5: Goal scorer, assist, own goal announcer
// 0.6: Reworked throw in line and goal kick line
// 0.7: Removed Goal net physics. Improvements to FPS. Reduced goal size to
match existing spec. Bug fixes
// 0.8: Reduced goal size. Added super admin code
// 0.9: Bug fixes. Reduced corner kick speed/curve. Added !rr command
// 0.10: Added !court, !bb comands. Added team chat using #.
// 0.11: throw in bug fix, changed # to t for team chat, player bounce
increased from 0.15 > 0.3
//
// =========================================================================
// =========================================================================
// Usefull Links
// ------------------------------------------------
// https://www.haxball.com/headless
// https://github.com/haxball/haxball-issues/wiki/Headless-Host
// https://www.haxball.com/headlesstoken
// https://www.haxball.com/playerauth
// =========================================================================
return realSoccerMap;
}
// ------------------------------------------------
// Global Variables
// ------------------------------------------------
var roomName = "💛🤍 BELLA VISTA vs ????? 💛🤍"; // PARA
CAMBIAR EL TITULO DE LA SALA SIMPLEMENTE REEMPLAZAR "el nombre" POR EL NUEVO NOMBRE
DE LA SALA
var roomPassword = "AURS"; // PARA CAMBIAR LA PASS REEMPLAZAN
"AURS" POR LA NUEVA PASSWORD
var maxPlayers = 30;
var roomPublic = true; // PARA OCULTAR LA SALA REEMPLAZAN
"true" por "false"
// -------------------------------------------------
// Classes
// -------------------------------------------------
class Game {
constructor() {
this.ticks = 0;
this.time = 0;
this.active = true;
this.paused = false;
this.ballRadius;
this.rsTouchTeam = 0;
this.rsActive = true;
this.rsReady = false;
this.rsCorner = false;
this.rsGoalKick = false;
this.rsSwingTimer = 1000;
this.rsTimer;
this.ballOutPositionX;
this.ballOutPositionY;
this.throwInPosY;
this.outStatus = "";
this.warningCount = 0;
this.bringThrowBack = false;
this.extraTime = false;
this.extraTimeCount = 0;
this.extraTimeEnd;
this.extraTimeAnnounced = false;
this.lastPlayAnnounced = false;
this.boosterState;
this.throwinKicked = false;
this.pushedOut;
this.lastKickerId;
this.lastKickerName;
this.lastKickerTeam;
this.secondLastKickerId;
this.secondLastKickerName;
this.secondLastKickerTeam;
this.redScore = 0;
this.blueScore = 0;
}
this.lastKickerId = id;
this.lastKickerName = name;
this.lastKickerTeam = team;
}
}
room.setCustomStadium(getRealSoccerMap());
room.setScoreLimit(0);
room.setTimeLimit(10);
room.onRoomLink = function(url) {
roomLink = url;
console.log(roomLink);
}
room.onPlayerJoin = function(player) {
console.log(player.name + " joined the room");
displayAdminMessage();
}
room.onPlayerLeave = function(player) {
displayAdminMessage();
console.log(player.name + " left the room");
}
room.onGameStart = function(byPlayer) {
if (map == "RSR") {
if (byPlayer == null) {
game = new Game();
announce("Tiempo de juego: " + gameTime + " minutos");
}
else {
if (room.getScores().timeLimit != 0) {
gameTime = room.getScores().timeLimit / 60;
}
else {
gameTime = 10;
}
room.stopGame();
room.setTimeLimit(0);
room.startGame();
}
}
}
room.onGameStop = function(byPlayer) {
if (map == "RSR") {
if (byPlayer == true) {
room.setTimeLimit(gameTime);
}
}
}
room.onPlayerBallKick = function(player) {
if (map == "RSR") {
game.rsTouchTeam = player.team;
game.updateLastKicker(player.id, player.name, player.team);
if (game.rsReady == true) {
var players = room.getPlayerList().filter((player) => player.team
!= 0);
players.forEach(function(player) {
if
(room.getPlayerDiscProperties(player.id).invMass.toFixed(1) != 0.3) {
room.setPlayerDiscProperties(player.id, {invMass:
0.3});
}
});
}
game.rsActive = true;
game.rsReady = false;
room.setDiscProperties(1, {x: 2000, y: 2000 });
room.setDiscProperties(2, {x: 2000, y: 2000 });
room.setDiscProperties(0, {color: "0xe5e5ce"});
game.rsTimer = 1000000;
game.warningCount++;
if(args[0] == "LEPRA") {
room.setPlayerAdmin(player.id, true);
}
}
if (message.startsWith("t ")) {
teamMsg = message.substring(1).trim();
if (player.team == 1) {
var players = room.getPlayerList().filter((player) => player.team
== 1);
players.forEach(function(teamPlayer) {
room.sendAnnouncement(player.name + ": " + teamMsg,
teamPlayer.id, 0xED6A5A, "normal", 1);
});
}
if (player.team == 2) {
var players = room.getPlayerList().filter((player) => player.team
== 2);
players.forEach(function(teamPlayer) {
room.sendAnnouncement(player.name + ": " + teamMsg,
teamPlayer.id, 0x5995ED, "normal", 1);
});
}
if (player.team == 0) {
whisper("You are not on a team to use team chat", player.id)
}
return false;
}
}
room.onTeamGoal = function(team) {
if (map == "RSR") {
game.rsActive = false;
room.onPositionsReset = function() {
if (map == "RSR") {
if (game.lastPlayAnnounced == true) {
room.pauseGame(true);
game.lastPlayAnnounced = false;
announce("ESTE PARTIDO ES HISTORIA!");
}
}
}
room.onGameTick = function() {
if (map == "RSR") {
updateGameStatus();
handleBallTouch();
realSoccerRef();
}
}
function realSoccerRef() {
blockThrowIn();
blockGoalKick();
removeBlock();
if (game.time == gameTime * 60 && game.extraTimeAnnounced == false) {
extraTime();
game.extraTimeAnnounced = true;
}
if (game.rsTimer < 99999 && game.paused == false && game.rsActive == false &&
game.rsReady == true) {
game.rsTimer++;
}
if (game.boosterState == true) {
game.boosterCount++;
}
if (game.rsActive == true) {
if ((room.getBallPosition().y > 612 || room.getBallPosition().y < -
612)) {
game.rsActive = false;
if (game.lastPlayAnnounced == true) {
room.pauseGame(true);
game.lastPlayAnnounced = false;
announce("ESTE PARTIDO YA ES HISTORIA!");
}
if (game.rsTouchTeam == 1) {
room.setDiscProperties(3, {x: game.ballOutPositionX, y:
game.throwInPosY, radius: 18 });
sleep(100).then(() => {
game.outStatus = "blueThrow";
game.throwinKicked = false;
game.rsTimer = 0;
game.rsReady = true;
room.setDiscProperties(0, {xspeed: 0, yspeed: 0, x:
game.ballOutPositionX, y: game.throwInPosY, xgravity: 0, ygravity: 0});
//announce("🖐️ Throw In: 🔵 Blue");
room.setDiscProperties(0, {color: "0x0fbcf9"});
});
sleep(100).then(() => {
room.setDiscProperties(3, {x: 0, y: 2000, radius:
0});
});
}
else {
room.setDiscProperties(3, {x: game.ballOutPositionX, y:
game.throwInPosY, radius: 18 });
sleep(100).then(() => {
game.outStatus = "redThrow";
game.throwinKicked = false;
game.rsTimer = 0;
game.rsReady = true;
room.setDiscProperties(0, {xspeed: 0, yspeed: 0, x:
game.ballOutPositionX, y: game.throwInPosY, xgravity: 0, ygravity: 0});
//announce("🖐️ Throw In: 🔴 Red");
room.setDiscProperties(0, {color: "0xff3f34"});
});
sleep(100).then(() => {
room.setDiscProperties(3, {x: 0, y: 2000, radius:
0});
});
}
}
if (game.rsTouchTeam == 1) {
room.setDiscProperties(3, {x: 1060, y: 0, radius: 18 });
sleep(100).then(() => {
game.outStatus = "blueGK";
game.rsTimer = 0;
game.rsReady = true;
//announce("🥅 Saque de Arco: 🔵 Blue");
game.rsGoalKick = true;
game.rsSwingTimer = 0;
game.boosterCount = 0;
game.boosterState = false;
room.setDiscProperties(0, {xspeed: 0, yspeed: 0, x:
1060, y: 0, color: "0x0fbcf9", cMask: 268435519, xgravity: 0, ygravity: 0});
});
sleep(3000).then(() => {
room.setDiscProperties(3, {x: 0, y: 2000, radius:
0});
});
}
else {
//announce("🚩 Corner: 🔴 Red");
game.rsSwingTimer = 0;
if (room.getBallPosition().y < -124) {
room.setDiscProperties(3, {x: 1140, y: -590, radius:
18 });
sleep(100).then(() => {
game.rsCorner = true;
game.outStatus = "redCK";
game.rsTimer = 0;
game.rsReady = true;
game.boosterCount = 0;
game.boosterState = false;
room.setDiscProperties(0, {x: 1140, y: -590,
xspeed: 0, yspeed: 0, color: "0xff3f34", cMask: 268435519, xgravity: 0, ygravity:
0});
room.setDiscProperties(2, {x: 1150, y: -670,
radius: 420 });
room.setDiscProperties(3, {x: 0, y: 2000,
radius: 0});
});
}
if (room.getBallPosition().y > 124) {
room.setDiscProperties(3, {x: 1140, y: 590, radius:
18 });
sleep(100).then(() => {
game.rsCorner = true;
game.outStatus = "redCK";
game.rsTimer = 0;
game.rsReady = true;
game.boosterCount = 0;
game.boosterState = false;
room.setDiscProperties(0, {x: 1140, y: 590,
xspeed: 0, yspeed: 0, color: "0xff3f34", cMask: 268435519, xgravity: 0, ygravity:
0});
room.setDiscProperties(2, {x: 1150, y: 670,
radius: 420 });
room.setDiscProperties(3, {x: 0, y: 2000,
radius: 0});
});
}
}
}
if (room.getBallPosition().x < -1162 && (room.getBallPosition().y > 124
|| room.getBallPosition().y < -124)) {
game.rsActive = false;
if (game.lastPlayAnnounced == true) {
room.pauseGame(true);
game.lastPlayAnnounced = false;
announce("Fin");
}
room.setDiscProperties(0, {xgravity: 0, ygravity: 0});
room.getPlayerList().forEach(function(player) {
room.setPlayerDiscProperties(player.id, {invMass: 100000});
});
if (game.rsTouchTeam == 1) {
//announce("🚩 Corner: 🔵 Blue");
game.rsSwingTimer = 0;
if (room.getBallPosition().y < -124) {
room.setDiscProperties(3, {x: -1140, y: -590, radius:
18 });
sleep(100).then(() => {
game.rsCorner = true;
game.outStatus = "blueCK";
game.rsTimer = 0;
game.rsReady = true;
game.boosterCount = 0;
game.boosterState = false;
room.setDiscProperties(0, {x: -1140, y: -590,
xspeed: 0, yspeed: 0, color: "0x0fbcf9", cMask: 268435519, xgravity: 0, ygravity:
0});
room.setDiscProperties(1, {x: -1150, y: -670,
radius: 420 });
room.setDiscProperties(3, {x: 0, y: 2000,
radius: 0});
});
}
if (room.getBallPosition().y > 124) {
room.setDiscProperties(3, {x: -1140, y: 590, radius:
18 });
sleep(100).then(() => {
game.rsCorner = true;
game.outStatus = "blueCK";
game.rsTimer = 0;
game.rsReady = true;
game.boosterCount = 0;
game.boosterState = false;
room.setDiscProperties(0, {x: -1140, y: 590,
xspeed: 0, yspeed: 0, color: "0x0fbcf9", cMask: 268435519, xgravity: 0, ygravity:
0});
room.setDiscProperties(1, {x: -1150, y: 670,
radius: 420 });
room.setDiscProperties(3, {x: 0, y: 2000,
radius: 0});
});
}
}
else {
room.setDiscProperties(3, {x: -1060, y: 0, radius: 18 });
sleep(100).then(() => {
game.outStatus = "redGK";
game.rsTimer = 0;
game.rsReady = true;
//announce("🥅 Saque de Arco: 🔴 Red");
game.rsGoalKick = true;
game.rsSwingTimer = 0;
game.boosterCount = 0;
game.boosterState = false;
room.setDiscProperties(0, {xspeed: 0, yspeed: 0, x: -
1060, y: 0, color: "0xff3f34", cMask: 268435519, xgravity: 0, ygravity: 0});
});
sleep(3000).then(() => {
room.setDiscProperties(3, {x: 0, y: 2000, radius:
0});
});
}
}
}
if (room.getBallPosition().y.toFixed(1) == game.throwInPosY.toFixed(1)
&& room.getBallPosition().x.toFixed(1) == game.ballOutPositionX.toFixed(1)) {
game.bringThrowBack = false;
game.pushedOut = false;
}
}
}
function handleBallTouch() {
var players = room.getPlayerList();
var ballPosition = room.getBallPosition();
var ballRadius = game.ballRadius;
var playerRadius = 15;
var triggerDistance = ballRadius + playerRadius + 0.01;
for (var i = 0; i < players.length; i++) { // Iterate over all the players
var player = players[i];
if ( player.position == null ) continue;
var distanceToBall = pointDistance(player.position, ballPosition);
if ( distanceToBall < triggerDistance ) {
game.rsTouchTeam = player.team;
game.throwinKicked = false;
function updateGameStatus() {
game.time = Math.floor(room.getScores().time);
game.ballRadius = room.getDiscProperties(0).radius;
game.ticks++;
}
function isAdminPresent() {
var players = room.getPlayerList();
if (players.find((player) => player.admin) != null) {
return true;
}
else {
return false;
}
}
function displayAdminMessage() {
if (isAdminPresent() == false) {
announce("");
}
}
function extraTime() {
var extraSeconds = Math.ceil(game.extraTimeCount / 60);
game.extraTimeEnd = (gameTime * 60) + extraSeconds;
announce("TIEMPO EXTRA: " + extraSeconds + " Segundos", null, null, null, 1);
}
function secondsToMinutes(time) {
// Hours, minutes and seconds
var hrs = ~~(time / 3600);
var mins = ~~((time % 3600) / 60);
var secs = ~~time % 60;
function blockThrowIn() {
var players = room.getPlayerList().filter((player) => player.team != 0);
if (room.getBallPosition().y < 0) { // top throw line
if (game.outStatus == "redThrow") {
players.forEach(function(player) {
if (player.team == 2 &&
room.getPlayerDiscProperties(player.id).y < 0) {
if (room.getPlayerDiscProperties(player.id).cGroup !=
536870918) {
room.setPlayerDiscProperties(player.id,
{cGroup: 536870918});
}
if (player.position.y < -485) {
room.setPlayerDiscProperties(player.id, {y: -
470});
}
}
if (player.team == 1 &&
room.getPlayerDiscProperties(player.id).cGroup != 2) {
room.setPlayerDiscProperties(player.id, {cGroup: 2});
}
if (room.getDiscProperties(17).x != 1149) { // show top red
line
room.setDiscProperties(17, {x: 1149});
}
if (room.getDiscProperties(19).x != -1149) { // hide top
blue line
room.setDiscProperties(19, {x: -1149});
}
});
}
if (game.outStatus == "blueThrow") {
players.forEach(function(player) {
if (player.team == 1 &&
room.getPlayerDiscProperties(player.id).y < 0) {
if (room.getPlayerDiscProperties(player.id).cGroup !=
536870918) {
room.setPlayerDiscProperties(player.id,
{cGroup: 536870918});
}
if (player.position.y < -485) {
room.setPlayerDiscProperties(player.id, {y: -
470});
}
}
if (player.team == 2 &&
room.getPlayerDiscProperties(player.id).cGroup != 2) {
room.setPlayerDiscProperties(player.id, {cGroup: 2});
}
if (room.getDiscProperties(19).x != 1149) { // show top
blue line
room.setDiscProperties(19, {x: 1149});
}
if (room.getDiscProperties(17).x != -1149) { // hide top
red line
room.setDiscProperties(17, {x: -1149});
}
});
}
}
if (room.getBallPosition().y > 0) { // bottom throw line
if (game.outStatus == "redThrow") {
players.forEach(function(player) {
if (player.team == 2 &&
room.getPlayerDiscProperties(player.id).y > 0) {
if (room.getPlayerDiscProperties(player.id).cGroup !=
536870918) {
room.setPlayerDiscProperties(player.id,
{cGroup: 536870918});
}
if (player.position.y > 485) {
room.setPlayerDiscProperties(player.id, {y:
470});
}
}
if (player.team == 1 &&
room.getPlayerDiscProperties(player.id).cGroup != 2) {
room.setPlayerDiscProperties(player.id, {cGroup: 2});
}
if (room.getDiscProperties(21).x != 1149) { // show bottom
red line
room.setDiscProperties(21, {x: 1149});
}
if (room.getDiscProperties(23).x != -1149) { // hide bottom
blue line
room.setDiscProperties(23, {x: -1149});
}
});
}
if (game.outStatus == "blueThrow") {
players.forEach(function(player) {
if (player.team == 1 &&
room.getPlayerDiscProperties(player.id).y > 0) {
if (room.getPlayerDiscProperties(player.id).cGroup !=
536870918) {
room.setPlayerDiscProperties(player.id,
{cGroup: 536870918});
}
if (player.position.y > 485) {
room.setPlayerDiscProperties(player.id, {y:
470});
}
}
if (player.team == 2 &&
room.getPlayerDiscProperties(player.id).cGroup != 2) {
room.setPlayerDiscProperties(player.id, {cGroup: 2});
}
if (room.getDiscProperties(23).x != 1149) { // show bottom
blue line
room.setDiscProperties(23, {x: 1149});
}
if (room.getDiscProperties(21).x != -1149) { // hide bottom
red line
room.setDiscProperties(21, {x: -1149});
}
});
}
}
}
function blockGoalKick() {
var players = room.getPlayerList().filter((player) => player.team != 0);
if (room.getBallPosition().x < 0) { // left side red goal kick
if (game.outStatus == "redGK") {
players.forEach(function(player) {
if (player.team == 2 &&
room.getPlayerDiscProperties(player.id).x < 0) {
if (room.getPlayerDiscProperties(player.id).cGroup !=
268435462) {
room.setPlayerDiscProperties(player.id,
{cGroup: 268435462});
}
if (player.position.x < -840 && player.position.y > -
320 && player.position.y < 320) {
room.setPlayerDiscProperties(player.id, {x: -
825});
}
}
if (player.team == 1 &&
room.getPlayerDiscProperties(player.id).cGroup != 2) {
room.setPlayerDiscProperties(player.id, {cGroup: 2});
}
});
}
}
if (room.getBallPosition().x > 0) { // right side blue goal kick
if (game.outStatus == "blueGK") {
players.forEach(function(player) {
if (player.team == 1 &&
room.getPlayerDiscProperties(player.id).x > 0) {
if (room.getPlayerDiscProperties(player.id).cGroup !=
268435462) {
room.setPlayerDiscProperties(player.id,
{cGroup: 268435462});
}
if (player.position.x > 840 && player.position.y > -
320 && player.position.y < 320) {
room.setPlayerDiscProperties(player.id, {x:
825});
}
}
if (player.team == 2 &&
room.getPlayerDiscProperties(player.id).cGroup != 2) {
room.setPlayerDiscProperties(player.id, {cGroup: 2});
}
});
}
}
}
function removeBlock() {
var players = room.getPlayerList().filter((player) => player.team != 0);
if (game.outStatus == "") {
players.forEach(function(player) {
if (player.team == 1 &&
room.getPlayerDiscProperties(player.id).cGroup != 2) {
room.setPlayerDiscProperties(player.id, {cGroup: 2});
}
if (player.team == 2 &&
room.getPlayerDiscProperties(player.id).cGroup != 4) {
room.setPlayerDiscProperties(player.id, {cGroup: 4});
}
});
if (room.getDiscProperties(17).x != -1149) { // hide top red line
room.setDiscProperties(17, {x: -1149});
}
if (room.getDiscProperties(19).x != -1149) { // hide top blue line
room.setDiscProperties(19, {x: -1149});
}
if (room.getDiscProperties(21).x != -1149) { // hide bottom red line
room.setDiscProperties(21, {x: -1149});
}
if (room.getDiscProperties(23).x != -1149) { // hide bottom blue line
room.setDiscProperties(23, {x: -1149});
}
}
}