Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- #hotcheese
- Developers: Bushmeister and Smgxxx
- Testers: Bushmeister, his alts and Mepers
- Idea: Ikorra
- Thread: http://atelier801.com//topic?f=6&t=389040&p=1#m1
- DEVELOPERS: KEEP THE CODE CLEAN!
- ]]
- Module =
- {
- ["log"] = function (msg) for k, v in pairs(tfm.get.room.playerList) do if (Module.admins[k]~=nil) then tfm.exec.chatMessage("<N2>[Log]: <N>" .. tostring(msg), k); end end end;
- ["init"] = function () for k, v in pairs(tfm.get.room.playerList) do eventNewPlayer(k); end tfm.exec.disableAutoShaman(true); tfm.exec.disableAutoNewGame(true); tfm.exec.disableAutoTimeLeft(true); tfm.exec.disableAfkDeath(true); system.disableChatCommandDisplay("m.addAdmin", true); system.disableChatCommandDisplay("m.addMod", true); system.disableChatCommandDisplay("m.DebugSend", true); system.disableChatCommandDisplay("m.stop", true); system.disableChatCommandDisplay("m.ban", true); system.disableChatCommandDisplay("m.unban", true); system.disableChatCommandDisplay("m", true); system.disableChatCommandDisplay("a", true); system.disableChatCommandDisplay("lang", true); system.disableChatCommandDisplay("l", true); Module.newGame(); end;
- ["startGame"] = function ()
- local count = 0;
- local player;
- local playersTbl = {};
- for k, v in pairs(tfm.get.room.playerList) do
- if not(tfm.get.room.playerList[k].isDead) and not(Player[k].data.isAfk) then
- count = count+1;
- table.insert(playersTbl, k);
- elseif not(tfm.get.room.playerList[k].isDead) then
- tfm.exec.killPlayer(k);
- end
- end
- Module.log("count: " .. count);
- if (count<=1) then
- Module.lastPlayerWithCheese = nil;
- Module.newGame();
- return;
- end
- repeat
- player = playersTbl[math.random(1, #playersTbl)];
- until player~=Module.lastPlayerWithCheese;
- Module.lastTimePlayerThrewCheese = -500;
- Module.lastPlayerWithCheese = player;
- tfm.exec.killPlayer(player);
- system.newTimer(function()
- Message.send('receivedCheese', Player.getPlayerList("exceptPlayers"));
- Message.send('startGame', Player.getPlayerList("exceptPWC"), Module.lastPlayerWithCheese);
- end, 1000, false);
- end;
- ["stop"] = function (adminName) if (Player.isInRoom(adminName)==true and Module.admins[adminName]~=nil) then system.exit() end end;
- ["newGame"] = function () if (Module.lastMapIndex+1>#Maps) then Module.lastMapIndex = 1; else Module.lastMapIndex = Module.lastMapIndex + 1 end Module.log(Module.lastMapIndex) tfm.exec.newGame(Maps[Module.lastMapIndex]); end;
- ["addAdmin"] = function(playerName, adminName) if (Player.isInRoom(playerName)==true and Module.admins[adminName]~=nil) then Module.admins[playerName] = tfm.get.room.playerList[playerName]; Player[playerName].data.isAdmin = true; end end;
- ["addMod"] = function(playerName, adminName) if (Player.isInRoom(playerName)==true and Module.admins[adminName]~=nil) then Module.mods[playerName] = tfm.get.room.playerList[playerName]; Player[playerName].data.isMod = true; end end;
- ["admins"] = {["Bushmeister"] = tfm.get.room.playerList["Bushmeister"], ["Smgxxx"] = tfm.get.room.playerList["Smgxxx"]};
- ["mods"] = {};
- ["timerID"] = nil;
- ["lastPlayerWithCheese"] = nil;
- ["lastTimePlayerThrewCheese"] = 0;
- ["lastSpaceBar"] = 0;
- ["lastMapIndex"] = 1;
- }
- --[[
- MODULE DOCUMENTATION
- Module.init() - инициализирует игру. Биндит клавиши, выключает ненужные функции, скрывает команды.
- Module.startGame() - рандомно выбирает, кто из игроков получит сыр. Эта функция не выберет игрока повторно, если он был последний с сыром в прошлом раунде. Если в комнате 1 мышь - вызовет Module.newGame().
- Module.stop(adminName) - вызывает system.exit(). Необходимо имя администратора, который вызывает эту функцию.
- Module.newGame() - рандомно выбирает какую карту запустить. Эта функция не запустит карту, которая играла в прошлом раунде.
- Module.addAdmin(playerName, adminName) - добавляет игрока в админы. Необходимо имя администратора, который вызывает эту функцию.
- Module.addMod(playerName, adminName) - тоже самое, что и addAdmin, только добавляет игрока в модераторы.
- Message.send(message, messageType, sender) - отправляет сообщение в чат выбранному(выбранным) игроку(игрокам). Для отправки сообщения в чат модераторов/администраторов - необходимо имя модератора(администратора), который вызывает функцию.
- ]]
- Player =
- {
- ["isInRoom"] = function (playerName) return tfm.get.room.playerList[playerName]~=nil end,
- ["hasCheese"] = function (playerName) return tfm.get.room.playerList[playerName].hasCheese end,
- ["x"] = function (playerName) if (tfm.get.room.playerList[playerName]~=nil) then return tfm.get.room.playerList[playerName].x end return false end,
- ["y"] = function (playerName) if (tfm.get.room.playerList[playerName]~=nil) then return tfm.get.room.playerList[playerName].y end return false end;
- ["changeLang"] = function (playerName, lang) if (tfm.get.room.playerList[playerName]~=nil and lang~=nil) then Player[playerName].data.lang = lang end end;
- ["saveData"] = function(playerName) if (Player.isInRoom(playerName)==true and Player[playerName]~=nil) then system.savePlayerData (playerName, Player.ToString(playerName)) end end;
- ["loadData"] = function(playerName) if (Player.isInRoom(playerName)==true and Player[playerName]~=nil) then system.loadPlayerData(playerName) end end;
- ["ToString"] = function(playerName) local dataInText = Player[playerName].data.deaths .. " " .. Player[playerName].data.gaveCheese .. " " .. Player[playerName].data.roundsPlayed .. " " .. Player[playerName].data.scores.. " " .. Player[playerName].data.lang .. " " .. tostring(Player[playerName].data.isAdmin) .. " " .. tostring(Player[playerName].data.isMod) .. " " .. tostring(Player[playerName].data.ban.banType) .. " " .. tostring(Player[playerName].data.ban.unbanTime) .. " " .. tostring(Player[playerName].data.ban.Moderator); return dataInText; end; -- соединяет данные таблицы data в одну строку для дальнейшего сохранения
- ["ToTable"] =
- function(str, playerName)
- local args = {};
- for arg in str:gmatch("%S+") do
- if (arg=="nil") then
- arg = nil;
- end
- if (arg=="true") then
- arg = true;
- end
- if (arg=="false") then
- arg = false;
- end
- table.insert(args, arg);
- end
- Player[playerName].data.deaths = args[1];
- Player[playerName].data.gaveCheese = args[2];
- Player[playerName].data.roundsPlayed = args[3];
- Player[playerName].data.scores = args[4];
- Player[playerName].data.lang = args[5];
- Player[playerName].data.isAdmin = args[6];
- Player[playerName].data.isMod = args[7];
- Player[playerName].data.ban.banType = args[8];
- Player[playerName].data.ban.unbanTime = args[9];
- Player[playerName].data.ban.Moderator = args[10];
- end; -- сортирует данные из одной, целой строки в поля таблицы
- ["checkBan"] =
- function(playerName)
- if (Player[playerName].data.ban.banType=="temp" and Player[playerName].data.ban.unbanTime~=nil) then
- if (os.time()>tonumber(Player[playerName].data.ban.unbanTime)) then
- Player[playerName].data.ban.unbanTime = nil;
- Player[playerName].data.ban.banType = nil;
- tfm.exec.setPlayerScore (playerName, 0);
- else
- tfm.exec.killPlayer(playerName);
- tfm.exec.setPlayerScore (playerName, -360);
- end
- end
- if (Player[playerName].data.ban.banType=="perm") then
- tfm.exec.killPlayer(playerName);
- tfm.exec.setPlayerScore (playerName, -777);
- end
- end; -- будет проверять текущую дату+время и сверяет с unbanTime. Если срок прошел - анбан
- ["getPlayerList"] =
- function (typeList)
- local list = {}
- for k,v in pairs(tfm.get.room.playerList) do
- if (
- (typeList == nil) or
- (typeList == 'exceptPlayers' and Player.hasCheese(k) and not tfm.get.room.playerList[k].isDead) or
- (typeList == 'exceptPWC' and not(Player.hasCheese(k))) or
- (typeList == 'admins' and Module.admins[k] ~= nil) or
- (typeList == 'mods' and (Module.mods[k] ~= nil or Module.admins[k] ~= nil))
- ) then
- table.insert(list, k)
- end
- end
- return list;
- end;
- ["init"] =
- function(playerName)
- Player[playerName] =
- {--только свойства. Все методы доступы сразу из Player.
- ["data"] =
- {
- ["deaths"] = 0; -- смерти
- ["gaveCheese"] = 0; --сколько передано сыра
- ["roundsPlayed"] = 0; -- сыграно раундов
- ["scores"] = 0; -- очки
- ["lang"] = tfm.get.room.playerList[playerName].community; -- язык
- ["isAdmin"] = false;
- ["isMod"] = false;
- ["isAfk"] = true; -- данная переменная не должна сохраняться в saveData, а также не участвует в ToString() ToTable(). Необходима для убийства afk игроков, после того как был выдан сыр рандомом и выбора активного игрока(рандом вас не выберет, если вы не сдвинулись с места)
- ["ban"] =
- {
- ["banType"] = nil; --тип бана. temp или perm
- ["unbanTime"] = nil; --дата и время анбана (UNIX)
- ["Moderator"] = nil; --модератор, выдавший бан
- }
- }
- };
- if (Player[playerName].data.isAdmin==true or Module.admins[playerName]~=nil) then
- Module.admins[playerName] = tfm.get.room.playerList[playerName];
- Player[playerName].data.isAdmin = true;
- end
- if (Player[playerName].data.isMod==true or Module.mods[playerName]~=nil) then
- Module.mods[playerName] = tfm.get.room.playerList[playerName];
- Player[playerName].data.isMod = true;
- end
- Module.log(playerName.."\'s data has been initialized");
- Module.log("Player["..playerName.."].data.isAdmin = " .. tostring(Player[playerName].data.isAdmin));
- Module.log("Player["..playerName.."].data.isMod = " .. tostring(Player[playerName].data.isMod));
- end;
- }
- Maps =
- {
- 4465309,
- 4388974
- }
- Message =
- {
- ["send"] =
- function (messageKey, recipient, ...)
- if recipient == nil then recipient = Player.getPlayerList(); end
- if type(recipient) == 'string' then
- recipient = {recipient}
- end
- local message = '';
- for _,v in pairs(recipient) do
- if Player.isInRoom(v) then
- message = Message.translate(messageKey, Player[v].data.lang)
- message = message:format(...);
- tfm.exec.chatMessage(message, v);
- end
- end
- end;
- ["defaultLang"] = "en";
- ["translate"] = function (key, lang) return (Message[lang] or Message[Message.defaultLang])[key] or Message[Message.defaultLang][key] or key; end;
- ["en"] =
- {
- ["availableCommands"] = "<VI>[#HotCheese]:<T> Available commands: <J>%s";
- ["newPlayer"] = "<VI>[#HotCheese]:<T> Hello %s! Welcome to <VI>#HotCheese<T>! Every round random player receives hot cheese and you have to avoid them. If you catch hot cheese, try to throw it to another mouse as soon as it possible! Press <VI>spacebar<T> to throw cheese.";
- ["endGame"] = "<VI>[#HotCheese]:<T> %s<J> has lost the game T_T";
- ["startGame"] = "<VI>[#HotCheese]:<J> Oh, no! %s has received cheese! Be careful, (s)he'll try to throw hot cheese to you";
- ["receivedCheese"] = "<VI>[#HotCheese]:<J> Hurry up! You have only <T>20<J> seconds to give cheese to another mouse!";
- ["receivedCheeseGlobal"] = "<VI>[#HotCheese]:<J> Run away from <T>%s!<J> (S)he has caught hot cheese!";
- ["addAdmin"] = "<VI>[Module]:<V> Player <VP>%s<V> has been added to the admin group";
- ["addMod"] = "<VI>[Module]:<V>Player <VP>%s<V> has been added to the moderator group";
- ["stop"] = "<VI>[Module]:<VP> Goodbye!";
- ["testAll"] = "<VI>[Module]:<V> Это сообщение должно быть отправлено всем игрокам в комнате";
- ["testExcept"] = "<VI>[Module]:<V> Это сообщение должен был получить игрок с сыром";
- ["testNotExcept"] = "<VI>[Module]:<V> Это сообщение должно быть отправлено всем игрокам без сыра";
- ["testMods"] = "<VI>[Module]:<V> Это сообщение должно быть отправлено всем модераторам и администраторам";
- ["testAdmins"] = "<VI>[Module]:<V> Это сообщение должно быть отправлено всем администраторам";
- ["chatA"] = "<R>[Admins]<T> [%s]:<R> %s";
- ["chatM"] = "<ROSE>[Mods]<T> [%s]:<ROSE> %s";
- };
- ["ru"] =
- {
- ["newPlayer"] = "Привет %s! Добро пожаловать в мини-игру #HotCheese! Каждый раунд случайному игроку будет выдан горячий сыр, Вы должные избегать его(её)! Если Вы получили/поймали горячий сыр, постарайтесь как можно скорее передать его другой мышке. Используйте пробел, чтобы бросить сыр.";
- ["endGame"] = "<VI>[#HotCheese]:<T> %s<J> проиграл T_T";
- ["startGame"] = "<VI>[#HotCheese]:<J> О нет! <T>%s<J> получил(а) горячий сыр! Будьте осторожны, он(а) попытается бросить его вам!";
- ["receivedCheese"] = "<VI>[#HotCheese]:<J> Поторопись! У тебя есть только <T>20<J> секунд чтобы передать сыр!";
- ["receivedCheeseGlobal"] = "<VI>[#HotCheese]:<J> Убегайте от <T>%s!<J> У него горячий сыр!";
- ["addAdmin"] = "<VI>[Module]:<V>Игрок <VP>%s<V> стал администратором";
- ["addMod"] = "<VI>[Module]:<V>Игрок <VP>%s<V> стал модератором";
- ["stop"] = "<VI>[Module]:<VP> ^-^ bye-bye";
- };
- ["tr"] =
- {
- ["newPlayer"] = "<VI>[#HotCheese]:<T> Merhaba %s! <VI>#HotCheese<T>! odasına hoş geldin! Her oyuncu rastgele bir peynir alır, sizin bunlardan kaçmanız gerekiyor. En kısa sürede peyniri yakalayın ve diğer farelere vermeye çalışın! Peyniri vermek için <VI>Boşluk<T> tuşuna basın.";
- ["endGame"] = "<VI>[#HotCheese]:<T> %s<J> Oyunu kaybetti T_T ";
- ["startGame"] = "<VI>[#HotCheese]:<J> Ah, hayır! %s seçildi! Dikkat et, o sana peyniri vermeye çalışacak";
- ["receivedCheese"] = "<VI>[#HotCheese]:<J> Çabuk ol! Peyniri başka bir fareye vermek için sadece <T>20<J> saniyen var!";
- ["receivedCheeseGlobal"] = "<VI>[#HotCheese]:<J> <T>%s!<J> kişisinden kaç! Çünkü bu peyniri sana verirse oyunu kaybedersin. ";
- ["stop"] = "<VI>[Module]:<VP> ^-^ bye-bye";
- };
- }
- function eventPlayerDataLoaded(playerName,data)
- if (data~="#") then
- Player.ToTable(data, playerName);
- end
- end
- function eventNewPlayer(playerName)
- if (Player[playerName]==nil) then
- Player.init(playerName)
- end
- Message.send('newPlayer', playerName, playerName);
- local Buttons = {32, 37, 38, 39, 40, 65, 68, 83, 87};
- for i, v in ipairs(Buttons) do
- tfm.exec.bindKeyboard(playerName, v, true, true);
- end
- end
- function eventPlayerLeft(playerName)
- --Player[playerName] = nil;
- --Module.admins[playerName] = nil;
- --Module.mods[playerName] = nil;
- --tfm.exec.bindKeyboard(playerName, 32, true, false);
- end
- function eventNewGame()
- for k, v in pairs(tfm.get.room.playerList) do
- Player.checkBan(k);
- Player[k].data.isAfk = true;
- Player[k].data.roundsPlayed=Player[k].data.roundsPlayed+1;
- end
- if (Module.timerID~=nil) then
- --[[
- Необходимо т.к если в комнате один игрок и он умирает в первые 9 секунд
- (когда таймер начал работать) таймер остается рабочим и запускается
- в новом раунде раньше времени, а также создается новый таймер на 10сек.
- ♥while(true)♥
- ]]
- system.removeTimer(Module.timerID);
- Module.timerID=nil;
- end
- Module.lastTimePlayerThrewCheese = -10000;
- tfm.exec.setGameTime(130);
- Module.timerID = system.newTimer(function() Module.timerID = nil; Module.startGame(); end, 10000, false)
- end
- function eventPlayerDied(playerName)
- if (Player[playerName]~=nil) then
- Player[playerName].data.deaths = Player[playerName].data.deaths+1;
- else
- Module.log(playerName.."\'s data wasn't initialized")
- Player.init(playerName);
- end
- if (playerName~=Module.lastPlayerWithCheese) then
- local playersAlive = 0;
- for k, v in pairs(tfm.get.room.playerList) do
- if (tfm.get.room.playerList[k].isDead~=true) then
- playersAlive = playersAlive + 1;
- end
- end
- if (playersAlive<=1) then
- Module.newGame();
- end
- end
- if (playerName==Module.lastPlayerWithCheese) then
- if (Module.lastTimePlayerThrewCheese<20000 and Player[playerName].data.ban.banType==nil) then
- tfm.exec.setPlayerScore(playerName, -1, true); tfm.exec.respawnPlayer(playerName); tfm.exec.giveCheese(playerName);
- else
- Message.send('endGame', nil, playerName);
- Module.startGame();
- end
- end
- end
- function eventLoop(currentTime, timeRemaining)
- Module.lastSpaceBar = Module.lastSpaceBar-500;
- Module.lastTimePlayerThrewCheese = Module.lastTimePlayerThrewCheese+500; --счетчики времени последней передачи сыра и последнего нажатия пробела
- if (Module.lastTimePlayerThrewCheese>=20000) then
- tfm.exec.killPlayer(Module.lastPlayerWithCheese);
- end
- if (timeRemaining<=500) then
- Module.newGame();
- end
- end
- function eventKeyboard(playerName, keyCode, down, xPlayerPosition, yPlayerPosition)
- local Buttons = {37, 38, 39, 40, 65, 68, 83, 87};
- if Player[playerName].data.isAfk==true then
- for _, v in pairs(Buttons) do
- if keyCode==v then
- Player[playerName].data.isAfk = false;
- break;
- end
- end
- end
- if (Player.hasCheese(playerName)) then
- local playerNameWhoCaughtCheese = nil;
- if (keyCode==32 and Module.lastSpaceBar<=0) then--антиспам пробелом
- Module.lastSpaceBar = 500;
- for k, v in pairs(tfm.get.room.playerList) do
- if math.pow((Player.x(k)-xPlayerPosition), 2)+math.pow((Player.y(k)-yPlayerPosition), 2)<900 and k~=playerName then
- playerNameWhoCaughtCheese=k;
- break;
- end
- end
- if (playerNameWhoCaughtCheese~=nil) then
- Module.lastSpaceBar = 3000;
- Module.lastTimePlayerThrewCheese = -500;
- Module.lastPlayerWithCheese=playerNameWhoCaughtCheese;
- tfm.exec.giveCheese(playerNameWhoCaughtCheese);
- tfm.exec.playerVictory(playerName);
- tfm.exec.respawnPlayer(playerName);
- Player[playerName].data.gaveCheese = Player[playerName].data.gaveCheese+1;
- Player[playerName].data.scores = Player[playerName].data.scores+1;
- system.newTimer(function() Message.send('receivedCheeseGlobal', Player.getPlayerList("exceptPWC"), playerNameWhoCaughtCheese); Message.send('receivedCheese', Player.getPlayerList("exceptPlayers")); end, 1500, false);
- end
- end
- end
- end
- function eventChatCommand(playerName, message)
- if (Module.admins[playerName]~=nil) then
- --commands for admins
- if (message:sub(0,11)=="m.addAdmin " and message:len()>=12) then
- Module.addAdmin(message:sub(12), playerName);
- Message.send('addAdmin', playerName, message:sub(12));
- end
- if (message:sub(0,9)=="m.addMod " and message:len()>=10) then
- Module.addMod(message:sub(10), playerName)
- Message.send('addMod', playerName, message:sub(10));
- end
- if (message:sub(0,6)=="m.stop") then
- Message.send('stop');
- system.newTimer(function () Module.stop(playerName) end, 1000, false);
- end
- if (message:sub(0, 8)=="m.unban " and message:len()>9) then
- if (Player.isInRoom(message:sub(9))==true) then
- local pName = message:sub(9);
- Player[pName].data.ban.banType = nil;
- Player[pName].data.ban.unbanTime = nil;
- tfm.exec.setPlayerScore (pName, 0);
- end
- end
- if (message:sub(0,10)=="m.DebugPD " and message:len()>10) then
- if (Player.isInRoom(message:sub(11))) then
- tfm.exec.chatMessage("<R>"..Player.ToString(message:sub(11)));
- end
- end
- if (message=="m.DebugSend") then
- Message.send('testAll');
- Message.send('testExcept', Player.getPlayerList("exceptPlayers"));
- Message.send('testNotExcept', Player.getPlayerList("exceptPWC"));
- Message.send('testMods', Player.getPlayerList("mods"));
- Message.send('testAdmins', Player.getPlayerList("admins"));
- end
- if (message:sub(0,2)=="a " and message:len()>=3) then
- Message.send('chatA', Player.getPlayerList("admins"), playerName, message:sub(3));
- end
- end
- if (Module.admins[playerName]~=nil or Module.mods[playerName]~=nil) then
- if (message:sub(0,2)=="m " and message:len()>=3) then
- Message.send('chatM', Player.getPlayerList("mods"), playerName, message:sub(3));
- end
- if (message:sub(0,6)=="m.ban " and message:len()>9) then--check if temp or perm isnt null
- --!m.ban name type time
- local msgArgs = {}
- for arg in message:gmatch("%S+") do
- table.insert(msgArgs, arg);
- print(arg)
- end
- local pName = msgArgs[2];
- local bType = msgArgs[3];
- local bTime = nil
- if (bType~=nil and bType~="perm") then
- bTime = tonumber(msgArgs[4]);
- end
- if (Player[pName]~=nil) then
- if (bType~=nil) then
- if (bType=="perm" and Module.admins[playerName]~=nil) then
- Player[pName].data.ban.banType = "perm";
- Player[pName].data.ban.unbanTime = nil;
- Player[pName].data.ban.Moderator = playerName;
- tfm.exec.killPlayer(pName);
- tfm.exec.setPlayerScore (pName, -777);
- elseif (Module.admins[playerName]==nil) then
- tfm.exec.chatMessage("<VI>[Module]:<R> You don't have enough rights to do this action")
- end
- if (bType=="temp" and bTime~=nil and Player[pName].data.ban.banType==nil) then
- Player[pName].data.ban.banType = "temp";
- Player[pName].data.ban.unbanTime = os.time() + bTime*60*60*1000;
- Player[pName].data.ban.Moderator = playerName;
- tfm.exec.chatMessage(os.time().. " " .. Player[pName].data.ban.unbanTime)
- tfm.exec.killPlayer(pName);
- tfm.exec.setPlayerScore (pName, -777);
- end
- end
- end
- end
- end
- if (message:sub(0,5)=="lang " or message:sub(0,2)=="l ") then
- Player.changeLang(playerName, (message:sub(0,2)=="l " and message:sub(3,4)) or message:sub(6,7) )
- end
- end
- Module.init();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement