Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2017
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.92 KB | None | 0 0
  1. -- Makinit's flattenFunctionTree
  2. do
  3. function flattenFunctionTree(tree, path)
  4. for name, value in pairs(tree) do
  5. if type(value) == "table" then
  6. flattenFunctionTree(value, path .. name .. "_")
  7. elseif type(value) == "function" then
  8. _G[path .. name] = value
  9. end
  10. end
  11. end
  12.  
  13. local temp = {}
  14. for name, value in pairs(_G) do
  15. if value ~= _G then
  16. temp[name] = value
  17. end
  18. end
  19. flattenFunctionTree(temp, "")
  20. end
  21.  
  22. local text={
  23. en={
  24. welcome = "Welcome my nibas"
  25. }
  26. }
  27.  
  28. local _important,_info = 1,2
  29. local tags = {
  30. [0]={"",""},
  31. {"<VP><b>","</b>"},
  32. {"<J>",""}
  33. }
  34.  
  35. local maps = {
  36. "113156","124000","149422","149451","150607","150651","150664","151655","152260","152733","153996","155480","155606","155611","155628","155765","156720","157004","157203","157805","157960","158345","158417","158909","159131","159187","159298","159932","160841","161023","161434","162482","163094","163159","163172","163506","163531","163596","164544","164916","165186","166032","166037","166056","166271","166333","166361","166430","166805","167075","168204","168754","169059","169076","169110","169139","169228","170514","171148","171480","171482","171776","172501","172512","172520","172547","172605","172621","172951","172976","173623","173816","174223","175204","175280","176253","176507","176619","176710","176729","179005","179488","179492","179807","180801","182370","182769","183139","183141","184648","184817","184868","185289","185428","185529","185873","185887","186066","186220","186378","189819","190646","190996","191177","191203","191205","191443","191642","192158","192959","193662","195116","197229","198988","199210","199710","199826","201000","202574","203664","204488","204647","205240","205506","206396","208056","208373","208653","208940","209848","213752","213755","213874","214631","214755","216171","216173","217261","220352","222377","222910","223174","223947","224108","225744","226266","230588","231137","231921","232469","232678","235037","236768","237091","242291","250153","254785","257218","257324","257715","258192","258908","259319","261298","261814","263819","263926","264091","268915","270143","270924","271193","271411","272183","272402","272518","272689","277427","277513","277824","279337","281948","282584","284134","286254","289865","290824","295465","295630","295932","297442","299942","299983","301610","302080","303151","303939","304861","305567","305614","305705","305820","306365","306384","306655","307324","313216","314743","315666","315800","316012","318129","319443","320483","320626","322582","327354","327743","329200","329318","329571","330933","330967","331344","331988","332130","332906","333002","336305","337644","342035","343456","354984","357814","361500","365061","368839","372255","372419","373105","375455","376704","378704","380516","383358","391924","392240","393426","394132","395216","395310","395961","397467","397469","397478","398116","399364","401630","403755","403940","406154","408577","408643","410040","410045","412467","412913","419369","419635","420877","422981","423311","424604","424685","424900","425747","425884","431433","431749","432501","435812","438333","438364","438449","439092","444589","447805","449496","454049","455271","457726","458528","460961","467137","476706","478236","482791","492222","492399","496610","496886","497965","499986","500000","500690","500748","500894","504485","505619","506032","506613","506940","510996","511136","512887","514311","522719","523270","528032","531084","536905","541223","541693","541729","543010","549666","551317","552986","556575","556841","557066","557074","560526","560583","562897","563436","564198","568122","571683","574183","575497","584783","586901","587501","592189","593164","593204","593431","593530","596239","598845","605255","608368","612415","618999","654894","684566","692650","692740","721319","722837","729863","758595","783547","801683","815336","834297","842019","842167","868262","881158","886744","898934","912356","914570","919484","970919","976944","999963","1000006","1004622","1014313","1018394","1046877","1066607","1111252","1130256","1156092","1157281","1162831","1164086","1225867","1226207","1242584","1255359","1256085","1265789","1266330","1301649","1303323","1323048","1333846","1383297","1384078","1390405","1398609","1403454","1410539","1413528","1427980","1435902","1494499","1503203","1526894","1531604","1540221","1580356","1580835","1593066","1595965","1615753","1615949","1620703","1647131","1678634","1722755","1733211","1788490","1807217","1809410","1923584","1955745","1989803","1990413","2024960","2040569","2130169","2178800","2311703","2329940","2416969","2423300","2451444","2469365","2520540","2636519","2788517","2794566","2795201","2846829","2989803","3038589","3136410","3199998","3295967","3326197","3333223","3380788","3456260","3551333","3668866","3668888","3690269","3907267","3908151","3988424","4000000","4067327","4074214","4445580"
  37. }
  38.  
  39. local keys = {67,70,77,86}
  40. local _c = 67
  41. local _f = 70
  42. local _m = 77
  43. local _v = 86
  44.  
  45. local gameFinished = true
  46. local gameLoaded
  47. local gameStarted
  48. local currentMap
  49. local playersInRoom = 0
  50. local mice = {}
  51. local teleport = {}
  52. local cheated = {}
  53.  
  54. local timeList = {}
  55. local timeN = 0
  56.  
  57. local msgList = {}
  58.  
  59. function main()
  60. tfm_get_room_community = tfm.get.room.community
  61.  
  62. tfm_exec_disableAfkDeath(true)
  63. tfm_exec_disableAutoNewGame(true)
  64. tfm_exec_disableAutoTimeLeft(true)
  65. tfm_exec_disableAutoShaman(true)
  66. tfm_exec_disableAutoScore(true)
  67. for n in pairs(tfm.get.room.playerList) do
  68. tfm_exec_setPlayerScore(n, 0)
  69. eventNewPlayer(n)
  70. end
  71. startGame()
  72. end
  73.  
  74. function startGame()
  75. local newMap
  76. repeat
  77. newMap = math.random(#maps)
  78. until newMap ~= currentMap
  79. currentMap = newMap
  80.  
  81. tfm_exec_newGame(maps[newMap])
  82. end
  83.  
  84. function endGame()
  85. gameFinished = true
  86. tfm_exec_setGameTime(5)
  87. showTimeList()
  88. end
  89.  
  90. function eventNewGame()
  91. gameLoaded = true
  92. gameStarted = false
  93. gameFinished = false
  94.  
  95. tfm_exec_setGameTime(360)
  96. tfm_exec_setUIShamanName("Bootcamp")
  97. tfm_exec_setUIMapName("@"..tfm.get.room.xmlMapInfo.mapCode)
  98.  
  99. teleport = {}
  100. cheated = {}
  101. viewingList = {}
  102.  
  103. closeTimeList()
  104. timeList = {}
  105. timeN = 0
  106. end
  107.  
  108. function eventNewPlayer(name)
  109. playersInRoom = playersInRoom + 1
  110. mice[name] = {
  111. }
  112.  
  113. for _,k in pairs(keys) do
  114. tfm_exec_bindKeyboard(name, k, true)
  115. end
  116. system_bindMouse(name, true)
  117.  
  118. msg(lang().welcome, name, _important)
  119. tfm_exec_respawnPlayer(name)
  120. end
  121.  
  122. function eventPlayerLeft(name)
  123. playersInRoom = playersInRoom - 1
  124. mice[name] = nil
  125. end
  126.  
  127. function eventPlayerDied(name)
  128. if gameFinished then return end
  129. tfm_exec_respawnPlayer(name)
  130. end
  131.  
  132. function eventPlayerRespawn(name)
  133. cheated[name] = nil
  134. end
  135.  
  136. function eventPlayerWon(name, _, t)
  137. if gameFinished then return end
  138. tfm_exec_respawnPlayer(name)
  139.  
  140. local timeText
  141.  
  142. if cheated[name] then
  143. timeText = "Cheater!"
  144. else
  145. local pos = 0
  146. for i=timeN,1,-1 do
  147. if t < timeList[i].t then
  148. timeList[i+1] = timeList[i]
  149. else
  150. pos = i
  151. break
  152. end
  153. end
  154.  
  155. timeText = string.format("%02d:%02d:%02d", convertTime(t))
  156.  
  157. if pos<60 then
  158. timeList[pos+1] = {n=name, t=t}
  159. if timeN < 60 then
  160. timeN = timeN + 1
  161. else
  162. timeList[61] = nil
  163. end
  164.  
  165. if pos==0 then
  166. tfm_exec_setUIShamanName(name.." - "..timeText)
  167. end
  168. end
  169.  
  170. tfm_exec_setPlayerScore(name, 1, true)
  171. end
  172.  
  173. msgList[#msgList+1] = {n=name, ts=os.time()}
  174. ui_addTextArea(0, timeText, name, 20, 40, 120, 20)
  175. end
  176.  
  177. function eventLoop(t, tr)
  178. if not gameLoaded then return end
  179. if not gameStarted then
  180. if t > 3000 then
  181. gameStarted = true
  182. end
  183. return
  184. end
  185.  
  186. for i,m in ipairs(msgList) do
  187. if os.time() > m.ts + 2500 then
  188. ui_removeTextArea(0, m.n)
  189. table.remove(msgList, i)
  190. else
  191. break
  192. end
  193. end
  194.  
  195. if not gameFinished and tr <= 0 then
  196. endGame()
  197. elseif gameFinished and tr <= 0 then
  198. startGame()
  199. end
  200. end
  201.  
  202. function eventKeyboard(name, key, down, px, py)
  203. if key==_c then
  204. local tp = teleport[name]
  205. if tp then
  206. tfm_exec_movePlayer(name, tp.x, tp.y)
  207. cheated[name] = true
  208. end
  209. elseif key==_m then
  210. tfm_exec_killPlayer(name)
  211. elseif key==_f then
  212. tfm_exec_giveCheese(name)
  213. cheated[name] = true
  214. elseif key==_v then
  215. if viewingList[name] then
  216. closeTimeList(name)
  217. viewingList[name] = false
  218. else
  219. showTimeList(name)
  220. viewingList[name] = true
  221. end
  222. end
  223. end
  224.  
  225. function eventMouse(name, mx, my)
  226. teleport[name] = {x=mx, y=my}
  227. end
  228.  
  229. function eventChatCommand(name, com)
  230. if com=="mort" then
  231. tfm_exec_killPlayer(name)
  232. elseif com=="cheese" then
  233. tfm_exec_giveCheese(name)
  234. cheated[name] = true
  235. elseif com=="new" then
  236. startGame()
  237. elseif com=="test" then
  238. tfm_exec_newGame(1234567)
  239. end
  240. end
  241.  
  242. function eventTextAreaCallback(id, name, cb)
  243. if id==3 then
  244. closeTimeList(name)
  245. viewingList[name] = false
  246. end
  247. end
  248.  
  249. function showTimeList(name)
  250. ui_addTextArea(1, "<p align='center'><font size='16'>Completion times</font></p>", name, 270, 60, 260, 320)
  251. ui_addTextArea(2, "list", name, 280, 100, 240, 270)
  252. ui_addTextArea(3, "<a href='event:close'><p align='center'>X</p></a>", name, 550, 60, 20, 20, 0x882222)
  253. updateTimeList(name)
  254. end
  255.  
  256. function updateTimeList(name)
  257. local s=""
  258. for i=1,timeN do
  259. local t = timeList[i]
  260. tm,ts,th = convertTime(t.t)
  261. s=s..string.format("%02d - %02d:%02d:%02d - %013s\n", i, tm, ts, th, t.n)
  262. end
  263. ui_updateTextArea(2, s, name)
  264. end
  265.  
  266. function closeTimeList(name)
  267. for i=1,3 do
  268. ui_removeTextArea(i, name)
  269. end
  270. end
  271.  
  272. function msg(msg, tgt, tag)
  273. tag = tags[tag or 0]
  274. tfm_exec_chatMessage(tag[1]..msg..tag[2], tgt)
  275. end
  276.  
  277. function lang()
  278. return text[tfm_get_room_community] or text.en
  279. end
  280.  
  281. function hundredthsToMinutes(h)
  282. return math.floor(h/6000)
  283. end
  284.  
  285. function hundredthsToSeconds(h)
  286. return math.floor(h/100)
  287. end
  288.  
  289. function convertTime(time)
  290. local min = hundredthsToMinutes(time)
  291. time = time - min*6000
  292.  
  293. local sec = hundredthsToSeconds(time)
  294. time = time - sec*100
  295.  
  296. return min,sec,time
  297. end
  298.  
  299. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement