nick191821971782

Untitled

Feb 7th, 2020
330
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.08 KB | None | 0 0
  1. /*jshint esversion: 6 */
  2. /*jslint browser: true */
  3. /*global window */
  4. /*global console */
  5. /*global HBInit */
  6.  
  7.  
  8. var room = HBInit({ roomName: "Nick's Size Pub",
  9. noPlayer: true, maxPlayers: 10, public: false });
  10.  
  11. const MIN_SIZE = 7;
  12. const MAX_SIZE = 18;
  13.  
  14. function errorMessagePM(message, id){
  15. room.sendAnnouncement("Error: " + message, id, 0xFF0000);
  16. }
  17.  
  18. function updateAdmins() {
  19. // Get all players
  20. var players = room.getPlayerList();
  21. if ( players.length == 0 ) return; // No players left, do nothing.
  22. if ( players.find((player) => player.admin) != null ) return; // There's an admin left so do nothing.
  23. room.setPlayerAdmin(players[0].id, true); // Give admin to the first non admin player in the list
  24. }
  25.  
  26. function changeOurSize(p, m){
  27. if (p.team != 0 && !tookASize.hasOwnProperty(p.id)){
  28. let size = m.substr("!size ".length);
  29. if (!isNaN(size) && size >= MIN_SIZE && size <= MAX_SIZE){
  30. room.setPlayerDiscProperties(p.id, {radius: size, invMass: size / 30});
  31. tookASize[p.id] = size;
  32. }
  33. else {
  34. errorMessagePM("You have to put a size between " +
  35. MIN_SIZE + " and " + MAX_SIZE, p.id);
  36. }
  37. }
  38. else {
  39. errorMessagePM("You can only choose a size once per game when playing.", p.id);
  40. }
  41. return false;
  42. }
  43.  
  44. function bb(p){
  45. room.kickPlayer(p.id, "rip !", false);
  46. return false;
  47. }
  48.  
  49. function helpFun(p){
  50. room.sendAnnouncement("You can choose the size of your player only once per game by writing !size X in the chat.", p.id, 0x00FF00);
  51. room.sendAnnouncement("Where X is a number between 7 and 23.", p.id, 0x00FF00);
  52. room.sendAnnouncement("You can only select one size per game. Your weight also depend on your size", p.id, 0x00FF00);
  53. return false;
  54. }
  55.  
  56.  
  57.  
  58.  
  59. room.onPlayerJoin = function(p){
  60. updateAdmins();
  61. room.sendAnnouncement("Hey " + p.name + " . This is a room " +
  62. "where the players can choose their size, read !help !", p.id, 0x00AAFF);
  63. };
  64.  
  65. room.onPlayerLeave = function(){
  66. updateAdmins();
  67. };
  68.  
  69.  
  70. room.onGameStart = function(){
  71. tookASize = {};
  72. };
  73.  
  74.  
  75. room.onPositionsReset = function(){
  76. let id = Object.keys(tookASize);
  77. let size;
  78. for (var i = 0; i < id.length; i++) {
  79. if (tookASize.hasOwnProperty(id[i])){
  80. size = tookASize[id[i]];
  81. room.setPlayerDiscProperties(id[i], {radius: size, invMass: size / 30});
  82. }
  83. }
  84. };
  85.  
  86.  
  87.  
  88. var commands = {
  89. "!size": changeOurSize,
  90. "!help": helpFun,
  91. "!bb": bb,
  92. };
  93.  
  94.  
  95. function handleCommands(p, m){
  96. let spacePos = m.search(" ");
  97. let command = m.substr(0, spacePos !== -1 ? spacePos : m.length);
  98. if (commands.hasOwnProperty(command) === true) return commands[command](p, m);
  99. if (m.startsWith("!") === true) {
  100. room.sendChat("PM from Host: This is not an existing command, write !help if needed !", p.id);
  101. return false;
  102. }
  103. return true;
  104. }
  105.  
  106.  
  107. room.onPlayerChat = function(p, m){
  108. if (handleCommands(p, m) === false) return false;
  109.  
  110. };
Advertisement
Add Comment
Please, Sign In to add comment