Advertisement
superpaste

super mario maker on tfm

Jul 3rd, 2017
442
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 29.28 KB | None | 0 0
  1. adm="Jellymichey#0000"
  2. lang="PT"
  3. blockRespawnRate=5
  4. chatMessages=true
  5. -----------------------------------------------------------------------
  6. recreatingBlocks={}
  7. recreatingBlocksNumber=0
  8. arrayUIs={}
  9. textareas={}
  10. definition={{name="type",type="integer"},{name="friction",type="integer"},{name="restitution",type="integer"},{name="color",type="color"},{name="foreground",type="boolean"},{name="miceCollision",type="boolean"},{name="width",type="integer"},{name="height",type="integer"},{name="angle",type="integer"}}
  11. function distance ( x1, y1, x2, y2 )
  12.   local dx = x1 - x2
  13.   local dy = y1 - y2
  14.   return math.sqrt ( dx * dx + dy * dy )
  15. end
  16. function unload()
  17. print("unloading")
  18. --eventLoop=system.exit()
  19. end
  20. function absoluteMiceCollision(b)
  21. if b==nil then return nil end
  22. if b.miceCollision==nil then
  23. return true
  24. end
  25. return b.miceCollision
  26. end
  27. function table.clone(orig)
  28.     local orig_type = type(orig)
  29.     local copy
  30.     if orig_type == 'table' then
  31.         copy = {}
  32.         for orig_key, orig_value in next, orig, nil do
  33.             copy[table.clone(orig_key)] = table.clone(orig_value)
  34.         end
  35.         setmetatable(copy, table.clone(getmetatable(orig)))
  36.     else -- number, string, boolean, etc
  37.         copy = orig
  38.     end
  39.     return copy
  40. end
  41. function initAdminData()
  42. return {type=0,timeSinceTyped=os.time(),isTeleporting=false,customnized=table.clone(prop[12]),callingValue="",showingCustom=false}
  43. end
  44. function table.slice(tbl, first, last, step)
  45.   local sliced = {}
  46.  
  47.   for i = first or 1, last or #tbl, step or 1 do
  48.     sliced[#sliced+1] = tbl[i]
  49.   end
  50.  
  51.   return sliced
  52. end
  53. function tablelength(T)
  54.   local count = 0
  55.   for _ in pairs(T) do count = count + 1 end
  56.   return count
  57. end
  58.  
  59. function generateCrambledText()
  60.     local abc = "abcdefghijklmnopqrstuvwxyz"
  61.     local ret = ""
  62.     for i=1,20 do
  63.         local e=math.random(1,string.len(abc))
  64.         ret=ret..string.sub(abc,e,e)
  65.     end
  66.     return ret
  67. end
  68. do
  69.     local cm=tfm.exec.chatMessage
  70.     tfm.exec.chatMessage=function(c,n) print("("..tostring(n)..") "..c) cm(c,n) end
  71. end
  72. spawnpointPlayers={}
  73. blocksInUse=0
  74. translation={PT={
  75. settings_MAP3="4 paredes",
  76. settings_MAP2="com paredes",
  77. settings_MAP1="normal",
  78. settings_MAP="estilo de mapa",
  79. settings_GRAVITY="gravidade",
  80.     settings_WIND="vento",
  81.     settings_WIDTH="largura do mapa",
  82.     settings_HEIGHT="altura do mapa",
  83.     settings_START="começar/carregar o mapa",
  84.     settings_USTART="temos que esperar 3s para carregar o mapa",
  85.     settings_popup_GRAVITY="gravidade",
  86.     settings_popup_WIND="vento",
  87.     settings_popup_WIDTH="largura",
  88. settings_popup_HEIGHT="altura",
  89. mapLoader="Carregando o mapa para você! :)",
  90. custom_type="Tipo do bloco (do tfm)",
  91. custom_friction="fricção",
  92. custom_restitution="restituição",
  93. custom_color="cor",
  94. custom_miceCollision="colisão com rato",
  95. custom_width="largura",
  96. custom_height="altura",
  97. custom_angle="angulo",
  98. custom_foreground="primeiro plano",
  99. custom_import="importar bloco selecionado",
  100. custom_import_ERROR="você não pode importar o bloco ",
  101. adm_ERROR_supremeDowngrade="Tentar diminuir o supremo não é possível. flw",
  102. adm_ERROR_autoDowngrade="Tentar diminuir você mesmo não é muito bom...",
  103. start_message="cuidado com o",
  104. help_ENVMAKE="aqui você pode clicar em tudo quanto é mapa para criar bloco! Você pode estacar blocos se a colisão deles for diferente! Para mudar de bloco você pode escrever !0 até !18 ou nas emoções!",
  105. help_MAPCONFIG="aqui você tem que configurar o mapa antes de ir jogar com ela!",
  106. settings_CHEESE="precisa de queijo",
  107. map_spawn_kill="Você perdeu o spawnoint! Vá se salvar em outro!"
  108. },
  109. EN={
  110. settings_CHEESE="requires cheese",
  111. settings_MAP3="4 walls",
  112. settings_MAP2="with walls",
  113. settings_MAP1="normal",
  114. settings_MAP="map style",
  115. settings_GRAVITY="gravity",
  116.     settings_WIND="wind",
  117.     settings_WIDTH="map width",
  118.     settings_HEIGHT="map height",
  119.     settings_START="load map/start",
  120.     settings_USTART="We need to wait 3s to load map",
  121.     settings_popup_GRAVITY="gravity",
  122.     settings_popup_WIND="wind",
  123.     settings_popup_WIDTH="width",
  124. settings_popup_HEIGHT="height",
  125. mapLoader="game is loading tiles for you :)",
  126. custom_type="(from tfm) block type",
  127. custom_friction="friction",
  128. custom_restitution="restitution",
  129. custom_color="color",
  130. custom_miceCollision="collision with mice",
  131. custom_width="width",
  132. custom_height="height",
  133. custom_angle="angle",
  134. custom_foreground="foreground",
  135. custom_import="import selected block",
  136. custom_import_ERROR="you can't import ",
  137. adm_ERROR_supremeDowngrade="Trying to downgrade the supreme isn't possible. Bye",
  138. adm_ERROR_autoDowngrade="Downgrading yourself isn't very good...",
  139. start_message="beware of",
  140. help_ENVMAKE="here you can click on everything you want to to create blocks! You can also stack up blocos with different collision setting! To change the block you can type !0 to !18 or on the emotions!",
  141. help_MAPCONFIG="here you need to config everything before playing with it!",
  142. map_spawn_kill="You lost spawnpoint! Go find a new one!"
  143. }}
  144.  
  145. function getWord(language,thing)
  146.     if translation[lang] then
  147.         if translation[lang][thing] then
  148.        
  149.         return translation[lang][thing]
  150.         else
  151.             return thing
  152.         end
  153.     else
  154.         if translation.EN[thing] then
  155.        
  156.         return translation.EN[thing]
  157.         else
  158.             return thing
  159.         end
  160.     end
  161. end
  162. tfm.exec.disableAutoNewGame(true)
  163. tfm.exec.disableAutoShaman(true)
  164. tfm.exec.disableAfkDeath(true)
  165. tfm.exec.disablePhysicalConsumables (true)
  166. widesness=800
  167. cheeseRequired=false
  168. spection={}
  169. playersEntered={}
  170. admins={}
  171. playerData={}
  172. mapPred="normal"
  173. gravityFactor={gravity=10,wind=0}
  174. heightness=400
  175. showCustom=false
  176. spawnpointTiles={}
  177. CstDefs={type=0,width=40,height=40,friction=0.3,restitution=0.2,color=0xaaaaaa}
  178. DefCall=""
  179. prop = {}
  180. prop[0] = {type=0,width=40,height=40,friction=0.3,restitution=0.2}
  181. prop[1] = {type=1,width=40,height=40,friction=0,restitution=0.2}
  182. prop[2] = {type=2,width=40,height=40,friction=0,restitution=1.2}
  183. prop[3] = {type=3,width=40,height=40,friction=0,restitution=20}
  184. prop[4] = {type=4,width=40,height=40,friction=20,restitution=0.2}
  185. prop[5] = {type=5,width=40,height=40,friction=0.3,restitution=0.2}
  186. prop[6] = {type=6,width=40,height=40,friction=0.3,restitution=0.2}
  187. prop[7] = {type=7,width=40,height=40,friction=0.1,restitution=0.2}
  188. prop[8] = {type=8,width=40,height=40,friction=0.3,restitution=0.2,miceCollision=false}
  189. prop[9] = {type=9,width=40,height=40,friction=0.3,restitution=0.2,miceCollision=false}
  190. prop[10] = {type=10,width=40,height=40,friction=0.3,restitution=0}
  191. prop[11] = {type=11,width=40,height=40,friction=0.05,restitution=0.1}
  192. prop[12] = {type=12,width=40,height=40,friction=0.3,restitution=0.2,color=0xaaaaaa}
  193. prop[13] = {type=13,width=20,friction=0.3,restitution=0.2,color=0xaaaaaa}
  194. prop[14] = {type=14,width=40,height=40,friction=0.3,restitution=0.2,color=0xaaaaaa}
  195. prop[15] = {type=15,width=40,height=40,friction=0.3,restitution=0.2,color=0xaaaaaa,miceCollision=false}
  196. prop[16] = {type=4,width=10,height=40,friction=20,restitution=0.2,color=0xaaaaaa}
  197. prop[17] = {type=0,width=10,height=40,friction=0.3,restitution=0.2,color=0xaaaaaa}
  198. prop[18] = {type=1,width=10,height=10,friction=0,restitution=0.2,color=0xaaaaaa,angle=45}
  199. function makeMapMaker(fromMain)
  200.     if fromMain==nil then
  201.         tiles={}
  202.         start="nil"
  203.         finish="nil"
  204.         ui.removeTextArea(0)
  205.         ui.removeTextArea(1)
  206.         for x,v in pairs(spawnpointTiles) do
  207.             ui.removeTextArea(v.ui)
  208.         end
  209.         for x,v in pairs(textareas) do
  210.             ui.removeTextArea(v.textarea)
  211.         end
  212.         textareas={}
  213.         for _,x in pairs(playerData) do
  214.             x.spawnpointPlayers.place="nil"
  215.         end
  216.         spawnpointTiles = {}
  217.     end
  218.     tfm.exec.chatMessage(getWord(lang,"help_MAPCONFIG"),adm)
  219.     blocksInUse=0
  220.     tfm.exec.newGame('<C><P /><Z><S /><D /><O /></Z></C>')
  221.     isOnMenu=true
  222.     ui.addTextArea(2, '<p align=\"right\"><a href="event:wide">'..getWord(lang,"settings_WIDTH")..'</a></p>', adm, 0, 20, 400, 0, 0x123450, 0x123450, 1, false)
  223.     ui.addTextArea(3, "<a href=\"event:height\">"..getWord(lang,"settings_HEIGHT").."</a>", adm, 400, 20, 400, 0, 0x123450, 0x123450, 1, false)
  224.     ui.addTextArea(4, "<p align=\"center\">"..getWord(lang,"settings_USTART").."</p>", adm, 0, 60, 800, 0, 0x123450, 0x123450, 1, false)
  225.     ui.addTextArea(5, '<p align="right"><a href=\"event:gravity\">'..getWord(lang,"settings_GRAVITY")..'</a></p>', adm, 0, 40, 400, 0, 0x123450, 0x123450, 1, false)
  226.     ui.addTextArea(6, '<a href="event:wind">'..getWord(lang,"settings_WIND")..'</a>', adm, 400, 40, 400, 0, 0x123450, 0x123450, 1, false)
  227.     ui.addTextArea(7, "<font color=\"#"..(cheeseRequired and "00ff00" or "ff0000").."\">".."<a href=\"event:requiredCheese\">"..getWord(lang,"settings_CHEESE").."</a>", adm, 00, 360, 800, 0, 0x123450, 0x123450, 1, false)
  228.     ui.addTextArea(8, getWord(lang,"settings_MAP")..': <a href="event:map1">'..getWord(lang,"settings_MAP1")..'</a>, <a href="event:map2">'..getWord(lang,"settings_MAP2")..'</a>, <a href="event:map3">'..getWord(lang,"settings_MAP3")..'</a>', adm, 0, 380, 800, 0, 0x123450, 0x123450, 1, false)
  229. end
  230. if tfm.get.room.playerList[adm]==nil then ---------------
  231.  scrambledText=generateCrambledText()
  232.  print(scrambledText)
  233.  ui.addTextArea(1, 'who\'ll write '..scrambledText.." wins admin...", nil, 0, 250, 400, 0, 0x123450, 0x123450, 1, true)
  234.  flyPerm={}
  235. else
  236. flyPerm={adm}
  237. admins={[adm]=initAdminData()}
  238. ui.addTextArea(1, getWord(lang,"start_message")..' '..adm.."...", nil, 0, 250, 400, 0, 0x123450, 0x123450, 1, false)
  239. ui.addTextArea(1, '!number -> select block<br>!start -> starting point<br>!finish -> ending point<br>!spawnpoint -> creates spawnpoint<br>!fly player#0000 ->set a player to fly<br>!reset -> resets map', adm, 0, 250, 400, 0, 0x123450, 0x123450, 1, false)
  240. makeMapMaker(true)
  241. end
  242.  
  243. function eventNewGame()
  244.     lastId="nil"
  245.     ui.setShamanName (adm)
  246.     ui.setMapName(adm.." <BL>- @-1")
  247.     for i,v in pairs(tfm.get.room.playerList) do
  248.         tfm.exec.killPlayer(i)
  249.     end
  250. end
  251. function eventTextAreaCallback( id, j, c)
  252. local sucess,status=pcall(function( id, j, c)
  253. print("")
  254.     local cl={}
  255.     for i in string.gmatch(c,"[^;]+") do
  256.         cl[#cl+1]=i
  257.     end
  258.     if c=="wide" then
  259.         ui.addPopup(0, 2, getWord(lang,"settings_popup_WIDTH"), adm, 300, 150, 200, true)
  260.         elseif c=="requiredCheese" then
  261.         cheeseRequired=not cheeseRequired
  262.         ui.updateTextArea(7,"<font color=\"#"..(cheeseRequired and "00ff00" or "ff0000").."\">".."<a href=\"event:requiredCheese\">"..getWord(lang,"settings_CHEESE").."</a>")
  263.         elseif c == "height" then
  264.         ui.addPopup(1, 2, getWord(lang,"settings_popup_HEIGHT"), adm, 300, 150, 200, true)
  265.        
  266.         elseif c == "start" then
  267.         isOnMenu=false
  268.         tfm.exec.chatMessage(getWord(lang,"help_ENVMAKE"),adm)
  269.         tfm.exec.newGame('<C><P G="'..gravityFactor["wind"]..','..gravityFactor["gravity"]..'" H="'..heightness..'" L="'..widesness..'"/><Z><S /><D /><O /></Z></C>')
  270.         for i=1,8 do
  271.             ui.removeTextArea(i,nil)
  272.         end
  273.         mapCreator=coroutine.create(function() local fc = 0
  274. if mapPred=="walls" or mapPred=="4w" then
  275. for i=0,tonumber(heightness/40) do
  276. compBlocks(0,i*40,1)
  277. fc=fc+1
  278. if fc==3 then coroutine.yield() fc=0 end
  279. end
  280. for i=0,tonumber(heightness/40) do
  281. compBlocks(widesness-1,i*40,1)
  282. fc=fc+1
  283. if fc==3 then coroutine.yield() fc=0 end
  284. end
  285. end
  286. if mapPred=="4w" then
  287. for i=0,tonumber((widesness-1)/40) do
  288. compBlocks(i*40,0,1)
  289. fc=fc+1
  290. if fc==3 then coroutine.yield() fc=0 end
  291. end
  292. for i=0,tonumber((widesness-1)/40) do
  293. compBlocks(i*40,heightness-1,1)
  294. fc=fc+1
  295. if fc==3 then coroutine.yield() fc=0 end
  296. end
  297. end end)
  298.         elseif c == "import" then
  299.         if tonumber(admins[j].type)==nil then
  300.             tfm.exec.chatMessage("<R>".. getWord(lang,"custom_import_ERROR") .. admins[j].type .."!",j)
  301.         else
  302.             admins[j].customnized=table.clone(prop[admins[j].type])
  303.         end
  304.         elseif c=="map1" then
  305. mapPred="normal"
  306. elseif c=="map2" then
  307. mapPred="walls"
  308. elseif c=="map3" then
  309. mapPred="4w"
  310.         elseif c=="gravity" then
  311.         ui.addPopup(3, 2, getWord(lang,"settings_popup_GRAVITY"), adm, 300, 150, 200, true)
  312.         elseif c=="wind" then
  313.         ui.addPopup(4, 2, getWord(lang,"settings_popup_WIND"), adm, 300, 150, 200, true)
  314.  
  315.         elseif cl[1]=="valueChange" then
  316.         admins[j].callingValue=cl[2]
  317.         if cl[3]=="integer" then
  318.         ui.addPopup(2, 2, cl[2] .. " set value", j, 300, 150, 200, true)
  319.         ui.addPopup(5, 1, cl[2] .. " set value", j, 300, 420, 200, true)
  320.         elseif cl[3]=="color" then
  321.             ui.showColorPicker (0, j, 0x000000, cl[2] .. " set value")
  322.             ui.addPopup(2, 2, cl[2] .. " set value", j, 300, 420, 200, true)
  323.             ui.addPopup(5, 1, cl[2] .. " set value", j, 300, 420, 200, true)
  324.         elseif cl[3]=="boolean" then
  325.         ui.addPopup(5, 1, cl[2] .. " set value", j, 300, 150, 200, true)
  326.         ui.addPopup(2, 2, cl[2] .. " set value", j, 300, 420, 420, true)
  327.         end
  328.     end
  329.     end,id,j,c)
  330.     if not(sucess) then tfm.exec.chatMessage("editor crashou... Envie o motivo do crash ao Jellymichey#0000<br>"..status) unload() end
  331. end
  332.  
  333.  
  334. tiles={}
  335. start="nil"
  336. finish="nil"
  337. function eventKeyboard(j,c,p,x,y)
  338. local sucess,status=pcall(function(j,c,p,x,y)
  339.     if c==32 then
  340.     for _,i in pairs(flyPerm) do
  341.         if j==i then
  342.             tfm.exec.movePlayer(j, 0, 0, true, 0, -50, true)
  343.             tfm.exec.displayParticle (13, x, y, 0, 0, 0, 0)
  344.         end
  345.     end
  346.     end
  347.     if c>=48 and c<=57 and admins[j] then
  348.         if admins[j].timeSinceTyped>os.time()-1000 then
  349.             if string.len(tostring(admins[j].type))~=2 then
  350.                 admins[j].type=tonumber(admins[j].type..tostring(c-48))
  351.             end
  352.         else
  353.             admins[j].type=c-48
  354.         end
  355.         admins[j].timeSinceTyped=os.time()
  356.         if admins[j].type>#prop then
  357.             admins[j].type=#prop
  358.         end
  359.         ui.addTextArea (-1, tostring(admins[j].type), j, 0, 370, 20, 20, 0x111111, 0x111111, 1, true)
  360.     end
  361.     if c==40 or c==83 then
  362.     for id,n in pairs(spawnpointTiles) do
  363.         if x < n["x"]+20 and x > n["x"]-10 and y < n["y"]+20 and y > n["y"]-10 and (not tfm.get.room.playerList[j].isDead) then
  364.                 playerData[j].spawnpointPlayers.place={}
  365.                 playerData[j].spawnpointPlayers.place[1]=x
  366.                 playerData[j].spawnpointPlayers.place[2]=y
  367.                 if playerData[j].spawnpointPlayers.spawnId~="nil" then
  368.                 spawnpointTiles[playerData[j].spawnpointPlayers.spawnId].peopleUsing[j]=nil
  369.                 end
  370.                 playerData[j].spawnpointPlayers.spawnId=id
  371.                 n.peopleUsing[j]=true
  372.                 playerData[j].spawnpointPlayers.cheese=tfm.get.room.playerList[j].hasCheese
  373.                 for xx=-60,0 do
  374.                 tfm.exec.displayParticle (0, x, y+(xx*5), 0, 0, math.random(-10,10)/100, 0, j)
  375.                 end
  376.             end
  377.         end
  378.     end
  379.     end,j,c,p,x,y)
  380.     if not(sucess) then tfm.exec.chatMessage("editor crashou... Envie o motivo do crash ao Jellymichey#0000<br>"..status) unload() end
  381. end
  382.  
  383. function eventNewPlayer(n)
  384. local sucess,status=pcall(function(n)
  385.     tfm.exec.chatMessage("<J>humm bom dia! #editor feito pelo Jellymichey#0000!<br>neste module os admins fazem o mapa e vocês, ratinhos, tentam resolê-lo</J>",n)
  386.     playerData[n]={}
  387.     if not isOnMenu then
  388.     recreator=coroutine.create(function()
  389.         while tablelength(recreatingBlocks)~=0 do
  390.             for i=0,blockRespawnRate do
  391.                 tfm.exec.removePhysicObject(#recreatingBlocks)
  392.                 tfm.exec.addPhysicObject(#recreatingBlocks, recreatingBlocks[#recreatingBlocks]["x"], recreatingBlocks[#recreatingBlocks]["y"], recreatingBlocks[#recreatingBlocks]["defs"])
  393.                 recreatingBlocks[#recreatingBlocks]=nil
  394.                 if tablelength(recreatingBlocks)==0 then break end
  395.             end
  396.             coroutine.yield()
  397.         end
  398.     end)
  399.     recreatingBlocks=table.clone(tiles)
  400.     recreatingBlocksNumber=tablelength(recreatingBlocks)
  401.     ui.addTextArea(-3, "<p align=\"center\"><font size=\"20\">"..getWord(lang,"mapLoader").."</font></p>", n, 0, 20, 800, 400, 0x111111, 0x111111, 0.7, true)
  402.     end
  403.     playerData[n].spawnpointPlayers={place="nil",cheese=false,spawnId="nil"}
  404.     system.bindKeyboard(n, 32, false, true)
  405.     for i=48,57 do
  406.     system.bindKeyboard(n, i, false, true)
  407.     end
  408.     system.bindKeyboard(n, 40, false, true)
  409.     system.bindKeyboard(n, 83, false, true)
  410.     system.bindMouse(n,true)
  411.     playersEntered[#playersEntered+1]=n
  412.     end,n)
  413.     if not(sucess) then tfm.exec.chatMessage("editor crashou... Envie o motivo do crash ao Jellymichey#0000<br>"..status) unload() end
  414.     end
  415.  
  416. function eventPlayerDied(n)
  417.     if not(start=="nil") then
  418.         if spection[n] then return end
  419.         tfm.exec.respawnPlayer(n)
  420.     end
  421. end
  422.  
  423. function eventPlayerRespawn(n)
  424. local sucess,status=pcall(function(n)
  425.     if not(isOnMenu) then
  426.         if playerData[n].spawnpointPlayers.place=="nil" then
  427.             if start~="nil" then
  428.             print("a")
  429.                 tfm.exec.movePlayer(n, start[1]+25, start[2]+25, false, 0, 0, false)
  430.             end
  431.         else
  432.             tfm.exec.movePlayer(n, playerData[n].spawnpointPlayers.place[1], playerData[n].spawnpointPlayers.place[2], false, 0, 0, false)
  433.             if playerData[n].spawnpointPlayers.cheese then
  434.             tfm.exec.giveCheese(n)
  435.             end
  436.         end
  437.         if adm==n then
  438.             tfm.exec.setNameColor ( n, 0xffff00)
  439.         end
  440.         for _,i in pairs(admins) do
  441.             tfm.exec.setNameColor (i, 0x00ff00)
  442.         end
  443.     end
  444.     end,n)
  445.     if not(sucess) then tfm.exec.chatMessage("editor crashou... Envie o motivo do crash ao Jellymichey#0000<br>"..status) unload() end
  446. end
  447.  
  448. function eventPlayerWon(n)
  449.     playerData[n].spawnpointPlayers.place="nil"
  450.     eventPlayerDied(n)
  451. end
  452. function compBlocks(x,y,thisType,customed)
  453.         if (tonumber(thisType)==nil) then
  454.             if thisType == "start" then
  455.                 ui.addTextArea (0, "", nil, math.floor(x/40)*40+15, math.floor(y/40)*40+15, 25, 25, 0xff0000, 0xff0000, 1, false)
  456.                 start={math.floor(x/40)*40,math.floor(y/40)*40}
  457.                 for i in pairs(tfm.get.room.playerList) do
  458.                     eventPlayerDied(i)
  459.                 end
  460.             end
  461.             if thisType == "finish" then
  462.                 ui.addTextArea (1, "", nil, math.floor(x/40)*40+15, math.floor(y/40)*40+15, 25, 25, 0x00ff00, 0x00ff00, 1, false)
  463.                 finish={(math.floor(x/40)*40),(math.floor(y/40)*40)}
  464.             end
  465.             if thisType == "spawnpoint" then
  466.                 local have = false
  467.                 local id = ""
  468.                 for v,n in pairs(spawnpointTiles) do
  469.                     if n["x"] == math.floor(x/40)*40+25 and n["y"] == math.floor(y/40)*40+25 then
  470.                         have=true
  471.                         id=v
  472.                     end
  473.                 end
  474.                 if have==true then
  475.                     ui.removeTextArea(spawnpointTiles[id].ui,nil)
  476.                     for i in pairs(spawnpointTiles[id].peopleUsing) do
  477.                         tfm.exec.chatMessage("<V>"..getWord(lang,"map_spawn_kill"),i)
  478.                         playerData[i].spawnpointPlayers={place="nil",cheese=false,spawnId="nil"}
  479.                     end
  480.                     spawnpointTiles[id]=nil
  481.                     else
  482.                     local i = 1
  483.                     while not(spawnpointTiles[i]==nil) do
  484.                         i=i+1
  485.                     end
  486.                     local ii = 10
  487.                     while not(arrayUIs[ii]==nil) do
  488.                         ii = ii + 1
  489.                     end
  490.                     arrayUIs[ii]="spawnpoint"
  491.                     spawnpointTiles[i]={peopleUsing={},ui=ii,x=math.floor(x/40)*40+25,y=math.floor(y/40)*40+25}
  492.                     ui.addTextArea (ii, "", nil, math.floor(x/40)*40+15, math.floor(y/40)*40+15, 25, 25, 0xffff00, 0xffff00, 1, false)
  493.                 end
  494.             end
  495.             if thisType == "custom" then
  496.                 local have = false
  497.                 local id = ""
  498.                 for v,n in pairs(tiles) do
  499.                     if n["x"] == math.floor(x/40)*40+25 and n["y"] == math.floor(y/40)*40+25 and absoluteMiceCollision(n.defs)==absoluteMiceCollision(customed) then
  500.                         have = true
  501.                         id=v
  502.                     end
  503.                 end
  504.                 if have==true then
  505.                     tfm.exec.removePhysicObject(id)
  506.                     blocksInUse=blocksInUse-1
  507.                     tiles[id]=nil
  508.                     else
  509.                     local i = 1
  510.                     while not(tiles[i]==nil) do
  511.                         i=i+1
  512.                     end
  513.                     if blocksInUse<480 then
  514.                     tfm.exec.addPhysicObject(i, math.floor(x/40)*40+25, math.floor(y/40)*40+25, table.clone(customed))
  515.                     tiles[i]={x=math.floor(x/40)*40+25,y=math.floor(y/40)*40+25,defs=table.clone(customed)}
  516.                     blocksInUse=blocksInUse+1
  517.                     lastId=i
  518.                     end
  519.                 end
  520.             end
  521.             else
  522.             local have = false
  523.             local id = ""
  524.             for v,n in pairs(tiles) do
  525.                 if n["x"] == math.floor(x/40)*40+25 and n["y"] == math.floor(y/40)*40+25 and absoluteMiceCollision(n.defs)==absoluteMiceCollision(prop[thisType]) then
  526.                     have = true
  527.                     id=v
  528.                 end
  529.             end
  530.             if have==true then
  531.                 tfm.exec.removePhysicObject(id)
  532.                 blocksInUse=blocksInUse-1
  533.                 tiles[id]=nil
  534.                 else
  535.                 local i = 1
  536.                 while not(tiles[i]==nil) do
  537.                     i=i+1
  538.                 end
  539.                 if blocksInUse<480 then
  540.                 tfm.exec.addPhysicObject(i, math.floor(x/40)*40+25, math.floor(y/40)*40+25, prop[thisType])
  541.                 tiles[i]={x=math.floor(x/40)*40+25,y=math.floor(y/40)*40+25,defs=prop[thisType]}
  542.                 blocksInUse=blocksInUse+1
  543.                 lastId=i
  544.                 end
  545.             end
  546.             ui.addTextArea(-2,blocksInUse.."/480 blocks",nil,700,380,100,20,0x111111,0x111111,1,true)
  547.         end
  548. end
  549. function eventMouse(n,x,y,remoteBlock)
  550. local sucess,status=pcall(function(n,x,y,remoteBlock)
  551. print(admins[n])
  552.     if not(isOnMenu) and admins[n] then
  553.         thisType=admins[n].type
  554.         if not(remoteBlock==nil) then
  555.             thisType=remoteBlock
  556.         end
  557.         if admins[n].panflet then
  558.             if admins[n].panflet=="" then
  559.                 local d=""
  560.                 for i,v in pairs(textareas) do
  561.                     if distance(x,y,v.x,v.y)<30 then
  562.                         arrayUIs[v.textarea]=nil
  563.                         ui.removeTextArea(v.textarea)
  564.                         d=i
  565.                         break
  566.                     end
  567.                 end
  568.                 if d~="" then
  569.                 textareas[d]=nil
  570.                 end
  571.                 admins[n].panflet=nil
  572.                 return
  573.             else
  574.                 local i = 0
  575.                 while not(textareas[i]==nil) do
  576.                     i = i + 1
  577.                 end
  578.                 local ii = 10
  579.                 while not(arrayUIs[ii]==nil) do
  580.                     ii = ii + 1
  581.                 end
  582.                 arrayUIs[ii]="textarea"
  583.                 textareas[i]={textarea=ii,text=admins[n].panflet,x=x,y=y}
  584.                 ui.addTextArea(ii, admins[n].panflet, nil, x, y, 0, 0, 0x111111, 0x111111, 1, false)
  585.                 admins[n].panflet=nil
  586.                 return
  587.             end
  588.         end
  589.         if admins[n].isTeleporting~=false then
  590.             tfm.exec.movePlayer(admins[n].isTeleporting,x,y,false,0,0,true)
  591.             admins[n].isTeleporting=false
  592.         else
  593.             compBlocks(x,y,thisType,admins[n].customnized)
  594.         end
  595.     end
  596.     end,n,x,y,remoteBlock)
  597.     if not(sucess) then tfm.exec.chatMessage("editor crashou... Envie o motivo do crash ao Jellymichey#0000<br>"..status) unload() end
  598. end
  599.  
  600. function eventChatCommand(n,c)
  601. local sucess,status=pcall(function(n,c)
  602.     local rules = {}
  603.     for i in string.gmatch(c,"[^ ]+") do
  604.         rules[#rules+1]=i
  605.     end
  606.     if admins[n] then
  607.         if tonumber(c) == nil and c ~= "use" and rules[1]~="t" then
  608.         for _,i in pairs(admins) do
  609.             if tfm.get.room.playerList[i.name]~=nil then
  610.                 tfm.exec.chatMessage("<N2>Ξ ["..n.."] !"..c,i.name)
  611.             end
  612.         end
  613.         end
  614.         if not(tonumber(c)==nil) then
  615.             admins[n].type = tonumber(c)
  616.             elseif rules[1] == "reload" then
  617.     recreator=coroutine.create(function()
  618.         while tablelength(recreatingBlocks)~=0 do
  619.             for i=0,blockRespawnRate do
  620.                 tfm.exec.removePhysicObject(#recreatingBlocks)
  621.                 tfm.exec.addPhysicObject(#recreatingBlocks, recreatingBlocks[#recreatingBlocks]["x"], recreatingBlocks[#recreatingBlocks]["y"], recreatingBlocks[#recreatingBlocks]["defs"])
  622.                 recreatingBlocks[#recreatingBlocks]=nil
  623.                 if tablelength(recreatingBlocks)==0 then break end
  624.             end
  625.             coroutine.yield()
  626.         end
  627.     end)
  628.     recreatingBlocks=table.clone(tiles)
  629.     recreatingBlocksNumber=tablelength(recreatingBlocks)
  630.             elseif rules[1] == "reset" then
  631.             if adm==n then
  632.             makeMapMaker()
  633.             else
  634.             tfm.exec.chatMessage("<VP>Você precisa ser o master"..c,n)
  635.             end
  636.             elseif rules[1] == "textarea" then
  637.             print(#rules)
  638.             admins[n].panflet=(rules[2] and table.concat(table.slice(rules,2,#rules,1), " ") or "")
  639.             print(admins[n].panflet)
  640.             elseif rules[1] == "t" then
  641.             for i in pairs(admins) do
  642.                 if tfm.get.room.playerList[i]~=nil then
  643.                     tfm.exec.chatMessage("<CH>Ξ ["..n.."] "..table.concat(table.slice(rules,2,#rules,1), " "),i)
  644.                 end
  645.             end
  646.             elseif rules[1] == "adm" then
  647.             if rules[2]==n then tfm.exec.chatMessage("<R>"..getWord(lang,"adm_ERROR_autoDowngrade"),n) return end
  648.             if rules[2]==adm then tfm.exec.chatMessage("<R>"..getWord(lang,"adm_ERROR_supremeDowngrade"),n) return end
  649.             if admins[rules[2]] then
  650.                 admins[rules[2]]=nil
  651.                 tfm.exec.setNameColor (rules[2], 0xbbbbbb)
  652.                 else
  653.                 admins[rules[2]]=initAdminData()
  654.                 tfm.exec.setNameColor (rules[2], 0x00ff00)
  655.             end
  656.             elseif c == "start" then
  657.             admins[n].type = "start"
  658.             elseif c == "finish" then
  659.             admins[n].type = "finish"
  660.             elseif c == "custom" then
  661.             if admins[n].showingCustom then
  662.                 ui.removeTextArea(5,n)
  663.                 admins[n].showingCustom=false
  664.                 else
  665.                 local compose = ""
  666.                 for _,i in pairs(definition) do
  667.                     compose = compose .. "<a href=\"event:valueChange;" .. i.name .. ";"..i.type.."\">" .. getWord(lang,"custom_"..i.name) .. "</a>  "
  668.                 end
  669.                 ui.addTextArea(5, compose .. "  <a href=\"event:import\">"..getWord(lang,"custom_import").."</a>", n, 0, 20, 800, 0, 0x123450, 0x123450, 1, true)
  670.                 admins[n].showingCustom=true
  671.             end
  672.             elseif c == "use" then
  673.             admins[n].type = "custom"
  674.             elseif rules[1] == "tp" then
  675.             if nil==rules[2] then
  676.                 admins[n].isTeleporting=n
  677.             elseif tfm.get.room.playerList[rules[2]] then
  678.                 if nil==rules[3] then
  679.                     admins[n].isTeleporting=rules[2]
  680.                 else
  681.                     tfm.exec.movePlayer(rules[2],tfm.get.room.playerList[rules[3]].x,tfm.get.room.playerList[rules[3]].y,false,0,0,true)
  682.                 end
  683.             end
  684.             elseif c == "spawnpoint" then
  685.             admins[n].type = "spawnpoint"
  686.             elseif rules[1]=="fly" then
  687.             local there="no"
  688.             local id_=0
  689.             for id,i in pairs(flyPerm) do
  690.                 if i==rules[2] then
  691.                     there="yes"
  692.                     id_=id
  693.                 end
  694.             end
  695.             if there=="yes" then
  696.                 flyPerm[id_]=nil
  697.                 else
  698.                 flyPerm[#flyPerm+1]=rules[2]
  699.             end
  700.             elseif rules[1]=="spectator" then
  701.             if spection[rules[2]] then
  702.                 spection[rules[2]]=nil
  703.                 else
  704.                 spection[rules[2]]=true
  705.                 tfm.exec.killPlayer(rules[2])
  706.             end
  707.             eventPlayerDied(rules[2])
  708.         end
  709.     end
  710.     end,n,c)
  711.     if not(sucess) then tfm.exec.chatMessage("editor crashou... Envie o motivo do crash ao Jellymichey#0000<br>"..status) unload() end
  712. end
  713.  
  714. function eventLoop(p)
  715. local sucess,status=pcall(function(p)
  716.     if isOnMenu==true then
  717.         if p>4000 then --controls the acess to load the map
  718.             ui.updateTextArea(4,"<p align=\"center\"><a href=\"event:start\">"..getWord(lang,"settings_START").."</a></p>")
  719.         end
  720.     end
  721.     if not(finish=="nil") then
  722.         for i,v in pairs(tfm.get.room.playerList) do
  723.         if (not v.hasCheese) or (not cheeseRequired) then
  724.             if v["x"] < finish[1]+40 and v["x"] > finish[1]-0 and v["y"] < finish[2]+40 and v["y"] > finish[2]-0 and (not v.isDead) then
  725.                 tfm.exec.giveCheese(i)
  726.                 if not cheeseRequired then
  727.                 tfm.exec.playerVictory(i)
  728.                 tfm.get.room.playerList[i].y=tfm.get.room.playerList[i].y+400
  729.                 playerData[i].spawnpointPlayers.place="nil"
  730.                 end
  731.             end
  732.             else
  733.             if v["x"] < start[1]+40 and v["x"] > start[1]-0 and v["y"] < start[2]+40 and v["y"] > start[2]-0 and (not v.isDead) then
  734.                 tfm.exec.playerVictory(i)
  735.             end
  736.             end
  737.         end
  738.     end
  739.     if recreator~=nil then
  740.     if coroutine.status(recreator)~="dead" then
  741.         coroutine.resume(recreator)
  742.         print("re")
  743.         if coroutine.status(recreator)=="dead" then
  744.             for _,v in pairs(playersEntered) do
  745.                 ui.updateTextArea(-3,"<p align=\"center\"><font size=\"20\">pronto!</p>",v)
  746.                 if not(start=="nil") then
  747.                     ui.addTextArea (0, "", v, start[1]+13, start[2]+13, 25, 25, 0xff0000, 0xff0000, 1, false)
  748.                 end
  749.                 if not(finish=="nil") then
  750.                     print("fnish")
  751.                     ui.addTextArea (1, "", v, finish[1]+13, finish[2]+13, 25, 25, 0x00ff00, 0x00ff00, 1, false)
  752.                 end
  753.                 for i,v in pairs(spawnpointTiles) do
  754.                     ui.addTextArea (v.textarea, "", nil, v["x"]-10, v["y"]-10, 25, 25, 0xffff00, 0xffff00, 1, false)
  755.                 end
  756.                 for i,v in pairs(textareas) do
  757.                     ui.addTextArea (v.textarea, v.text, nil, v["x"], v["y"], 0, 0, 0x111111, 0x111111, 1, false)
  758.                 end
  759.                 eventPlayerDied(v)
  760.                 print(v)
  761.             end
  762.             playersEntered={}
  763.         else
  764.         print("load")
  765.             ui.updateTextArea(-3,"<p align=\"center\"><font size=\"20\">"..getWord(lang,"mapLoader").."</font><br><br>"..string.rep("▓",math.ceil((recreatingBlocksNumber-tablelength(recreatingBlocks))/recreatingBlocksNumber*30))..string.rep("░",math.floor((tablelength(recreatingBlocks))/recreatingBlocksNumber*30)).."</p>",v)
  766.         end
  767.     else
  768.     ui.removeTextArea(-3)
  769.     end
  770.     end
  771.     if mapCreator~=nil then
  772.         if coroutine.status(mapCreator)~="dead" then
  773.             coroutine.resume(mapCreator)
  774.         end
  775.     end
  776.     for i,v in pairs(admins) do
  777.         if v.timeSinceTyped<os.time()-2000 then
  778.             ui.removeTextArea(-1,i)
  779.         end
  780.     end
  781.     end,p)
  782.     if not(sucess) then tfm.exec.chatMessage("editor crashou...<br> Envie o motivo do crash ao Jellymichey#0000: "..status) unload() end
  783. end
  784.  
  785. function eventPopupAnswer( id, j, r)
  786.     if id==5 then
  787.         admins[j].customnized[admins[j].callingValue]=(r=="yes")
  788.     end
  789.     print(tonumber(r))
  790.     if not(tonumber(r)==nil) then
  791.         if id==0 then
  792.             widesness=math.max(800,tonumber(r))
  793.         end
  794.         if id==1 then
  795.             heightness=math.max(400,tonumber(r))
  796.         end
  797.         if id==2 then
  798.             admins[j].customnized[admins[j].callingValue]=r
  799.         end
  800.         if id==3 then
  801.             gravityFactor["gravity"]=tonumber(r)
  802.         end
  803.         if id==4 then
  804.             gravityFactor["wind"]=tonumber(r)
  805.         end
  806.     end
  807. end
  808. function eventChatMessage(j,c)
  809.     if scrambledText~=nil then
  810.         if c==scrambledText then
  811.             scrambledText=nil
  812.             adm=j
  813.             flyPerm={adm}
  814.             admins={[adm]=initAdminData()}
  815.             ui.addTextArea(1, 'beware of '..adm.."...", nil, 0, 250, 400, 0, 0x123450, 0x123450, 1, false)
  816.             ui.addTextArea(1, '!number -> select block<br>!start -> starting point<br>!finish -> ending point<br>!spawnpoint -> creates spawnpoint<br>!fly player#0000 ->set a player to fly<br>!reset -> resets map', adm, 0, 250, 400, 0, 0x123450, 0x123450, 1, false)
  817.             makeMapMaker(true)
  818.         end
  819.     end
  820. end
  821. function eventColorPicked ( id, j, c)
  822. if c==-1 then return false end
  823. admins[j].customnized[admins[j].callingValue]=tostring(c)
  824. end
  825. for i in pairs(tfm.get.room.playerList) do --players init
  826.     eventNewPlayer(i)
  827. end
  828. tfm.exec.setRoomMaxPlayers(25)
  829.  
  830. for _, v in next, {"start","spawnpoint","reset","finish","fly","adm","custom","use","tp","t","spectator","textarea","reload"} do
  831. system.disableChatCommandDisplay(v)
  832. end
  833. for i in pairs(prop) do system.disableChatCommandDisplay(tostring(i)) end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement