Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[To-do list:
- • Map rotation; --almost done (no)
- • remove guide message to shaman on divine mode
- • finish round if shaman has left
- • disable skills
- • if mice are won shaman is dead
- • use towers[key].speed
- • voting system to skip map (?) ]]
- --[[ keys
- C 67
- V 86
- B 66
- N 78
- Q 81
- W 87
- E 69
- Ct 17
- H 72 ]]--
- tfm.exec.disableAutoNewGame(true)
- tfm.exec.disableAutoTimeLeft(true)
- tfm.exec.disableAfkDeath(true)
- players={}
- toDesp = {}
- timerList = {}
- towerdefense = {
- version = '<J>Towerdefense <T>BETA_1';
- towers = {
- [67] = {call = 'Cannon Tower'; price = 6; obj = 17};
- [86] = {call = 'Ball Tower'; price = 3; obj = 6};
- [66] = {call = 'Spirit Tower'; price = 3, obj = 24}
- };
- maps = {
- 1387919;
- 1675985;
- 1617965;
- 1565707;
- 1395396;
- 1415547;
- 4932803;
- 2365986;
- };
- coords = {
- -- [''] = {x = ; y = }
- ['@1387919'] = {x = 25; y = 329};
- ['@1675985'] = {x = 27; y = 340};
- ['@1617965'] = {x = 23; y = 340};
- ['@1565707'] = {x = 22; y = 345};
- ['@1395396'] = {x = 23; y = 279};
- ['@1415547'] = {x = 35; y = 328};
- ['@4932803'] = {x = 180; y = 340};
- ['@2365986'] = {x = 40; y = 345};
- };
- Shamankeys = {
- 67, 86, 66, 78, 17, 72
- };
- keys = {
- 17, 72
- };
- messages = {
- chat_welcome = 'Welcome to <J>%s<BL>! Press <J>[H]<BL> for more information!';
- chat_help = 'If you\'re the <CH>shaman<bl> defense the cheese! Press <V>C, V, B<BL> to buy the tower, summon the arrow to place it on the map! Press <V>[Ctrl]<BL> to get more information about towers!\nEvery <V>6 seconds<BL> you\'ll get <V>1 point<BL>!\n\nIf you\'re the <V>mouse<BL> try to get the cheese!';
- chat_towerTab = '<J>Tower Key Price\n<T>Cannon tower <V>C <V>6\n<T>Ball tower <V>B <V>3\n<T>Spirit tower <V>N <V>3';
- chat_lessP = '<R>You haven\'t enough points to buy this tower!';
- chat_Swarning = '<R>You must turn off the divine mode to play this module as the shaman!';
- chat_buy = 'You have bought <T>%s';
- chat_angle = 'Angle: <V>%x°';
- chat_shaman = 'You\'re the <CH>Shaman<BL>! Defense the <J>cheese<BL>! You have <V>10 seconds<BL> to place the towers before 1st wave starts!';
- chat_sWon = '<CH>Shaman<BL> has won!';
- chat_mWon = '<V>Mice<BL> have won!';
- };
- }
- module = {
- INIT = function()
- mice_won = false
- module.newGame()
- end;
- newGame = function()
- tfm.exec.newGame(towerdefense.maps[math.random(#towerdefense.maps)])
- end;
- sendMessage = function(m, name)
- tfm.exec.chatMessage(m, name)
- end;
- buyTower = function(key, name)
- if towerdefense.towers[key] ~= nil then
- local points = players[name].points
- local price = towerdefense.towers[key].price
- if points >= price then
- points = points - price
- players[name] = {points = points, key = towerdefense.towers[key].obj, angle = 0}
- module.sendMessage(string.format(towerdefense.messages.chat_buy, towerdefense.towers[key].call), name)
- ui.updateTextArea(0, "<b><p align = 'center'>Points: "..players[name].points.."</p>", name)
- else
- module.sendMessage(towerdefense.messages.chat_lessP, name)
- end
- end
- end;
- setTower = function(name, x, y, angle)
- local id = players[name].key
- local xS = 50
- local xY = 50
- players[name].timest = os.time()
- if id == 17 and angle == 0 then
- angle = 180;
- elseif id == 17 and angle ~= 0 then
- angle = -angle
- elseif id == 6 then
- xS = 20
- yS = 20
- end
- module.addTimer(function() local object = tfm.exec.addShamanObject(id, x, y, angle, xS, yS) table.insert(toDesp,{os.time(),object}) end, 2500, 1000)
- players[name].key = 0
- end;
- spawnPlayers = function()
- local i = tfm.get.room.currentMap
- if towerdefense.coords[i] ~= nil then
- for name,players in pairs(tfm.get.room.playerList) do
- if not players.isShaman then
- tfm.exec.movePlayer(name, towerdefense.coords[i].x, towerdefense.coords[i].y)
- end
- end
- end
- end;
- respawnPlayers = function()
- local i = tfm.get.room.currentMap
- for name,player in pairs(tfm.get.room.playerList) do
- if not player.isShaman and player.isDead then
- tfm.exec.respawnPlayer(name)
- tfm.exec.movePlayer(name, towerdefense.coords[i].x, towerdefense.coords[i].y)
- end
- end
- end;
- addPoints = function()
- for name,player in pairs(tfm.get.room.playerList) do
- if player.isShaman and started == true then
- players[name].points = players[name].points + 1
- ui.updateTextArea(0, "<b><p align = 'center'>Points: "..players[name].points.."</p>", name)
- end
- end
- end;
- addTimer = function(callback, time, loops, label, ...) -- thanks to Eshkation for help and source
- local id = #timerList + 1
- timerList[id] = {
- callback = callback;
- time = time;
- loops = loops or 1;
- label = label;
- currentTime = 0;
- currentLoop = 0;
- isComplete = false;
- arguments = {...};
- }
- return id
- end;
- removeTimer = function(id)
- if timerList[id] ~= nil then
- timerList[id] = 0
- return true
- end
- return false
- end;
- removeAllTimers = function ()
- timerList = {}
- end;
- }
- eventNewGame = function()
- mice = 0
- n = 0
- seconds = 10
- mice_won = false
- module.removeAllTimers()
- module.addTimer(module.addPoints, 8000, 1000) -- +1 point
- module.addTimer(module.respawnPlayers, 5000, 1000) -- respawn
- tfm.exec.setGameTime(180)
- for k,v in pairs(tfm.get.room.playerList) do
- mice = mice + 1
- end
- print('bind == true')
- for name,player in pairs(tfm.get.room.playerList) do
- if player.isShaman and tfm.get.room.playerList[name].shamanMode ~= 2 then
- module.sendMessage(towerdefense.messages.chat_shaman, name)
- for i,key in ipairs(towerdefense.Shamankeys) do
- system.bindKeyboard(name, key, true, true)
- end
- players[name] = {points = 10, key = 0, timest = os.time()}
- ui.addTextArea(0, "<b><p align = 'center'>Points: "..players[name].points.."</p>", name, -18, 380, 100, 100, 0x324650, 0x0, 0, true)
- elseif player.isShaman and tfm.get.room.playerList[name].shamanMode == 2 then
- module.sendMessage(towerdefense.messages.chat_Swarning)
- tfm.exec.setGameTime(0)
- end
- if not player.isShaman then
- ui.removeTextArea(0)
- players[name] = {}
- for key,s in ipairs(towerdefense.keys) do
- system.bindKeyboard(name, s, true, true)
- end
- end
- end
- end;
- eventNewPlayer = function(name)
- players[name] = {}
- for i,key in ipairs(towerdefense.keys) do
- system.bindKeyboard(name, key, true, true)
- end
- module.sendMessage(string.format(towerdefense.messages.chat_welcome, towerdefense.version), name)
- end;
- eventKeyboard = function(name, keyc, down, x, y)
- if keyc == 17 then
- module.sendMessage(towerdefense.messages.chat_towerTab, name)
- elseif keyc == 72 then
- module.sendMessage(towerdefense.messages.chat_help, name)
- elseif players[name].key == 0 then
- module.buyTower(keyc, name)
- end
- end;
- eventSummoningEnd = function (name, id, x, y, angle)
- if players[name].key ~= 0 then
- module.setTower(name, x, y, angle)
- end
- end;
- function eventPlayerGetCheese (name)
- tfm.exec.playerVictory(name)
- end;
- function eventPlayerWon(name)
- n = n + 1
- i = math.ceil(mice/2)
- module.sendMessage('<V>'..name..' <N>got the cheese! (<V>'..n..'/'..i..'<N>)', nil)
- if n >= i then
- module.sendMessage(towerdefense.messages.chat_mWon, nil)
- tfm.exec.setGameTime(10)
- started = false
- for name,player in pairs(tfm.get.room.playerList) do
- if player.isShaman then
- players[name] = {points = 0, key = 0}
- else
- players[name] = {}
- end
- end
- end
- end;
- function eventLoop(time, rem)
- seconds = seconds - 0.5
- if seconds == 0 then
- module.spawnPlayers()
- end
- if time >= 10000 and started == false then
- started = true
- end
- if rem <= 0 and mice_won == true then
- module.newGame()
- elseif rem <= 0 and mice_won == false then
- module.sendMessage(towerdefense.messages.chat_sWon, nil)
- module.newGame()
- end
- for k,obj in ipairs(toDesp) do
- if obj[1] <= os.time() - 2500 then
- tfm.exec.removeObject(obj[2])
- table.remove(toDesp,k)
- end
- end
- -- timer
- local timersToRemove = {}
- for id = 1, #timerList do
- local timer = timerList[id]
- if type(timer) == 'table' then
- if not timer.isComplete then
- timer.currentTime = timer.currentTime + 500
- if timer.currentTime >= timer.time then
- timer.currentTime = 0
- timer.currentLoop = timer.currentLoop + 1
- if timer.loops > 0 then
- if timer.currentLoop >= timer.loops then
- timer.isComplete = true
- end
- end
- if type(timer.callback) == 'function' then
- timer.callback(timer.currentLoop, table.unpack(timer.arguments))
- end
- end
- end
- if timer.isComplete then
- if type(eventTimerComplete) == 'function' then
- eventTimerComplete(id, timer.label)
- end
- timersToRemove[#timersToRemove+1] = id
- end
- end
- end
- end;
- module.INIT()
Advertisement
Add Comment
Please, Sign In to add comment