Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*jshint esversion: 6 */
- /*jslint browser: true */
- /*global window */
- /*global console */
- /*global HBInit */
- var room = HBInit({ roomName: "Nick's Size Pub",
- noPlayer: true, maxPlayers: 10, public: false });
- const MIN_SIZE = 7;
- const MAX_SIZE = 18;
- function errorMessagePM(message, id){
- room.sendAnnouncement("Error: " + message, id, 0xFF0000);
- }
- function updateAdmins() {
- // Get all players
- var players = room.getPlayerList();
- 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 changeOurSize(p, m){
- if (p.team != 0 && !tookASize.hasOwnProperty(p.id)){
- let size = m.substr("!size ".length);
- if (!isNaN(size) && size >= MIN_SIZE && size <= MAX_SIZE){
- room.setPlayerDiscProperties(p.id, {radius: size, invMass: size / 30});
- tookASize[p.id] = size;
- }
- else {
- errorMessagePM("You have to put a size between " +
- MIN_SIZE + " and " + MAX_SIZE, p.id);
- }
- }
- else {
- errorMessagePM("You can only choose a size once per game when playing.", p.id);
- }
- return false;
- }
- function bb(p){
- room.kickPlayer(p.id, "rip !", false);
- return false;
- }
- function helpFun(p){
- room.sendAnnouncement("You can choose the size of your player only once per game by writing !size X in the chat.", p.id, 0x00FF00);
- room.sendAnnouncement("Where X is a number between 7 and 23.", p.id, 0x00FF00);
- room.sendAnnouncement("You can only select one size per game. Your weight also depend on your size", p.id, 0x00FF00);
- return false;
- }
- room.onPlayerJoin = function(p){
- updateAdmins();
- room.sendAnnouncement("Hey " + p.name + " . This is a room " +
- "where the players can choose their size, read !help !", p.id, 0x00AAFF);
- };
- room.onPlayerLeave = function(){
- updateAdmins();
- };
- room.onGameStart = function(){
- tookASize = {};
- };
- room.onPositionsReset = function(){
- let id = Object.keys(tookASize);
- let size;
- for (var i = 0; i < id.length; i++) {
- if (tookASize.hasOwnProperty(id[i])){
- size = tookASize[id[i]];
- room.setPlayerDiscProperties(id[i], {radius: size, invMass: size / 30});
- }
- }
- };
- var commands = {
- "!size": changeOurSize,
- "!help": helpFun,
- "!bb": bb,
- };
- function handleCommands(p, m){
- let spacePos = m.search(" ");
- let command = m.substr(0, spacePos !== -1 ? spacePos : m.length);
- if (commands.hasOwnProperty(command) === true) return commands[command](p, m);
- if (m.startsWith("!") === true) {
- room.sendChat("PM from Host: This is not an existing command, write !help if needed !", p.id);
- return false;
- }
- return true;
- }
- room.onPlayerChat = function(p, m){
- if (handleCommands(p, m) === false) return false;
- };
Advertisement
Add Comment
Please, Sign In to add comment