Advertisement
Guest User

Untitled

a guest
Nov 17th, 2019
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.90 KB | None | 0 0
  1. geo = {
  2. "code": "",
  3. "lat": 49.209452,
  4. "lon": 19.76135
  5. }
  6.  
  7. var room = HBInit({ roomName: "🔵(S.L.H) SuperCup", maxPlayers: 30, playerName : "Lproject", public : true ,password : "semif",geo });
  8. room.setDefaultStadium("Classic");
  9. room.setScoreLimit(0);
  10. room.setTimeLimit(7);
  11.  
  12.  
  13.  
  14.  
  15.  
  16. /*
  17. Functions
  18. */
  19. // If there are no admins left in the room give admin to one of the remaining players.
  20. function updateAdmins() {
  21. // Get all players except the host (id = 0 is always the host)
  22. var players = room.getPlayerList().filter((player) => player.id != 0 );
  23. if ( players.length == 0 ) return; // No players left, do nothing.
  24. if ( players.find((player) => player.admin) != null ) return; // There's an admin left so do nothing.
  25. room.setPlayerAdmin(players[0].id, true); // Give admin to the first non admin player in the list
  26. }
  27.  
  28. function initPlayerStats(id){
  29. stats.set(id, [0, 0, 0, 0, 0]) // goals, assists, wins, loses, og
  30. }
  31.  
  32.  
  33. // Gives the last player who touched the ball, works only if the ball has the same
  34. // size than in classics maps.
  35. var radiusBall = 10;
  36. var triggerDistance = radiusBall + 15 + 0.1;
  37. function getLastTouchTheBall(lastPlayerTouched) {
  38. var ballPosition = room.getBallPosition();
  39. var players = room.getPlayerList();
  40. for(var i = 0; i < players.length; i++) {
  41. if(players[i].position != null) {
  42. var distanceToBall = pointDistance(players[i].position, ballPosition);
  43. if(distanceToBall < triggerDistance) {
  44. lastPlayerTouched = players[i];
  45. }
  46. }
  47. }
  48. return lastPlayerTouched;
  49.  
  50. }
  51.  
  52. // Calculate the distance between 2 points
  53. function pointDistance(p1, p2) {
  54. var d1 = p1.x - p2.x;
  55. var d2 = p1.y - p2.y;
  56. return Math.sqrt(d1 * d1 + d2 * d2);
  57. }
  58.  
  59.  
  60. // return: the name of the team who took a goal
  61. var team_name = team => team == 1 ? "blue" : "red";
  62.  
  63. // return: whether it's an Own Goal
  64. var isOwnGoal = (team, player) => team != player.team ? " (OwnGoal)" : "";
  65.  
  66. // return: a better display of the second when a goal is scored
  67. var floor = s => s < 10 ? "0" + s : s;
  68.  
  69. // return: whether there's an assist
  70. var playerTouchedTwice = playerList => playerList[0].team == playerList[1].team ? " (" + playerList[1].name + ")" : "";
  71.  
  72.  
  73.  
  74. /*
  75. Events
  76. */
  77. var stats = new Map(); // map where will be set all player stats
  78. var mutedPlayers = []; // Array where will be added muted players
  79. var init = "init"; // Smth to initialize smth
  80. init.id = 0 // Faster than getting host's id with the method
  81. var scorers ; // Map where will be set all scorers in the current game (undefined if reset or end)
  82. var whoTouchedLast; // var representing the last player who touched the ball
  83. var whoTouchedBall = [init, init]; // Array where will be set the 2 last players who touched the ball
  84.  
  85.  
  86. room.onPlayerLeave = function(player) {
  87. updateAdmins();
  88. }
  89.  
  90.  
  91.  
  92. room.onPlayerJoin = function(player) {
  93.  
  94. updateAdmins(); // Gives admin to the first player who join the room if there's no one
  95. initPlayerStats(player.id); // Set new player's stat (happens if he refreshs)
  96. room.sendChat(" Hi " + player.name + " Welcome to S.L.H " )
  97. }
  98.  
  99. room.onPlayerChat = function(player, message) {
  100. if (message == "p") { // Set pause when someone say "p"
  101. room.pauseGame(false);
  102. }
  103. else if (message == "!p"){ // Unpause when someone say "!p"
  104. room.pauseGame(false);
  105. }
  106. else if (message == "!adminhelp"){
  107. room.sendChat('Write "!mute Player to mute somebody in the room, "!unmute Player "' +
  108. 'to unmute him, "!clear" to reset all bans')
  109. }
  110. else if (message == "!stats") {
  111. ps = stats.get(player.id); // stands for playerstats
  112. room.sendChat(player.name + ": goals: " + ps[0] + " ,assists: " + ps[1]
  113. + " ,OwnGoals: " + ps[4]);
  114. // + " wins: " + ps[2] + " loses: " + ps[3]
  115. }
  116. else if (message == "!erika26"){
  117. // Gives admin to the person why type this password
  118. room.setPlayerAdmin(player.id, true);
  119. return false; // The message won't be displayed
  120. }
  121. else if (player.admin == true && message.substr(0, 5) == "!mute" ){
  122. // Prevent somebody to talk in the room (uses the nickname, not the id)
  123. // need to be admin
  124. // ex: !mute Anddy
  125. if (!(mutedPlayers.includes(message.substr(6)))) mutedPlayers.push(message.substr(6));
  126. }
  127. else if (mutedPlayers.includes(player.name)){
  128. return false;
  129. }
  130. else if (player.admin == true && message.substr(0,7) == "!unmute"){
  131. // Allow somebody to talk if he has been muted
  132. // need to be admin
  133. // ex: !unmute Anddy
  134. pos = mutedPlayers.indexOf(message.substr(9));
  135. mutedPlayers.splice(pos, 1);
  136. }
  137. else if (player.admin == true && message == "!clear") room.clearBans();
  138. // reset the banned players
  139. // need to be admin
  140.  
  141. }
  142.  
  143. room.onPlayerBallKick = function(player){
  144. // Gets the last one who kicked the ball
  145. lastKicker = [player, room.getScores().time]
  146. }
  147.  
  148.  
  149.  
  150.  
  151.  
  152. room.onGameTick = function() {
  153. // A situation can happen where a player touch the ball very slightly by directly kicking
  154. // and it can lead to an error
  155.  
  156. whoTouchedLast = getLastTouchTheBall(whoTouchedLast);
  157. if (whoTouchedLast != undefined && whoTouchedLast.id != whoTouchedBall[0].id) {
  158. whoTouchedBall[1] = whoTouchedBall[0];
  159. whoTouchedBall[0] = whoTouchedLast; // last player who touched the ball
  160. }
  161. }
  162.  
  163.  
  164. room.onTeamGoal = function(team){ // Write on chat who scored and when.
  165.  
  166.  
  167. var time = room.getScores().time;
  168. var m = Math.trunc(time/60); var s = Math.trunc(time % 60);
  169. time = m + ":" + floor(s); // MM:SS format
  170. var ownGoal = isOwnGoal(team, whoTouchedBall[0]);
  171. var assist = "";
  172. if (ownGoal == "") assist = playerTouchedTwice(whoTouchedBall);
  173.  
  174.  
  175. room.sendChat("GOAAAAAAAAL BY " + whoTouchedBall[0].name +
  176. assist + ownGoal + " at " +
  177. time + " against team " + team_name(team));
  178.  
  179. if (ownGoal != "") {
  180. stats.get(whoTouchedBall[0].id)[4] += 1;
  181. } else {
  182. stats.get(whoTouchedBall[0].id)[0] += 1;
  183. }
  184.  
  185. if (whoTouchedBall[1] != init && assist != "") stats.get(whoTouchedBall[1].id)[1] += 1;
  186.  
  187.  
  188. if (scorers == undefined) scorers = new Map(); // Initializing dict of scorers
  189. scorers.set(scorers.size + 1 +") " + whoTouchedLast.name, [time, assist, ownGoal])
  190. whoTouchedBall = [init, init];
  191. whoTouchedLast = undefined;
  192. }
  193.  
  194.  
  195.  
  196. room.onTeamVictory = function(scores){ // Sum up all scorers since the beginning of the match.
  197.  
  198. room.sendChat("Scored goals:")
  199. for (var [key, value] of scorers) { // key: name of the player, value: time of the goal
  200. room.sendChat(key + " " + value[1] + value[2] + ": " + value[0]);
  201. }
  202. }
  203.  
  204. room.onGameStop = function(){
  205. scorers = undefined;
  206. whoTouchedBall = [init, init];
  207. whoTouchedLast = undefined;
  208. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement