Advertisement
Travonrodfer

Avatar

Aug 10th, 2017
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.38 KB | None | 0 0
  1. local alive = 0
  2. element = 1
  3. solido = 1
  4. aqualarg = 51
  5. aqualta = 51
  6. aquangle = 0
  7. xa = 400
  8. ya = 200
  9. earthlarg = 100
  10. localearth = 100
  11. anearth = 0
  12. tendi = {}
  13. scoressoal = {}
  14. scorecord = 0
  15. avatar = " "
  16. ttmp = true
  17. fogimp = false
  18. local pool = {}
  19.  
  20. function eventTextAreaCallback(id, name, link)
  21.     if link == "fecho" then
  22.         ui.removeTextArea(0)
  23.         ui.removeTextArea(-1)
  24.         ui.removeTextArea(-2)
  25.     elseif link == "tendi" then
  26.         ui.removeTextArea(0)
  27.         ui.removeTextArea(-1)
  28.         ui.removeTextArea(-2)
  29.         tendi[name] = true
  30.     end
  31. end
  32.  
  33. function eventMouse(name, x, y)
  34.     if element == 4 and name == avatar then
  35.         tfm.exec.displayParticle(26, x, y, 1, 1)
  36.         tfm.exec.explosion(x, y, 30, 50)
  37.     elseif element == 3 and name == avatar then
  38.         if fogimp then
  39.             tfm.exec.addPhysicObject(3, x, y,{type=3,width=20,height=100,miceCollision=true, groundCollision=false, friction=0.3, restitution=20, dynamic=false})
  40.         else
  41.             tfm.exec.addPhysicObject(3, x, y,{type=3,width=100,height=20,miceCollision=true, groundCollision=false, friction=0.3, restitution=20, dynamic=false})
  42.         end
  43.     elseif element == 2 and name == avatar then
  44.         if x > localearth then
  45.             anearth = 45
  46.             tfm.exec.addPhysicObject(2,localearth,400,{type=6,width=200,height=earthlarg,miceCollision=true, groundCollision=true, friction=0.3, angle = anearth})
  47.         elseif x < localearth then
  48.             anearth = -45
  49.             tfm.exec.addPhysicObject(2,localearth,400,{type=6,width=200,height=earthlarg,miceCollision=true, groundCollision=true, friction=0.3, angle = anearth})
  50.         end
  51.     elseif element == 1 and name == avatar and solido == 1 then
  52.         if x > xa then
  53.             aquangle = 45
  54.             tfm.exec.addPhysicObject(1,xa,ya,{type=1,width=aqualarg,height=aqualta,miceCollision=true, groundCollision= true, foreground=false, friction=0, angle=aquangle})
  55.         elseif x < xa then
  56.             aquangle = -45
  57.             tfm.exec.addPhysicObject(1,xa,ya,{type=1,width=aqualarg,height=aqualta,miceCollision=true, groundCollision= true, foreground=false, friction=0, angle=aquangle})
  58.         end
  59.     end
  60. end
  61.  
  62. function extremos()
  63.     if aqualarg >= 800 and element == 1 then
  64.         aqualarg = 799
  65.         tfm.exec.addPhysicObject(1,xa,ya,{type=9,width=aqualarg,height=aqualta,miceCollision=false, groundCollision=false, foreground=true})
  66.     elseif aqualarg <= 50 and element == 1 then
  67.         aqualarg = 51
  68.         tfm.exec.addPhysicObject(1,xa,ya,{type=9,width=aqualarg,height=aqualta,miceCollision=false, groundCollision=false, foreground=true})
  69.     end
  70.     if aqualta >= 400 and element == 1 then
  71.         aqualta = 399
  72.         tfm.exec.addPhysicObject(1,xa,ya,{type=9,width=aqualarg,height=aqualta,miceCollision=false, groundCollision=false, foreground=true})
  73.     elseif aqualta <= 50 and element == 1 then
  74.         aqualta = 51
  75.         tfm.exec.addPhysicObject(1,xa,ya,{type=9,width=aqualarg,height=aqualta,miceCollision=false, groundCollision=false, foreground=true})
  76.     end
  77.     if xa >= 800 and element == 1 and solido == 1 then
  78.         xa = 799
  79.         tfm.exec.addPhysicObject(1,xa,ya,{type=1,width=aqualarg,height=aqualta,miceCollision=true, groundCollision= true, foreground=false, friction=0, angle=aquangle})
  80.     elseif xa <= 0 and element == 1 and solido == 1 then
  81.         xa = 0
  82.         tfm.exec.addPhysicObject(1,xa,ya,{type=1,width=aqualarg,height=aqualta,miceCollision=true, groundCollision= true, foreground=false, friction=0, angle=aquangle})
  83.     end
  84.     if ya <= 0 and element == 1 and solido == 1 then
  85.         ya = 0
  86.         tfm.exec.addPhysicObject(1,xa,ya,{type=1,width=aqualarg,height=aqualta,miceCollision=true, groundCollision= true, foreground=false, friction=0, angle=aquangle})
  87.     elseif ya >= 400 and element == 1 and solido == 1 then
  88.         ya = 399
  89.         tfm.exec.addPhysicObject(1,xa,ya,{type=1,width=aqualarg,height=aqualta,miceCollision=true, groundCollision= true, foreground=false, friction=0, angle=aquangle})
  90.     end
  91.     if localearth >= 900 and element == 2 then
  92.         localearth = 800
  93.         tfm.exec.addPhysicObject(2,localearth,400,{type=6,width=200,height=earthlarg,miceCollision=true, groundCollision=true, friction=0.3, angle = anearth})
  94.     elseif localearth <= -100 and element == 2 then
  95.         localearth = 0
  96.         tfm.exec.addPhysicObject(2,localearth,400,{type=6,width=200,height=earthlarg,miceCollision=true, groundCollision=true, friction=0.3, angle = anearth})
  97.     end
  98.     if earthlarg >= 800 and element == 2 then
  99.         earthlarg = 799
  100.         tfm.exec.addPhysicObject(2,localearth,400,{type=6,width=200,height=earthlarg,miceCollision=true, groundCollision=true, friction=0.3, angle = anearth})
  101.     elseif earthlarg <= 0 and element == 2 then
  102.         earthlarg = 0
  103.         tfm.exec.addPhysicObject(2,localearth,400,{type=6,width=200,height=earthlarg,miceCollision=true, groundCollision=true, friction=0.3, angle = anearth})
  104.     end
  105. end
  106.  
  107. function eventKeyboard(name, key, down, x, y)
  108.     if name == avatar then
  109.         if key == 188 or key == 109 then
  110.             element = element + 1
  111.             elementos()
  112.         elseif key == 190 or key == 107 then
  113.             element = element - 1
  114.             elementos()
  115.         end
  116.     end
  117.     if element >= 5 and name == avatar then
  118.         element = 1
  119.         elementos()
  120.     elseif element <= 0 and name == avatar then
  121.         element = 4
  122.         elementos()
  123.     end
  124.     if key == 32 and element == 1 and solido == 1 and name == avatar then
  125.         tfm.exec.addPhysicObject(1,xa,ya,{type=9,width=aqualarg,height=aqualta,miceCollision=false, groundCollision=false, foreground=true})
  126.         solido = 0
  127.     elseif key == 32 and element == 1 and solido == 0 and name == avatar then
  128.         aquangle = 0
  129.         tfm.exec.addPhysicObject(1,xa,ya,{type=1,width=aqualarg,height=aqualta,miceCollision=true, groundCollision= true, foreground=false, friction=0, angle=aquangle})
  130.         solido = 1
  131.     elseif key == 32 and element == 2 and name == avatar then
  132.         anearth = 0
  133.         tfm.exec.addPhysicObject(2,localearth,400,{type=6,width=200,height=earthlarg,miceCollision=true, groundCollision=true, friction=0.3, angle = anearth})
  134.     elseif key == 32 and element == 3 and name == avatar then
  135.         if fogimp then
  136.             tfm.exec.addPhysicObject(3, x, y,{type=3,width=20,height=100,miceCollision=true, groundCollision=false, friction=0.3, restitution=20, dynamic=false})
  137.         else
  138.             tfm.exec.addPhysicObject(5, x, y + 25,{type=3,width=100,height=20,miceCollision=true, groundCollision=false, friction=0.3, restitution=20, dynamic=false})
  139.         end
  140.     elseif key == 32 and element == 4 and name == avatar then
  141.         tfm.exec.displayParticle(26,x,y, 1,1)
  142.         tfm.exec.explosion(x, y, 20, 100)
  143.     elseif key == 75 and element == 3 and name == avatar then
  144.         tfm.exec.addPhysicObject(5, x + 20, y - 7,{type=3,width=20,height=20,miceCollision=true, groundCollision=true, friction=0.3, restitution=20, dynamic=true, fixedRotation=1})
  145.         table.insert(pool, {tfm.exec.addShamanObject(6000, x + 1, y - 7,0, 1, 0, true), os.time()})
  146.     elseif key == 72 and element == 3 and name == avatar then
  147.         tfm.exec.addPhysicObject(5, x - 20, y - 7,{type=3,width=20,height=20,miceCollision=true, groundCollision=true, friction=0.3, restitution=20, dynamic=true, fixedRotation=1})
  148.         table.insert(pool, {tfm.exec.addShamanObject(6000, x - 1, y - 7,0, -1, 0, true), os.time()})
  149.     elseif key == 74 and element == 3 and name == avatar then
  150.         fogimp = false
  151.     elseif key == 85 and element == 3 and name == avatar then
  152.         fogimp = true
  153.     elseif key == 75 and element == 1 and solido == 0 and name == avatar then
  154.         aqualarg = aqualarg + 20
  155.         aqualta = 50
  156.         tfm.exec.addPhysicObject(1,xa,ya,{type=9,width=aqualarg,height=aqualta,miceCollision=false, groundCollision=false, foreground=true})
  157.         extremos()
  158.     elseif key == 75 and element == 1 and solido == 1 and name == avatar then
  159.         xa = xa + 100
  160.         tfm.exec.addPhysicObject(1,xa,ya,{type=1,width=aqualarg,height=aqualta,miceCollision=true, groundCollision= true, foreground=false, friction=0, angle=aquangle})
  161.         extremos()
  162.     elseif key == 72 and element == 1 and solido == 1 and name == avatar then
  163.         xa = xa -100
  164.         tfm.exec.addPhysicObject(1,xa,ya,{type=1,width=aqualarg,height=aqualta,miceCollision=true, groundCollision= true, foreground=false, friction=0, angle=aquangle})
  165.         extremos()
  166.     elseif key == 72 and element == 1 and solido == 0 and name == avatar then
  167.         aqualarg = aqualarg - 20
  168.         aqualta = 50
  169.         tfm.exec.addPhysicObject(1,xa,ya,{type=9,width=aqualarg,height=aqualta,miceCollision=false, groundCollision=false, foreground=true})
  170.         extremos()
  171.     elseif key == 74 and element == 1 and solido == 0 and name == avatar then
  172.         aqualta = aqualta - 20
  173.         aqualarg = 50
  174.         tfm.exec.addPhysicObject(1,xa,ya,{type=9,width=aqualarg,height=aqualta,miceCollision=false, groundCollision=false, foreground=true})
  175.         extremos()
  176.     elseif key == 74 and element == 1 and solido == 1 and name == avatar then
  177.         ya = ya + 50
  178.         tfm.exec.addPhysicObject(1,xa,ya,{type=1,width=aqualarg,height=aqualta,miceCollision=true, groundCollision= true, foreground=false, friction=0, angle=aquangle})
  179.         extremos()
  180.     elseif key == 85 and element == 1 and solido == 0 and name == avatar then
  181.         aqualta = aqualta + 20
  182.         aqualarg = 50
  183.         tfm.exec.addPhysicObject(1,xa,ya,{type=9,width=aqualarg,height=aqualta,miceCollision=false, groundCollision=false, foreground=true})
  184.         extremos()
  185.     elseif key == 85 and element == 1 and solido == 1 and name == avatar then
  186.         ya = ya - 50
  187.         tfm.exec.addPhysicObject(1,xa,ya,{type=1,width=aqualarg,height=aqualta,miceCollision=true, groundCollision= true, foreground=false, friction=0, angle=aquangle})
  188.         extremos()
  189.     elseif key == 75 and element == 2 and name == avatar then
  190.         localearth = localearth + 200
  191.         tfm.exec.addPhysicObject(2,localearth,400,{type=6,width=200,height=earthlarg,miceCollision=true, groundCollision=true, friction=0.3, angle = anearth})
  192.         extremos()
  193.     elseif key == 75 and element == 4 and name == avatar then
  194.         tfm.exec.displayParticle(27,x,y, 1,1)
  195.         tfm.exec.movePlayer(name,0,0,true,40,0,true)
  196.     elseif key == 72 and element == 2 and name == avatar then
  197.         localearth = localearth - 200
  198.         tfm.exec.addPhysicObject(2,localearth,400,{type=6,width=200,height=earthlarg,miceCollision=true, groundCollision=true, friction=0.3, angle = anearth})
  199.         extremos()
  200.     elseif key == 72 and element == 4 and name == avatar then
  201.         tfm.exec.displayParticle(27,x,y, 1,1)
  202.         tfm.exec.movePlayer(name,0,0,true,-40,0,true)
  203.     elseif key == 85 and element == 2 and name == avatar then
  204.         earthlarg = earthlarg + 50
  205.         tfm.exec.addPhysicObject(2,localearth,400,{type=6,width=200,height=earthlarg,miceCollision=true, groundCollision=true, friction=0.3, angle = anearth})
  206.         extremos()
  207.     elseif key == 85 and element == 4 and name == avatar then
  208.         tfm.exec.displayParticle(27,x,y, 1,1)
  209.         tfm.exec.movePlayer(name,0,0,true,0,-40,true)
  210.     elseif key == 74 and element == 2 and name == avatar then
  211.         earthlarg = earthlarg - 50
  212.         tfm.exec.addPhysicObject(2,localearth,400,{type=6,width=200,height=earthlarg,miceCollision=true, groundCollision=true, friction=0.3, angle = anearth})
  213.         extremos()
  214.     end
  215. end
  216.  
  217. function eventLoop(ct, tr)
  218.     if alive <= 0 then
  219.         alive = 0
  220.     end
  221.     if tr <= 0 then
  222.         initial()
  223.     elseif tr <= 10 then
  224.         ttmp = false
  225.     end
  226.     for i,v in ipairs(pool) do
  227.         if v[2] < os.time() - 1000 then
  228.             tfm.exec.removeObject(v[1])
  229.             table.remove(pool, i)
  230.         end
  231.     end
  232.     for name in pairs(tfm.get.room.playerList) do
  233.         if scoressoal[name] > scorecord then
  234.             scorecord = scoressoal[name]
  235.         end
  236.     end
  237. end
  238.  
  239. for name in pairs(tfm.get.room.playerList) do
  240.     scoressoal[name] = 0
  241.     tendi[name] = false
  242.     tfm.exec.setPlayerScore(name, 0, false)
  243.     if name == avatar then
  244.         tfm.exec.changePlayerSize(avatar, 1.2)
  245.         tfm.exec.setPlayerScore(avatar, 0)
  246.         ui.setMapName("avatartar e a lenda de "..avatar.."")
  247.         if tendi[name] == false then
  248.             ui.addTextArea(-2, "<a href=\"event:tendi\"><r>Não mostrar novamente!", avatar, 330, 155, xua, yua, 0x17262e, 0x000000, 1, true)
  249.             ui.addTextArea(-1, "<a href=\"event:fecho\"><r>Ok, entendi!", avatar, 365, 255, xua, yua, 0x17262e, 0x000000, 1, true)
  250.             ui.addTextArea(0, "Você é o avatar e deve dominar os elementos para\najudar os ratos a pegarem o queijo! Aperte os \nbotões <r>, <n>e <r>. <n>para trocar o elemento, aperte <r>espaço\n<n>para dominar e as letras <r>U H J K<n> ou o <r>clique do \nmouse<n>, para mexer em algumas especificações.", avatar, 250, 180, xua, yua, 0x17262e, 0x000000, 1, true)
  251.         end
  252.     end
  253.     for id = 0,255 do
  254.         system.bindKeyboard(name,id,true,true)
  255.         system.bindMouse(name, true)
  256.     end
  257. end
  258.  
  259. function eventNewPlayer(name)
  260.     scoressoal[name] = 0
  261.     tendi[name] = false
  262.     for id = 0,255 do
  263.         system.bindKeyboard(name,id,true,true)
  264.         system.bindMouse(name, true)
  265.     end
  266. end
  267.  
  268. function eventPlayerDied(name)
  269.     local morto=0
  270.     local n
  271.     for pname,player in pairs(tfm.get.room.playerList) do
  272.         if not player.isDead then
  273.             morto=morto+1
  274.             n=pname
  275.         end
  276.     end
  277.     if name == avatar then
  278.         tfm.exec.setPlayerScore(avatar, 0, false)
  279.         if ttmp then
  280.             tfm.exec.setGameTime(10)
  281.             ttmp = false
  282.         end
  283.     else
  284.         tfm.exec.setPlayerScore(name, 1, true)
  285.         scoressoal[name] = scoressoal[name] + 1
  286.     end
  287.     if morto == 0 then
  288.         initial()
  289.     end
  290. end
  291.  
  292. function eventPlayerWon(name)
  293.     local vitoria = 0
  294.     local n
  295.     for pname,player in pairs(tfm.get.room.playerList) do
  296.         if not player.Win then
  297.             vitoria = vitoria + 1
  298.             n=pname
  299.         end
  300.     end
  301.     if name == avatar then
  302.         tfm.exec.setPlayerScore(name, 0, false)
  303.         if ttmp then
  304.             tfm.exec.setGameTime(10)
  305.             ttmp = false
  306.         end
  307.     else
  308.         tfm.exec.setPlayerScore(name, 10, true)
  309.         scoressoal[name] = scoressoal[name] + 10
  310.     end
  311.     if vitoria <= 0 then
  312.         initial()
  313.     end
  314. end
  315.  
  316. function elementos()
  317.     for name in pairs(tfm.get.room.playerList) do
  318.         if element == 1 then
  319.             tfm.exec.setNameColor(avatar, 0x00D0FF)
  320.             ui.setMapName("Avatar: a lenda de <font color=\"#00D0FF\">"..avatar.."")
  321.             ui.addTextArea(1, "<b><p align='center'><font size='13' color='#000000'>Agua</font></p></b>", avatar, 5,375,100,20, 0x00D0FF, 0, 1, true)
  322.         elseif element == 2 then
  323.             tfm.exec.setNameColor(avatar, 0x300005)
  324.             ui.setMapName("Avatar: a lenda de <font color=\"#300005\">"..avatar.."")
  325.             ui.addTextArea(1, "<b><p align='center'><font size='13' color='#000000'>Terra</font></p></b>", avatar, 5,375,100,20, 0x300005, 0, 1, true)
  326.         elseif element == 3 then
  327.             tfm.exec.setNameColor(avatar, 0xC72535)
  328.             ui.setMapName("Avatar: a lenda de <font color=\"#C72535\">"..avatar.."")
  329.             ui.addTextArea(1, "<b><p align='center'><font size='13' color='#000000'>Fogo</font></p></b>", avatar, 5,375,100,20, 0xC72535, 0, 1, true)
  330.         elseif element == 4 then
  331.             tfm.exec.setNameColor(avatar, 0xC8C5C5)
  332.             ui.setMapName("Avatar: a lenda de <font color=\"#C8C5C5\">"..avatar.."")
  333.             ui.addTextArea(1, "<b><p align='center'><font size='13' color='#000000'>Ar</font></p></b>", avatar, 5,375,100,20, 0xC8C5C5, 0, 1, true)
  334.         end
  335.     end
  336. end
  337.  
  338. function sha()
  339.     local p = {}
  340.     for k, v in next, tfm.get.room.playerList do
  341.         for name in pairs(tfm.get.room.playerList) do
  342.             if scoressoal[name] == scorecord then
  343.                 p[#p + 1] = k
  344.                 if name == avatar then
  345.                     scorecord = 0
  346.                     scoressoal[avatar] = 0
  347.                     tfm.exec.setPlayerScore(avatar, 0, false)
  348.                 end
  349.             end
  350.         end
  351.     end
  352.     return p[math.random(#p)]
  353. end
  354.  
  355. function initial()
  356.     local dia = {"#4","#8"}
  357.     tfm.exec.disableAutoShaman(true)
  358.     tfm.exec.disableAutoScore()
  359.     tfm.exec.newGame(dia[math.random(#dia)])
  360.     avatar = sha()
  361.     for name in pairs(tfm.get.room.playerList) do
  362.         if name == avatar then
  363.             tfm.exec.changePlayerSize(avatar, 1.2)
  364.             tfm.exec.setPlayerScore(avatar, 0)
  365.             elementos()
  366.             if tendi[name] == false then
  367.                 ui.addTextArea(-2, "<a href=\"event:tendi\"><r>Não mostrar novamente!", avatar, 330, 155, xua, yua, 0x17262e, 0x000000, 1, true)
  368.                 ui.addTextArea(-1, "<a href=\"event:fecho\"><r>Ok, entendi!", avatar, 365, 255, xua, yua, 0x17262e, 0x000000, 1, true)
  369.                 ui.addTextArea(0, "Você é o avatar e deve dominar os elementos para\najudar os ratos a pegarem o queijo! Aperte os \nbotões <r>, <n>e <r>. <n>para trocar o elemento, aperte <r>espaço\n<n>para dominar e as letras <r>U H J K<n> ou o <r>clique do \nmouse<n>, para mexer em algumas especificações.", avatar, 250, 180, xua, yua, 0x17262e, 0x000000, 1, true)
  370.             end
  371.         end
  372.     end
  373. end
  374. initial()
  375.  
  376. function eventNewGame()
  377.     ttmp = true
  378.     p = {}
  379.     aqualarg = 100
  380.     xa = 400
  381.     ya = 200
  382.     earthlarg = 100
  383.     localearth = 100
  384.     for name in pairs(tfm.get.room.playerList) do
  385.         tfm.exec.setPlayerScore(avatar, 0, false)
  386.         tfm.exec.changePlayerSize(name, 1)
  387.         for id =-2,4 do
  388.             ui.removeTextArea(id, name)
  389.         end
  390.     end
  391.     initial()
  392. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement