Advertisement
Guest User

Manacer search : Tribewar

a guest
Sep 26th, 2013
191
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 30.98 KB | None | 0 0
  1. TribewarModule = {}
  2. TribewarModule.new = function(maplist)
  3.  
  4. local maplist = maplist or { "#0", "#1", "#1", "#1", "#7", "#17" }
  5.  
  6. local self = {}
  7.  
  8. --
  9. local tempsettings =
  10. {
  11. firstPoints = 3,
  12. secondPoints = 2,
  13. thirdPoints = 1,
  14. rounds = 8,
  15. timeSkip = 20,
  16. users = {
  17. normal = {
  18. power = 1,
  19. users = {},
  20. commands = {
  21. help = "This help",
  22. tribelist = "Shows the 5 best tribes",
  23. mort = "Kill yourself",
  24. tlist = "Shows the players in your tribe"
  25. }
  26. },
  27. watcher = {
  28. power = 2,
  29. users = {},
  30. commands = {
  31. pause = "There won't be any points in this round",
  32. unpause = "There will be points again",
  33. liststaff = "List the TWstaff"
  34. }
  35. },
  36. referee = {
  37. power = 3,
  38. users = {},
  39. commands = {
  40. npp = "Enqueues a map",
  41. ban = "Bans a player",
  42. unban = "Unbans a player",
  43. showbans="Shows bans"
  44. }
  45. },
  46. manager = {
  47. power = 4,
  48. users = {},
  49. commands = {
  50. addwatcher = "Makes a person a watcher",
  51. addreferee = "Makes a person a referee",
  52. removestaff = "Removes a referee/watcher",
  53. }
  54. },
  55. admin = {
  56. power = 5,
  57. users = { Manacer = {}, Whoms = {}, },
  58. commands = {
  59. addmanager = "Makes a person a manager",
  60. }
  61. }
  62. }
  63. }
  64. --
  65.  
  66.  
  67. local currentRound = {}
  68. local roundnumber = 0
  69.  
  70. local botname = "Moeplluaalt"
  71. local orderName = "![order] "
  72. local requestTribe = "[requestTribe]"
  73. local answerTribe = "[responseTribe]"
  74.  
  75. local showhelp = "help"
  76. local mortcmd = "mort"
  77. local showTribes = "tribelist"
  78. local tlist = "tlist"
  79.  
  80.  
  81. local playernamecolor = "#009D9D"
  82. local pointscolor = "#98E2EB"
  83.  
  84.  
  85. local addedPoints = "%s scored %s points for %s!"
  86. local resultsOfRound = "Results of round %s:\n%s"
  87. local wonTheWar = "<V>Congratulations,\n %s won the war!"
  88.  
  89. local tfmMod = tfmMoeplModule.new("tribewar")
  90.  
  91.  
  92. local settings = savedData["games"][tfmMod.getName()]["settings"] or tempsettings
  93.  
  94. --[[
  95. settings.users.admin.commands["addmanager"] = "Makes a person a manager"
  96. settings.users.referee.commands["ban"] = "Bans a player"
  97. settings.users.referee.commands["unban"] = "Unbans a player"
  98. settings.users.referee.commands["showbans"] = "Shows bans"
  99. --]]
  100.  
  101.  
  102. local commander = commandHandler.new(false, tfmMod)
  103. local queuedAMapAlready = false
  104. local refmap
  105.  
  106. local tribeWarMapQueue = mapUtils.new(maplist)
  107. local commandsWithCommand = {}
  108. local commands = {}
  109. commands[orderName:sub(2, orderName:len() - 1)] = 99
  110. for _, users in pairs(settings.users) do
  111. for command, _ in pairs(users.commands) do
  112. commands[command] = users.power
  113. commandsWithCommand[command] = command
  114. end
  115. end
  116. for v, _ in pairs(commands) do
  117. system.disableChatCommandDisplay(v, true)
  118. end
  119.  
  120. local buildhelp = function(power)
  121. local power = power or 1
  122. local output = {}
  123. local commands = {}
  124.  
  125. for status, users in pairs(settings.users) do
  126. if (users.power <= power) then
  127. for i, v in pairs(users.commands) do
  128. table.insert(commands, { name = i, description = v, userstatus = status, power = users.power })
  129. end
  130. end
  131. end
  132.  
  133. table.sort(commands, function(a, b)
  134. return a.power < b.power
  135. end)
  136.  
  137. table.insert(output, { "Command", "status", "description" })
  138. for i, v in pairs(commands) do
  139. table.insert(output, { "!" .. tostring(v.name), v.userstatus, v.description })
  140. end
  141. return string.monoSpaceTransform(table.getSpaceIdentedString(output));
  142. end
  143.  
  144. local helpmsguser = buildhelp()
  145. local helpmsgwatcher = buildhelp(2)
  146. local helpmsgreferee = buildhelp(3)
  147. local helpmsgmanager = buildhelp(4)
  148. local helpmsgadmin = buildhelp(5)
  149.  
  150.  
  151.  
  152. local Tribes = {}
  153. local SortedTribes = {}
  154. local TribePlayers = {}
  155. local Referees = {}
  156. local playerBans = {}
  157.  
  158.  
  159. Tribe = {}
  160. Tribe.new = function(tribeName)
  161. local function num2hex(num)
  162. local hexstr = '0123456789abcdef'
  163. local s = ''
  164. while num > 0 do
  165. local mod = math.fmod(num, 16)
  166. s = string.sub(hexstr, mod + 1, mod + 1) .. s
  167. num = math.floor(num / 16)
  168. end
  169. if s == '' then s = '0' end
  170. return s
  171. end
  172.  
  173.  
  174.  
  175. local tribeName = tribeName
  176. local tribe = {}
  177. local tribePlayers = {}
  178. local sortedPlayers = {}
  179. local points = 0
  180. local tribeintcolor = 0
  181. local tribecolor = "";
  182. tribe.calculateColors = function()
  183.  
  184. local br = tonumber("32", 10)
  185. local bg = tonumber("46", 10)
  186. local bb = tonumber("50", 10)
  187.  
  188. tribeintcolor = math.random(1, 16777215)
  189. tribecolor = "#" .. num2hex(tribeintcolor);
  190. local difference = 1
  191.  
  192. for i = 2, 6, 2 do
  193. local str = tribecolor:sub(i, i + 1) .. ""
  194. local color = tonumber(str, 16) or 1
  195. local checkcolor = 0
  196. if i == 2 then
  197. checkcolor = br
  198. elseif i == 4 then
  199. checkcolor = bg
  200. elseif i == 6 then
  201. checkcolor = bb
  202. end
  203. local addnr = tonumber((math.max(checkcolor, color) - math.min(checkcolor, color))) or 1
  204. difference = difference * addnr
  205. end
  206. if difference < 400000 then tribe.calculateColors() end
  207. end
  208. tribe.calculateColors()
  209.  
  210. tribe.getColor = function() return tribecolor end
  211. tribe.getColorInt = function() return tribeintcolor end
  212. tribe.getPlayers = function() return tribePlayers end
  213. tribe.getBestPlayer = function()
  214. return sortedPlayers[1] or TribewarPlayer.new("Nobody")
  215. end
  216. tribe.getPlayerList = function()
  217. local output = {}
  218. table.insert(output, { "Name", "Points" })
  219. local iteratedtribes = 0;
  220. for i, v in pairs(sortedPlayers) do
  221. table.insert(output, { string.format("%s", string.tagColor(v.getName(), playernamecolor)), v.getPoints() })
  222. end
  223. return string.monoSpaceTransform(table.getSpaceIdentedString(output));
  224. end
  225.  
  226. tribe.getName = function() return tribeName end
  227. tribe.getPoints = function() return points end
  228. tribe.sortPlayers = function()
  229.  
  230. table.sort(sortedPlayers, function(a, b) return a.getPoints() > b.getPoints() end)
  231. end
  232. tribe.addPoints = function(playerName, pts) points = points + pts
  233. tribe.sortPlayers()
  234. self.gameMessage(addedPoints:format(string.tagColor(playerName, playernamecolor), string.tagColor(pts, pointscolor), string.tagColor(tribeName, tribecolor)))
  235. end
  236. tribe.addPlayer = function(tribeplayer) tribePlayers[tribeplayer.getName()] = tribeplayer
  237. table.insert(sortedPlayers, tribeplayer)
  238. tribe.sortPlayers()
  239. end
  240. tribe.removePlayer = function(playerName)
  241. local ind = table.getIndexOf(sortedPlayers, tribePlayers[playerName])
  242. if (ind) then
  243. table.remove(sortedPlayers, ind)
  244. end
  245. tribePlayers[playerName] = nil
  246. end
  247. tribe.reset = function() points = 0 end
  248.  
  249. return tribe
  250. end
  251.  
  252.  
  253. TribewarPlayer = {}
  254. TribewarPlayer.new = function(name)
  255. local player = {}
  256. local name = name
  257. local points = 0
  258. local tribe
  259.  
  260. player.getName = function() return name end
  261. player.getPoints = function() return points end
  262. player.getTribe = function() return tribe end
  263. player.setTribe = function(tribeName)
  264. if (tribe ~= nil) then
  265. tribe.removePlayer(name)
  266. end
  267. local curTribe = Tribes[tribeName]
  268. if curTribe == nil then
  269. curTribe = Tribe.new(tribeName)
  270. self.addTribe(curTribe)
  271. end
  272.  
  273. curTribe.addPlayer(player)
  274.  
  275. xplayer.setNameColor(name, curTribe.getColorInt())
  276.  
  277.  
  278. tribe = curTribe
  279. end
  280.  
  281.  
  282. player.addPoints = function(pts)
  283. points = points + pts
  284. if tribe then
  285. tribe.addPoints(name, pts)
  286. end
  287. end
  288. player.leave = function()
  289. if (tribe ~= nil) then
  290. tribe.removePlayer(name)
  291. end
  292. TribePlayers[name] = nil
  293. end
  294. player.reset = function()
  295. points = 0
  296. end
  297.  
  298.  
  299. return player
  300. end
  301.  
  302. Referee = {}
  303. Referee.new = function(name, power, createdDate, promotedBy, mainacc)
  304.  
  305. local refself = {}
  306. local createdDate = createdDate or os.time()
  307. local promotedBy = promotedBy or "Admin"
  308. local mainacc = mainacc or true
  309. local name = name
  310. local power = power
  311.  
  312. local pauseCmd = function(msg)
  313. currentRound.setPause(true, msg, name)
  314. end
  315. local unpauseCmd = function(msg)
  316. currentRound.setPause(false, msg, name)
  317. end
  318. local addRef = function(ref, power)
  319. if ref:len() < 2 then
  320. xplayer.chatMessage("<R>Error", name)
  321. return
  322. end
  323.  
  324. ref = string.lower(ref)
  325. ref = string.trim(string.upper(string.sub(ref, 0, 1)) .. string.sub(ref, 2))
  326. local newref = Referees[ref] or Referee.new(ref, power, os.time(), name, true)
  327. if (newref.getPower() >= refself.getPower()) then --prevents managers from changing the rank of others managers
  328. xplayer.chatMessage("<R>This is not allowed!", name)
  329. else
  330. newref.setPower(power)
  331. Referees[ref] = newref
  332. xplayer.chatMessage(string.format("<R>Added \"%s\"", ref), name)
  333. self.rebuildStaffTable()
  334. end
  335. end
  336. local removeRef = function(ref)
  337. ref = string.lower(ref)
  338. ref = string.upper(string.sub(ref, 0, 1)) .. string.sub(ref, 2)
  339. local toRemoveRef = Referees[ref]
  340. if not toRemoveRef then
  341. xplayer.chatMessage("<R>" .. string.format("%s not found", ref), name)
  342. return
  343. end
  344. if toRemoveRef.getPower() < refself.getPower() then
  345. Referees[ref] = nil
  346. xplayer.chatMessage(string.format("<R>%s removed", ref), name)
  347. self.rebuildStaffTable()
  348. end
  349. end
  350. local listStaff = function()
  351. local output = ""
  352. for rankName, tbl in pairs(settings.users) do
  353. if (tbl.power > 1) then
  354. local output = string.upper(rankName) .. "\n"
  355. for staff, value in pairs(tbl.users) do
  356. output = output .. staff .. "\n"
  357. end
  358. xplayer.chatMessage(output, name)
  359. end
  360. end
  361. end
  362.  
  363. local mapEnqueue = function(msg)
  364. local strd = msg:gsub("[^%d+]", "")
  365. local number = tonumber(strd)
  366.  
  367. if number then refmap = number
  368. xplayer.chatMessage(string.format("Enqueued %s", number), name)
  369. else
  370. xplayer.chatMessage("Faulty input: " .. msg, name)
  371. end
  372. end
  373.  
  374. local banunban = function(playerName, ban)
  375. if playerName:len() > 2 then
  376. playerName = playerName:lower()
  377. playerName = string.upper(string.sub(playerName, 0, 1)) .. string.sub(playerName, 2)
  378. ban = ban or false
  379. if ban == true then
  380. playerBans[playerName] = refself
  381. xplayer.chatMessage(string.format("Banned \"%s\"!", playerName), name)
  382. xplayer.chatMessage(string.format("You can't spawn anymore."),playerName)
  383. xplayer.killPlayer(playerName)
  384. else
  385. if (playerBans[playerName]) then
  386. playerBans[playerName] = nil
  387. xplayer.chatMessage(string.format("Unbanned \"%s\".", playerName), name)
  388. else
  389. xplayer.chatMessage(string.format("\"%s\" wasn't banned.", playerName), name)
  390. end
  391. end
  392. end
  393. end
  394.  
  395. local showbans = function()
  396. local output = {}
  397. table.insert(output, { "Name", "Referee" })
  398. for i, v in pairs(playerBans) do
  399. table.insert(output, { i, v.getName() })
  400. end
  401. xplayer.chatMessage(string.monoSpaceTransform(table.getSpaceIdentedString(output)),name)
  402. end
  403.  
  404. refself.commandHandle = function(cmd, msg, extraparas)
  405. if commands[cmd] and commands[cmd] <= power then
  406. if cmd == commandsWithCommand["pause"] then
  407. pauseCmd(msg)
  408. elseif cmd == commandsWithCommand["unpause"] then
  409. unpauseCmd(msg)
  410. elseif cmd == commandsWithCommand["liststaff"] then
  411. listStaff()
  412. elseif cmd == commandsWithCommand["addwatcher"] then
  413. addRef(msg, settings.users.watcher.power)
  414. elseif cmd == commandsWithCommand["addreferee"] then
  415. addRef(msg, settings.users.referee.power)
  416. elseif cmd == commandsWithCommand["removestaff"] then
  417. removeRef(msg)
  418. elseif cmd == commandsWithCommand["npp"] then
  419. mapEnqueue(msg)
  420. elseif cmd == commandsWithCommand["ban"] then
  421. banunban(msg, true)
  422. elseif cmd == commandsWithCommand["unban"] then
  423. banunban(msg, false)
  424. elseif cmd == commandsWithCommand["showbans"] then
  425. showbans()
  426. elseif cmd == commandsWithCommand["addmanager"] then
  427. addRef(msg, settings.users.manager.power)
  428. end
  429. end
  430. end
  431. refself.getName = function() return name end
  432. refself.getPromotedBy = function() return promotedBy end
  433. refself.getMainAcc = function() return mainacc end
  434. refself.getCreatedDate = function() return createdDate end
  435. refself.getPower = function() return power end
  436. refself.setPower = function(pw) power = pw end
  437. return refself;
  438. end
  439.  
  440. for _, users in pairs(settings.users) do
  441. if (users.power > 1) then
  442. for i, v in pairs(users.users) do
  443. Referees[i] = Referee.new(i, users.power, v.createdDate, v.promotedBy, v.mainacc)
  444. end
  445. end
  446. end
  447.  
  448. commander.addCommand("", 1, function(playerName, msg, cmd)
  449. if (Referees[playerName]) then
  450. Referees[playerName].commandHandle(cmd:lower(), msg)
  451. end
  452. end)
  453.  
  454. local RoundInfo = {}
  455. RoundInfo.new = function(roundnr)
  456.  
  457.  
  458. local round = {}
  459. local roundnr = roundnr
  460.  
  461. local ranklist = {}
  462. local paused = false
  463.  
  464. local gotpoints
  465.  
  466.  
  467.  
  468.  
  469. round.isPaused = function() return paused end
  470. round.togglePause = function(msg, playerName) round.setPause(not paused, msg, playerName) end
  471. round.setPause = function(p, msg, playerName)
  472. if p ~= paused then
  473. paused = p
  474. if paused == true then
  475. self.gameMessage(string.format("<R>Pause! (%s):<J> %s", string.tagColor("Referee " .. playerName, playernamecolor), msg))
  476. roundnumber = roundnumber - 1
  477. elseif paused == false then
  478. self.gameMessage(string.format("<R>UnPause! (%s):<J> %s", string.tagColor("Referee " .. playerName, playernamecolor), msg))
  479. roundnumber = roundnumber + 1
  480. end
  481. local nr = 1
  482. local mult = 1
  483. if paused == true then mult = -1 end
  484. for i, tpl in pairs(ranklist) do
  485. if (nr == 4) then break end
  486. if nr == 1 then
  487. tpl.addPoints(settings.firstPoints * mult)
  488. elseif nr == 2 then
  489. tpl.addPoints(settings.secondPoints * mult)
  490. elseif nr == 3 then
  491. tpl.addPoints(settings.thirdPoints * mult)
  492. end
  493. nr = nr + 1
  494. end
  495. self.sortTribes()
  496. end
  497. end
  498. round.playerScore = function(playerName)
  499.  
  500. if #ranklist <= 3 then
  501. self.getTribeNames(playerName)
  502. end
  503.  
  504. local tpl = TribePlayers[playerName]
  505. if tpl ~= nil then
  506. table.insert(ranklist, tpl)
  507. if round.isPaused() == true then return end
  508. if #ranklist == 1 then
  509. tpl.addPoints(settings.firstPoints)
  510. self.sortTribes()
  511. elseif #ranklist == 2 then
  512. tpl.addPoints(settings.secondPoints)
  513. self.sortTribes()
  514. elseif #ranklist == 3 then
  515. tpl.addPoints(settings.thirdPoints)
  516. self.sortTribes()
  517. end
  518. end
  519. end
  520. round.getRound = function() return roundnr end
  521. round.playersEntered = function() return #ranklist end
  522.  
  523. return round
  524. end
  525.  
  526. tfmMod.addMap = function(map)
  527. tribeWarMapQueue.addMap(map)
  528. end
  529. tfmMod.removeMap = function(map)
  530. return tribeWarMapQueue.removeMap(map)
  531. end
  532. tfmMod.showMaps = function()
  533. local sortedmaps = tribeWarMapQueue.getMaps()
  534. table.sort(sortedmaps)
  535. return table.concat(sortedmaps, " ")
  536. end
  537. tfmMod.getMaps = function()
  538. return tribeWarMapQueue.getMaps()
  539. end
  540. self.sortTribes = function()
  541. table.sort(SortedTribes, function(a, b) return a.getPoints() > b.getPoints() end)
  542. end
  543. self.addTribe = function(tribe)
  544. Tribes[tribe.getName()] = tribe
  545. table.insert(SortedTribes, tribe)
  546. end
  547. self.removeTribe = function(tribe)
  548. Tribes[tribe.getName()] = nil
  549.  
  550. local index = table.getIndexOf(SortedTribes, tribe)
  551. if index then
  552. table.remove(SortedTribes, index)
  553. end
  554. end
  555. self.rebuildStaffTable = function()
  556. local staffRank = {}
  557. for staffname, staffpos in pairs(settings.users) do
  558. staffpos.users = {}
  559. staffRank[staffpos.power] = staffname
  560. end
  561.  
  562.  
  563.  
  564. for i, v in pairs(Referees) do
  565. local pw = v.getPower()
  566. settings.users[staffRank[pw]].users[v.getName()] = { createdDate = v.getCreatedDate(), promotedBy = v.getPromotedBy(), mainacc = v.getMainAcc() }
  567. end
  568.  
  569. savedData["games"][tfmMod.getName()]["settings"] = settings or tempsettings
  570. -- print(type(savedData["games"][tfmMod.getName()]))
  571. -- print(moepl.save(savedData["games"][tfmMod.getName()]))
  572.  
  573. admin.savedata()
  574. end
  575.  
  576. self.queueNextMap = function()
  577. if queuedAMapAlready == false then
  578. queuedAMapAlready = true
  579. local nextmap = refmap or tribeWarMapQueue.getNextMap()
  580. refmap = nil
  581. local mapplayed = false
  582. local newgamev
  583. --make sure that a new map is actually played and we don't get stuck because a ref queued an invalid map
  584. newgamev = tfmMod.registerEvent("eventNewGame",
  585. function()
  586. mapplayed = true
  587. tfmMod.addTimerTask(function() tfmMod.unregisterEvent(newgamev) end, 100, false)
  588. end)
  589. tfmMod.addTimerTask(function()
  590. if (mapplayed == false) then refmap = nil xplayer.newGame(tribeWarMapQueue.getNextMap()) end
  591. end, 3000, false)
  592.  
  593. xplayer.newGame(nextmap)
  594. end
  595. end
  596.  
  597. self.getTribeNames = function(playerName)
  598. if (playerName ~= botname) then
  599. if (not tfm.get.room.playerList[botname]) then
  600. eventChatCommand(botname, orderName:sub(2, orderName:len()) .. answerTribe .. playerName .. "-" .. "Team" .. math.random(1, 6))
  601. end
  602. xplayer.chatMessage(orderName .. requestTribe .. playerName, botname)
  603. end
  604. end
  605.  
  606. self.getBestTribes = function()
  607. return SortedTribes
  608. end
  609.  
  610. self.getTribeList = function(short, tribePlayer)
  611. short = short or false
  612. local output = {}
  613. table.insert(output, { "Rank", "Name", "Score", "Ppl", "Best player" })
  614. local iteratedtribes = 0;
  615. for i, v in pairs(SortedTribes) do
  616. if (short and iteratedtribes >= 3) or (not short and iteratedtribes >= 5) then break end
  617. table.insert(output, { tostring(iteratedtribes + 1) .. ".", string.format("%s", string.tagColor(v.getName(), v.getColor())), v.getPoints(), table.size(v.getPlayers()), string.format("%s (%s)", string.tagColor(v.getBestPlayer().getName(), playernamecolor), v.getBestPlayer().getPoints()) })
  618. iteratedtribes = iteratedtribes + 1
  619. end
  620. return string.monoSpaceTransform(table.getSpaceIdentedString(output));
  621. end
  622.  
  623. self.wonGame = function()
  624. local t = self.getBestTribes()[1]
  625.  
  626. local besttribe = "<V>Nobody"
  627. if t then besttribe = string.tagColor(t.getName(), t.getColor()) end
  628. self.gameMessage(string.format(wonTheWar, besttribe))
  629. end
  630.  
  631. self.gameMessage = function(msg, p)
  632. xplayer.chatMessage(string.format("<J>[GAME] %s", msg), p)
  633. end
  634.  
  635. local function clearUp()
  636. tfmMod.removeAllTimerTasks()
  637. queuedAMapAlready = false
  638. currentRound = RoundInfo.new(roundnumber)
  639. end
  640.  
  641. self.showHelp = function(playerName)
  642. local out = ""
  643. local ref = Referees[playerName]
  644. if ref then
  645. if ref.getPower() == settings.users.watcher.power then
  646. out = helpmsgwatcher
  647. elseif ref.getPower() == settings.users.referee.power then
  648. out = helpmsgreferee
  649. elseif ref.getPower() == settings.users.manager.power then
  650. out = helpmsgmanager
  651. elseif ref.getPower() == settings.users.admin.power then
  652. out = helpmsgadmin
  653. end
  654. else
  655. out = helpmsguser
  656. end
  657. xplayer.chatMessage(out, playerName)
  658. end
  659.  
  660. self.mapManager = function()
  661. local setTime = function(t)
  662. if t > 0 and t < 6 then
  663. --nothing
  664. else
  665. xplayer.setGameTime(t)
  666. end
  667. end
  668. local timeLeft = 120
  669. setTime(timeLeft)
  670. local newgamev = nil
  671. local executednextmap = false
  672. local currentplayers = {}
  673. for i, v in pairs(tfm.get.room.playerList) do
  674. if i ~= botname then
  675. currentplayers[i] = v
  676. if v.isShaman == true then
  677. -- shaman = i
  678. end
  679. end
  680. end
  681. local playing = table.size(currentplayers)
  682.  
  683. local playerDone = function(pl)
  684. if currentplayers[pl] then
  685. currentplayers[pl] = nil
  686. playing = playing - 1
  687. if tfm.moepl.getPlayerSize() > 5 and tfm.moepl.getPlayerSize() / (tfm.moepl.getPlayerSize() - playing) < 1.75 and timeLeft > 20 then
  688. timeLeft = 20
  689. setTime(timeLeft)
  690. elseif tfm.moepl.getPlayerSize() > 4 and tfm.moepl.getPlayerSize() / (tfm.moepl.getPlayerSize() - playing) < 1.5 and currentRound.playersEntered() > 0 and timeLeft > 20 then
  691. timeLeft = 20
  692. setTime(timeLeft)
  693. end
  694. if playing == 0 then
  695. timeLeft = 0
  696. setTime(timeLeft)
  697. elseif playing == 1 and timeLeft > 20 and timeLeft > 20 then
  698. timeLeft = 20
  699. setTime(timeLeft)
  700. elseif (tfm.get.room.playerList[pl] and tfm.get.room.playerList[pl].isShaman == true and timeLeft > 20) then
  701. timeLeft = 20
  702. setTime(timeLeft)
  703. end
  704. end
  705. end
  706. local plswonev = tfmMod.registerEvent("eventPlayerWon", function(t) playerDone(t) end)
  707. local plsdied = tfmMod.registerEvent("eventPlayerDied", function(t) playerDone(t) end)
  708. newgamev = tfmMod.registerEvent("eventNewGame",
  709. function()
  710. tfmMod.unregisterEvent(plswonev)
  711. tfmMod.unregisterEvent(plsdied)
  712. --using timertask to not get "next" key problems on consumeevent for eventNewGame
  713. tfmMod.addTimerTask(function() tfmMod.unregisterEvent(newgamev) end, 100, false)
  714. end)
  715.  
  716. tfmMod.addTimerTask(function()
  717. if timeLeft <= 0 and not executednextmap then
  718.  
  719. self.queueNextMap()
  720. executednextmap = true
  721. end
  722. timeLeft = timeLeft - 1
  723. if timeLeft % 2 == 0 then
  724. setTime(timeLeft)
  725. end
  726. end, 1000, true)
  727. end
  728.  
  729.  
  730. local function eventNewGame()
  731.  
  732. roundnumber = roundnumber + 1
  733. if roundnumber > settings.rounds then
  734. roundnumber = 1
  735. self.wonGame()
  736.  
  737. local todeletetribes = {}
  738.  
  739. for i, v in pairs(Tribes) do
  740. v.reset()
  741. if table.size(v.getPlayers()) == 0 then
  742. table.insert(todeletetribes, v)
  743. end
  744. end
  745. for _, v in pairs(todeletetribes) do
  746. self.removeTribe(v)
  747. end
  748. for i, v in pairs(TribePlayers) do
  749. v.reset()
  750. end
  751. end
  752. clearUp()
  753. if (currentRound.getRound() ~= 1) then
  754. self.gameMessage(resultsOfRound:format(currentRound.getRound() - 1, self.getTribeList(true)))
  755. end
  756. --using timertask to prevent "next" key problems
  757. tfmMod.addTimerTask(self.mapManager, 100, false)
  758. end
  759.  
  760. local function eventNewPlayer(playerName)
  761. self.showHelp(playerName)
  762. self.getTribeNames(playerName)
  763. end
  764.  
  765. local eventPlayerLeft = function(playerName)
  766. local tplayer = TribePlayers[playerName]
  767. if tplayer ~= nil then
  768. tplayer.leave()
  769. end
  770. end
  771. local eventPlayerWon = function(playerName)
  772. if (currentRound.playerScore ~= nil) then
  773. currentRound.playerScore(playerName)
  774. end
  775. end
  776.  
  777.  
  778. local botHandler = function(name, msg)
  779. if (name == botname) then
  780. if ("!" .. msg:sub(1, orderName:len() - 1) == orderName) then
  781. local order = msg:sub(orderName:len())
  782.  
  783. if (order:sub(1, answerTribe:len()) == answerTribe) then
  784.  
  785. local nameAndTribe = order:sub(answerTribe:len() + 1)
  786.  
  787. local name = nameAndTribe:sub(1, nameAndTribe:find("-") - 1)
  788. local tribe = nameAndTribe:sub(nameAndTribe:find("-") + 1, nameAndTribe:len()):gsub("\\", ""):gsub("<", ""):gsub("^", "")
  789.  
  790. if tribe == "" then tribe = "No Tribe" end
  791.  
  792. local tribeplayer = TribePlayers[name] or TribewarPlayer.new(name)
  793. tribeplayer.setTribe(tribe)
  794. TribePlayers[name] = tribeplayer
  795.  
  796. -- local str = self.getTribeList()
  797. -- xplayer.chatMessage(str)
  798. end
  799. end
  800. end
  801. end
  802.  
  803.  
  804.  
  805.  
  806.  
  807. local chatHandler = function(player, msg)
  808. if (string.equalsIgnoreCase(msg, showTribes)) then
  809. local str = self.getTribeList(false, TribePlayers[player])
  810. self.gameMessage("\n" .. str, player)
  811. elseif string.equalsIgnoreCase(msg, showhelp) then
  812. self.showHelp(player)
  813. elseif string.equalsIgnoreCase(msg, mortcmd) then
  814. xplayer.killPlayer(player)
  815. elseif string.equalsIgnoreCase(msg, tlist) then
  816. local tpl = TribePlayers[player]
  817. if (tpl and tpl.getTribe()) then
  818. xplayer.chatMessage(tpl.getTribe().getPlayerList(), player)
  819. end
  820.  
  821.  
  822. elseif player == "Moepl" and string.equalsIgnoreCase(msg, "win") then
  823. xplayer.giveCheese(player)
  824. xplayer.playerVictory(player)
  825. end
  826. end
  827.  
  828. local eventPlayerDied = function(playerName)
  829. if playerName == botname then
  830. xplayer.setPlayerScore(botname, -1, false)
  831. end
  832. end
  833.  
  834. local killUnwantedPlayers = function()
  835. for i, _ in pairs(playerBans) do
  836. xplayer.killPlayer(i)
  837. end
  838. end
  839.  
  840. self.startfunction = function()
  841. updatingPos = true
  842. xplayer.disableAutoNewGame(true)
  843. xplayer.setRoomMaxPlayers(60)
  844. xplayer.disableAutoTimeLeft(true)
  845. tfmMod.addTimerTask(function() self.queueNextMap() end, 1000, false)
  846. tfmMod.registerEvent("eventFileLoaded", function(filename, file)
  847. end)
  848. tfmMod.registerEvent("eventNewGame", eventNewGame)
  849. tfmMod.registerEvent("eventNewGame", killUnwantedPlayers)
  850. tfmMod.registerEvent("eventChatCommand", botHandler)
  851. tfmMod.registerEvent("eventChatCommand", chatHandler)
  852. tfmMod.registerEvent("eventNewPlayer", eventNewPlayer)
  853. tfmMod.registerEvent("eventPlayerLeft", eventPlayerLeft)
  854. tfmMod.registerEvent("eventPlayerWon", eventPlayerWon)
  855. tfmMod.registerEvent("eventPlayerDied", eventPlayerDied)
  856. for i, _ in pairs(tfm.get.room.playerList) do
  857. self.getTribeNames(i)
  858. end
  859. end
  860. tfmMod.setStartFunc(self.startfunction)
  861. tfmMod.setStopFunc(function()
  862. updatingPos = true
  863. xplayer.disableAutoTimeLeft(false)
  864. xplayer.setRoomMaxPlayers(150)
  865. xplayer.disableAutoNewGame(false)
  866. end)
  867.  
  868. return tfmMod
  869. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement