Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var room = HBInit({ roomName: "[BOT]", maxPlayers: 16, playerName : "BOT", public : false});
- room.setDefaultStadium("Classic");
- room.setScoreLimit(3);
- room.setTimeLimit(3);
- /*
- Functions
- */
- // If there are no admins left in the room give admin to one of the remaining players.
- function updateAdmins() {
- // Get all players except the host (id = 0 is always the host)
- var players = room.getPlayerList().filter((player) => player.id != 0 );
- if ( players.length == 0 ) return; // No players left, do nothing.
- if ( players.find((player) => player.admin) != null ) return; // There's an admin left so do nothing.
- room.setPlayerAdmin(players[0].id, true); // Give admin to the first non admin player in the list
- }
- function initPlayerStats(id){
- stats.set(id, [0, 0, 0, 0, 0]) // goals, assists, wins, loses, og
- }
- // Gives the last player who touched the ball, works only if the ball has the same
- // size than in classics maps.
- var radiusBall = 10;
- var triggerDistance = radiusBall + 15 + 0.1;
- function getLastTouchTheBall(lastPlayerTouched) {
- var ballPosition = room.getBallPosition();
- var players = room.getPlayerList();
- for(var i = 0; i < players.length; i++) {
- if(players[i].position != null) {
- var distanceToBall = pointDistance(players[i].position, ballPosition);
- if(distanceToBall < triggerDistance) {
- lastPlayerTouched = players[i];
- }
- }
- }
- return lastPlayerTouched;
- }
- // Calculate the distance between 2 points
- function pointDistance(p1, p2) {
- var d1 = p1.x - p2.x;
- var d2 = p1.y - p2.y;
- return Math.sqrt(d1 * d1 + d2 * d2);
- }
- // return: the name of the team who took a goal
- var team_name = team => team == 1 ? "blue" : "red";
- // return: whether it's an OG
- var isOwnGoal = (team, player) => team != player.team ? " (og)" : "";
- // return: a better display of the second when a goal is scored
- var floor = s => s < 10 ? "0" + s : s;
- // return: whether there's an assist
- var playerTouchedTwice = playerList => playerList[0].team == playerList[1].team ? " (" + playerList[1].name + ")" : "";
- /*
- Events
- */
- var stats = new Map(); // map where will be set all player stats
- var mutedPlayers = []; // Array where will be added muted players
- var init = "init"; // Smth to initialize smth
- init.id = 0 // Faster than getting host's id with the method
- var scorers ; // Map where will be set all scorers in the current game (undefined if reset or end)
- var whoTouchedLast; // var representing the last player who touched the ball
- var whoTouchedBall = [init, init]; // Array where will be set the 2 last players who touched the ball
- room.onPlayerLeave = function(player) {
- updateAdmins();
- }
- room.onPlayerJoin = function(player) {
- updateAdmins(); // Gives admin to the first player who join the room if there's no one
- initPlayerStats(player.id); // Set new player's stat (happens if he refreshs)
- room.sendChat("Hi " + player.name + " ! Write !help or !adminhelp if needed." )
- }
- room.onPlayerChat = function(player, message) {
- if (message == "p") { // Set pause when someone say "p"
- room.pauseGame(true);
- }
- else if (message == "!p"){ // Unpause when someone say "!p"
- room.pauseGame(false);
- }
- else if (message == "!help") {
- room.sendChat('Write "p" to pause the game, "!p" to unpause it, ' +
- '"!stats" to see some stats about yourself in the room. This room is under development. ')
- }
- else if (message == "!adminhelp"){
- room.sendChat('Write "!mute Player to mute somebody in the room, "!unmute Player "' +
- 'to unmute him, "!clear" to reset all bans')
- }
- else if (message == "!stats") {
- ps = stats.get(player.id); // stands for playerstats
- room.sendChat(player.name + ": goals: " + ps[0] + " ,assists: " + ps[1]
- + " ,og: " + ps[4]);
- // + " wins: " + ps[2] + " loses: " + ps[3]
- }
- else if (message == "!admin Anddyisthebest"){
- // Gives admin to the person why type this password
- room.setPlayerAdmin(player.id, true);
- return false; // The message won't be displayed
- }
- else if (player.admin == true && message.substr(0, 5) == "!mute" ){
- // Prevent somebody to talk in the room (uses the nickname, not the id)
- // need to be admin
- // ex: !mute Anddy
- if (!(mutedPlayers.includes(message.substr(6)))) mutedPlayers.push(message.substr(6));
- }
- else if (mutedPlayers.includes(player.name)){
- return false;
- }
- else if (player.admin == true && message.substr(0,7) == "!unmute"){
- // Allow somebody to talk if he has been muted
- // need to be admin
- // ex: !unmute Anddy
- pos = mutedPlayers.indexOf(message.substr(9));
- mutedPlayers.splice(pos, 1);
- }
- else if (player.admin == true && message == "!clear") room.clearBans();
- // reset the banned players
- // need to be admin
- }
- room.onPlayerBallKick = function(player){
- // Gets the last one who kicked the ball
- lastKicker = [player, room.getScores().time]
- }
- room.onGameTick = function() {
- // A situation can happen where a player touch the ball very slightly by directly kicking
- // and it can lead to an error
- whoTouchedLast = getLastTouchTheBall(whoTouchedLast);
- if (whoTouchedLast != undefined && whoTouchedLast.id != whoTouchedBall[0].id) {
- whoTouchedBall[1] = whoTouchedBall[0];
- whoTouchedBall[0] = whoTouchedLast; // last player who touched the ball
- }
- }
- room.onTeamGoal = function(team){ // Write on chat who scored and when.
- var time = room.getScores().time;
- var m = Math.trunc(time/60); var s = Math.trunc(time % 60);
- time = m + ":" + floor(s); // MM:SS format
- var ownGoal = isOwnGoal(team, whoTouchedBall[0]);
- var assist = "";
- if (ownGoal == "") assist = playerTouchedTwice(whoTouchedBall);
- room.sendChat("A goal has been scored by " + whoTouchedBall[0].name +
- assist + ownGoal + " at " +
- time + " against team " + team_name(team));
- if (ownGoal != "") {
- stats.get(whoTouchedBall[0].id)[4] += 1;
- } else {
- stats.get(whoTouchedBall[0].id)[0] += 1;
- }
- if (whoTouchedBall[1] != init && assist != "") stats.get(whoTouchedBall[1].id)[1] += 1;
- if (scorers == undefined) scorers = new Map(); // Initializing dict of scorers
- scorers.set(scorers.size + 1 +") " + whoTouchedLast.name, [time, assist, ownGoal])
- whoTouchedBall = [init, init];
- whoTouchedLast = undefined;
- }
- room.onTeamVictory = function(scores){ // Sum up all scorers since the beginning of the match.
- room.sendChat("Scored goals:")
- for (var [key, value] of scorers) { // key: name of the player, value: time of the goal
- room.sendChat(key + " " + value[1] + value[2] + ": " + value[0]);
- }
- }
- room.onGameStop = function(){
- scorers = undefined;
- whoTouchedBall = [init, init];
- whoTouchedLast = undefined;
- }
- function isOutsideStadium(ballPosition) {
- return ballPosition.x > stadiumWidth || ballPosition.x < -stadiumWidth || ballPosition.y > stadiumHeight || ballPosition.y < -stadiumHeight;
- }
- var isBallOutsideStadium = false;
- function checkBallPosition() {
- var ballPosition = room.getBallPosition();
- if(isOutsideStadium(ballPosition)) {
- if(!isBallOutsideStadium) {
- isBallOutsideStadium = true;
- exitingPos = ballPosition.x;
- var totalScores = room.getScores().red + room.getScores().blue;
- if(lastScores != totalScores) {
- lastScores = totalScores;
- return false;
- }
- if(ballPosition.x > stadiumWidth && lastTeamTouched == Team.RED || ballPosition.x < -stadiumWidth && lastTeamTouched == Team.BLUE) {
- lastCall = "[A] Kale Vuruşu";
- room.sendChat("[A] Kale Vuruşu Dokunmayın Karşı Takım");
- }
- else if(ballPosition.x > stadiumWidth && lastTeamTouched == Team.BLUE || ballPosition.x < -stadiumWidth && lastTeamTouched == Team.RED) {
- room.sendChat("[K] Köşe Vuruşu İyi Hizala Kısa Diyerek Aut Kullanma");
- lastCall = "[K] Köşe Vuruşu İyi Hizala Kısa Diyerek Aut Kullanma";
- }
- else {
- isBallKickedOutside = false;
- room.sendChat(lastTeamTouched == Team.RED ? "[B] Taç mavi takımda kırmızı sakın dokunma" : "[R] Taç kırmızı takımda mavi sakın dokunma");
- lastCall = lastTeamTouched == Team.RED ? "2" : "1";
- }
- }
- }
- else {
- isBallOutsideStadium = false;
- backMSG = true;
- }
- return true;
- }
- function getLastTouchTheBall() {
- var ballPosition = room.getBallPosition();
- var players = room.getPlayerList();
- for(var i = 0; i < players.length; i++) {
- if(players[i].position != null) {
- var distanceToBall = pointDistance(players[i].position, ballPosition);
- if(distanceToBall < triggerDistance) {
- if(lastPlayerTouched!=players[i].name)
- {
- if(lastTeamTouched==players[i].team)
- {
- assistingTouch = lastPlayerTouched;
- }else assistingTouch = "";
- }
- lastTeamTouched = players[i].team;
- previousPlayerTouched == lastPlayerTouched;
- lastPlayerTouched = players[i].name;
- }
- }
- }
- return lastPlayerTouched;
- }
- function pointDistance(p1, p2) {
- var d1 = p1.x - p2.x;
- var d2 = p1.y - p2.y;
- return Math.sqrt(d1 * d1 + d2 * d2);
- }
- function getPlayersNotWithinLine()
- {
- var players = room.getPlayerList();
- var found = false;
- if(crossed)
- {
- for(var i = 0; i < players.length; i++) {
- if(players[i].position != null) {
- if(players[i].team != lastTeamTouched && players[i].team!= lastCall)
- {
- if((players[i].position.y > greenLine || players[i].position.y < -greenLine) && pointDistance(room.getBallPosition(), players[i].position)<770)
- {
- for(var j = 0; j < lineCrossedPlayers.length; j++)
- {
- if(lineCrossedPlayers[j].name==players[i].name)
- {
- lineCrossedPlayers[j].times = lineCrossedPlayers[j].times + 1;
- room.sendChat("Cizgiyi Geçme Sünnetçi Gelir Haaa - " + players[i].name + " {" + lineCrossedPlayers[j].times + "}");
- found = true;
- }
- }
- if(!found)
- {
- lineCrossedPlayers.push({name: players[i].name, times: 1});
- room.sendChat("Cizgiyi Geçme Sünnetçi Gelir Haaa - " + players[i].name + " {1}");
- }
- }
- }
- }
- }
- }
- crossed = false;
- }
- function isBackRequired()
- {
- var ballPosition = room.getBallPosition();
- if(lastCall=="1")
- {
- if((ballPosition.x - exitingPos > throwInLeeway) && backMSG==true && isOutsideStadium(ballPosition))
- {
- backMSG = false;
- room.sendChat("Yerinden kullan La Ayı");
- }
- if((ballPosition.x - exitingPos < -throwInLeeway) && backMSG==true && isOutsideStadium(ballPosition))
- {
- backMSG = false;
- room.sendChat("Yerinden kullan La Ayı");
- }
- }
- if(lastCall=="2")
- {
- if((ballPosition.x - exitingPos > throwInLeeway) && backMSG==true && isOutsideStadium(ballPosition))
- {
- backMSG = false;
- room.sendChat("Yerinden kullan La Ayı");
- }
- if((ballPosition.x - exitingPos < -throwInLeeway) && backMSG==true && isOutsideStadium(ballPosition))
- {
- backMSG = false;
- room.sendChat("Yerinden kullan La Ayı");
- }
- }
- }
- function isThrowInCorrect()
- {
- var ballPosition = room.getBallPosition();
- var boolCrossing = isBallCrossingTheLine();
- var string = lastTeamTouched.toString();
- if(boolCrossing && !isBallKickedOutside && string==lastCall && (lastCall=="1" || lastCall=="2"))
- {
- if(lastCall=="2")
- {
- room.sendChat("[UYARI] Taçı sürükleyerek kullanma Leyn")
- }
- if(lastCall=="1")
- {
- room.sendChat("[UYARI] Taçı sürükleyerek kullanma Leyn");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement