Advertisement
Bolodefchoco_LUAXML

[Game] Jokenpô

Apr 8th, 2016
364
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 11.77 KB | None | 0 0
  1. --Creator: Bolodefchoco
  2. --Made in: 08/04/2016
  3. --Last update: 24/03/2017
  4. --[[ Notes:
  5.     Does:
  6.         Um Jokenpô (Pedra-Papel-Tesoura).
  7.         Os pontos em amarelo serão os empates. Para jogar, posicione-se em uma das cadeiras não usada e pressione espaço, pressione B N ou M para escolher o item.
  8.         Você terá sempre 9 segundos (Após os 3 primeiros de início de cada mapa) para escolher um item.
  9.     Keys:
  10.         B --> Pressionada, você optará por jogar Pedra
  11.         N --> Pressionada, você optará por jogar Papel
  12.         M --> Pressionada, você optará por jogar Tesoura (Que no caso, é um baiacu)
  13. ]]--
  14.  
  15. do
  16.     local byte = string.byte
  17.     string.byte = function(str)
  18.         return byte(str,1,#str)
  19.     end
  20. end
  21.  
  22. math.pythag = function(x1,y1,x2,y2,range)
  23.     return (x1-x2)^2 + (y1-y2)^2 <= (range^2)
  24. end
  25.  
  26. table.find = function(list,value,index)
  27.     for k,v in next,list do
  28.         if index then
  29.             if v[index] == value then
  30.                 return true,k
  31.             end
  32.         else
  33.             if v == value then
  34.                 return true,k
  35.             end
  36.         end
  37.     end
  38.     return false
  39. end
  40.  
  41. normalizedTime = function(time)
  42.     return math.floor(time) + ((time - math.floor(time)) >= .5 and .5 or 0)
  43. end
  44.  
  45. jokenpo = {
  46.     translations = {
  47.         en = {
  48.             tie = "Tie",
  49.             won = "Won",
  50.             welcome = "Welcome to <ROSE>#Jokenpo<CE>! Choose a chair, press space and start playing!",
  51.             guide = "<%s>Hello %s! <J>Press\n\t<PS>» <J>%s<PT> - Rock\n\t<PS>» <J>%s<PT> - Paper\n\t<PS>» <J>%s<PT> - Scissor (Pufferfish)",
  52.             played = "You've selected the item %s!",
  53.             items = {"Rock","Paper","Scissor"},
  54.             winner = "Won the game!",
  55.         },
  56.         br = {
  57.             tie = "Empate",
  58.             won = "Venceu",
  59.             welcome = "Bem-vindo ao <ROSE>#Jokenpo<CE>! Escolha uma cadeira, aperte espaço e comece a jogar!",
  60.             guide = "%s>Olá %s! <J>Pressione\n\t<PS>» <J>%s<PT> - Pedra\n\t<PS>» <J>%s<PT> - Papel\n\t<PS>» <J>%s<PT> - Tesoura (Baiacu)",
  61.             played = "Você selecionou o item %s!",
  62.             items = {"Pedra","Papel","Tesoura"},
  63.             winner = "Venceu o jogo!",
  64.         },
  65.     },
  66.     langue = "en",
  67.     totalRounds = 5,
  68.     objects = {
  69.         [1] = 85,
  70.         [2] = 95,
  71.         [3] = 65,
  72.     },
  73.     cBlue = "",
  74.     cRed = "",
  75.     players = {},
  76.     round = 0,
  77.     timer = 0,
  78.     newMapCD = 0,
  79.     tie = 0,
  80.     init = function()
  81.         jokenpo.langue = jokenpo.translations[tfm.get.room.community] and tfm.get.room.community or "en"
  82.         for _,f in next,{"AutoShaman","AutoScore","AutoNewGame","AutoTimeLeft","MinimalistMode","PhysicalConsumables","AfkDeath"} do
  83.             tfm.exec["disable"..f]()
  84.         end
  85.         tfm.exec.setRoomMaxPlayers(25)
  86.         jokenpo.newRound()
  87.     end,
  88.     map = function()
  89.         tfm.exec.newGame('<C><P /><Z><S><S P="0,0,0.3,0.2,0,0,0,0" L="30" o="2d3232" H="400" Y="200" T="12" X="15" /><S P="0,0,0.3,0.2,0,0,0,0" L="800" o="2d3232" H="70" Y="410" T="12" X="400" /><S L="30" o="2d3232" H="400" X="785" Y="210" T="12" P="0,0,0.3,0.2,0,0,0,0" /><S L="800" H="20" X="400" Y="10" T="12" P="0,0,0.3,0.2,0,0,0,0" /><S L="10" o="E3454D" X="318" H="66" Y="224" T="12" P="0,0,0.3,0.2,0,0,0,0" /><S P="0,0,0.3,0.2,-90,0,0,0" L="10" o="E3454D" H="46" Y="196" T="12" X="346" /><S L="10" o="E3454D" H="66" X="374" Y="224" T="12" P="0,0,0.3,0.2,0,0,0,0" /><S L="10" o="E3454D" H="46" X="346" Y="252" T="12" P="0,0,0.3,0.2,-90,0,0,0" /><S P="0,0,0.3,0.2,0,0,0,0" L="10" o="4577E3" X="482" Y="224" T="12" H="66" /><S P="0,0,0.3,0.2,-90,0,0,0" L="10" o="4577E3" X="454" Y="252" T="12" H="46" /><S P="0,0,0.3,0.2,0,0,0,0" L="10" o="4577E3" H="66" Y="224" T="12" X="426" /><S L="10" o="4577E3" H="46" X="454" Y="196" T="12" P="0,0,0.3,0.2,-90,0,0,0" /><S L="10" o="45e374" H="66" X="372" Y="105" T="12" P="0,0,0.3,0.2,0,0,0,0" /><S P="0,0,0.3,0.2,-90,0,0,0" L="10" o="45e374" X="400" Y="77" T="12" H="46" /><S L="10" o="45e374" X="428" H="66" Y="105" T="12" P="0,0,0.3,0.2,0,0,0,0" /><S L="10" o="45e374" X="400" H="46" Y="133" T="12" P="0,0,0.3,0.2,-90,0,0,0" /><S L="74" X="137" H="152" Y="300" T="12" P="0,0,0.3,0.2,0,0,0,0" /><S L="73" X="122" H="10" Y="150" T="12" P="0,0,0.3,0.2,0,0,0,0" /><S L="117" X="705" H="65" Y="340" T="12" P="0,0,0.3,0.2,0,0,0,0" /><S L="14" X="677" H="10" Y="289" T="13" P="0,0,0.3,0.2,0,0,0,0" /><S L="10" X="710" H="10" Y="285" T="13" P="0,0,0.3,0.2,0,0,0,0" /><S L="10" X="655" H="18" Y="301" T="12" P="0,0,0.3,0.2,0,0,0,0" /></S><D><P C="1c2b2b" Y="0" T="34" X="0" P="0,0" /><P P="0,0" Y="334" T="113" X="415" /><P C="cdc5bc,564740" Y="375" T="105" X="285" P="0,1" /><P C="cdc5bc,564740" Y="375" T="105" X="515" P="0,0" /><P C="564740" Y="376" T="104" X="400" P="0,0" /><DS Y="320" X="400" /><P C="413632" Y="379" T="95" P="0,0" X="707" /><P X="124" Y="174" T="112" P="0,0" /><P C="4577E3,babd2f,45e374,E3454D" Y="306" T="93" P="0,0" X="684" /><P C="413632,a3468e" Y="382" T="94" P="0,0" X="132" /><P P="0,0" Y="336" T="21" X="400" /><P X="400" Y="336" T="21" P="0,1" /><P X="475" Y="335" T="31" P="0,0" /><P X="325" Y="335" T="31" P="0,1" /></D><O /></Z></C>')
  90.     end,
  91.     player = function(n,b)
  92.         for i,k in next,{string.byte("BNM")} do
  93.             system.bindKeyboard(n,k,true,b)
  94.         end
  95.         if b then
  96.             system.bindKeyboard(n,32,true,false)
  97.             tfm.exec.playEmote(n,8)
  98.         end
  99.     end,
  100.     getResults = function()
  101.         local run = {}
  102.         for i = 2,1,-1 do
  103.             local v = jokenpo.players[i]
  104.             if v[3] == -1 then
  105.                 run[i] = false
  106.             else
  107.                 run[i] = v[4]
  108.             end
  109.         end
  110.  
  111.         local winner = ((run[1] and run[2]) and ((3 + run[1] - run[2]) % 3) or run[1] and 1 or run[2] and 2 or 0)
  112.  
  113.         local ids = {}
  114.         if winner == 1 then
  115.             ids = {24,5}
  116.             jokenpo.players[1][2] = jokenpo.players[1][2] + 1
  117.             tfm.exec.chatMessage("<CE>[•] <R>" .. jokenpo.players[1][1] .. " " .. jokenpo.translations[jokenpo.langue].won)
  118.         elseif winner == 2 then
  119.             ids = {5,24}
  120.             jokenpo.players[2][2] = jokenpo.players[2][2] + 1
  121.             tfm.exec.chatMessage("<CE>[•] <BV>" .. jokenpo.players[2][1] .. " " .. jokenpo.translations[jokenpo.langue].won)
  122.         elseif winner == 0 then
  123.             ids = {4,4}
  124.             jokenpo.tie = jokenpo.tie + 1
  125.             tfm.exec.chatMessage("<CE>[•] <J>" .. jokenpo.translations[jokenpo.langue].tie)
  126.         end
  127.         tfm.exec.playEmote(jokenpo.players[1][1],ids[1])
  128.         tfm.exec.playEmote(jokenpo.players[2][1],ids[2])
  129.     end,
  130.     getNameDisplay = function()
  131.         local str = ""
  132.         if #jokenpo.players == 2 then
  133.             str = "<R>" .. jokenpo.players[1][1] .. " <V>- <BV>" .. jokenpo.players[2][1]
  134.         else
  135.             if jokenpo.players[1] then
  136.                 str = "<R>" .. jokenpo.players[1][1]
  137.             elseif jokenpo.players[2] then
  138.                 str = "<BV>" .. jokenpo.players[2][1]
  139.             else
  140.                 return ""
  141.             end
  142.         end
  143.         return "   <G>|   <N>Players : " .. str
  144.     end,
  145.     colorName = function()
  146.         if jokenpo.players[1] then
  147.             tfm.exec.setNameColor(jokenpo.players[1][1],0xE3454D)
  148.         end
  149.         if jokenpo.players[2] then
  150.             tfm.exec.setNameColor(jokenpo.players[2][1],0x4577E3)
  151.         end
  152.     end,
  153.     newRound = function()
  154.         jokenpo.map()
  155.         ui.removeTextArea(0,nil)
  156.         jokenpo.timer,jokenpo.newMapCD = 9.5,0
  157.  
  158.         if (jokenpo.round+1) == jokenpo.totalRounds then
  159.             jokenpo.round = 0
  160.            
  161.             for k,v in next,jokenpo.players do
  162.                 jokenpo.player(v[1],false)
  163.                 system.bindKeyboard(v[1],32,true,true)
  164.             end
  165.  
  166.             jokenpo.cBlue,jokenpo.cRed = "",""
  167.             jokenpo.players = {}
  168.             jokenpo.tie = 0
  169.             for i = 1,2 do
  170.                 ui.removeTextArea(i,nil)
  171.             end
  172.         else
  173.             for k,v in next,jokenpo.players do
  174.                 jokenpo.player(v[1],true)
  175.                 v[3] = -1
  176.             end
  177.             jokenpo.colorName()
  178.         end
  179.         jokenpo.round = jokenpo.round + 1
  180.        
  181.         ui.addTextArea(3,"<p align='center'><font size='35'><J>"..math.floor(jokenpo.timer),nil,380,85,40,40,1,1,0,true)
  182.         ui.setMapName("<PT>#Jokenpo   <G>|   <N>Round : <V>" .. jokenpo.round .. jokenpo.getNameDisplay() .."<")
  183.         ui.addTextArea(4,"<p align='center'><font size='25'><J><B>X</B><font size='13'>\n"..("%02d"):format(jokenpo.tie),nil,380,207,40,nil,1,1,0,true)
  184.     end,
  185.     eventNewPlayer = function(n)
  186.         tfm.exec.chatMessage("<CE>[•] " .. jokenpo.translations[jokenpo.langue].welcome,n)
  187.         system.bindKeyboard(n,32,true,true)
  188.         tfm.exec.respawnPlayer(n)
  189.     end,
  190.     eventKeyboard = function(n,k,d,x,y)
  191.         if k == 32 then
  192.             if math.pythag(285,330,x,y,30) then
  193.                 if jokenpo.cRed == "" then
  194.                     tfm.exec.chatMessage("<CE>[•] " .. jokenpo.translations[jokenpo.langue].guide:format("R",n,"B","N","M"),n)
  195.                     jokenpo.cRed = n
  196.                     jokenpo.players[1] = {n,0,-1,0}
  197.                     ui.addTextArea(1,"<p align='center'>"..n.."\n"..("%02d"):format(jokenpo.players[1][2]),nil,270,165,105,nil,1,1,0,true)
  198.                     jokenpo.player(n,true)
  199.                 end
  200.             elseif math.pythag(515,330,x,y,30) then
  201.                 if jokenpo.cBlue == "" then
  202.                     tfm.exec.chatMessage("<CE>[•] " .. jokenpo.translations[jokenpo.langue].guide:format("BV",n,"B","N","M"),n)
  203.                     jokenpo.cBlue = n
  204.                     jokenpo.players[2] = {n,0,-1,0}
  205.                     ui.addTextArea(2,"<p align='center'>"..n.."\n"..("%02d"):format(jokenpo.players[2][2]),nil,425,165,105,nil,1,1,0,true)
  206.                     jokenpo.player(n,true)
  207.                 end
  208.             end
  209.             ui.setMapName("<PT>#Jokenpo   <G>|   <N>Round : <V>" .. jokenpo.round .. jokenpo.getNameDisplay() .."<")
  210.             jokenpo.colorName()
  211.         else
  212.             if jokenpo.cBlue ~= "" and jokenpo.cRed ~= "" then
  213.                 local isPlaying,ind = table.find(jokenpo.players,n,1)
  214.                 if isPlaying then
  215.                     if jokenpo.players[ind][3] == -1 then
  216.                         local found,key = table.find({string.byte("BNM")},k)
  217.                         if found then
  218.                             tfm.exec.chatMessage("<CE>[•] <J>" .. jokenpo.translations[jokenpo.langue].played:format(jokenpo.translations[jokenpo.langue].items[key]),n)
  219.                             jokenpo.player(n,false)
  220.                             jokenpo.players[ind][3] = jokenpo.objects[key]
  221.                             jokenpo.players[ind][4] = key
  222.                         end
  223.                     end
  224.                 end
  225.             end
  226.         end
  227.     end,
  228.     eventLoop = function(currentTime)
  229.         currentTime = normalizedTime(currentTime/1e3)
  230.         if currentTime > 3 then
  231.             if jokenpo.newMapCD > 0 and os.time() > jokenpo.newMapCD then
  232.                 jokenpo.newRound()
  233.             end
  234.  
  235.             if jokenpo.cBlue ~= "" and jokenpo.cRed ~= "" then
  236.                 if currentTime % 2 == 0 then
  237.                     tfm.exec.movePlayer(jokenpo.cBlue,515,330)
  238.                     tfm.exec.playEmote(jokenpo.cBlue,26)
  239.                     tfm.exec.movePlayer(jokenpo.cRed,285,330)
  240.                     tfm.exec.playEmote(jokenpo.cRed,26)
  241.                 end
  242.  
  243.                 if jokenpo.timer < 10 then
  244.                     jokenpo.timer = jokenpo.timer - .5
  245.                     ui.updateTextArea(3,"<p align='center'><font size='35'><J>"..math.floor(jokenpo.timer),nil)
  246.                    
  247.                     if jokenpo.timer <= 0 then
  248.                         jokenpo.timer = 10
  249.                        
  250.                         jokenpo.getResults()
  251.                        
  252.                         local spawnCoord = {350,450}
  253.                         for k,v in next,jokenpo.players do
  254.                             tfm.exec.addShamanObject(v[3],spawnCoord[k],200)
  255.                             ui.updateTextArea(k,"<p align='center'>"..v[1].."\n"..("%02d"):format(v[2]),nil)
  256.                         end
  257.    
  258.                         ui.addTextArea(0,("<font size='50'><p align='center'><R>%d <PT>| <J>%d <PT>| <BV>%s"):format(jokenpo.players[1][2],jokenpo.tie,jokenpo.players[2][2]),nil,5,270,795,nil,1,1,0,true)
  259.                         ui.addTextArea(4,"<p align='center'><font size='25'><J><B>X</B><font size='13'>\n"..("%02d"):format(jokenpo.tie),nil,380,207,40,nil,1,1,0,true)
  260.                        
  261.                         if jokenpo.round == jokenpo.totalRounds then
  262.                             jokenpo.round = 0
  263.  
  264.                             local p = {table.unpack(jokenpo.players)}
  265.                             local winner = ""
  266.                            
  267.                             if p[1][2] == p[2][2] then
  268.                                 winner = jokenpo.translations[jokenpo.langue].tie .. "!"
  269.                             else
  270.                                 table.sort(p,function(p1,p2) return p1[2] > p2[2] end)
  271.                                 winner = string.format("%s (%s) %s!",p[1][1],p[1][2],jokenpo.translations[jokenpo.langue].won)
  272.                                 tfm.exec.chatMessage("<CE>[•] " .. p[1][1] .. " " .. jokenpo.translations[jokenpo.langue].winner,n)
  273.                             end
  274.                            
  275.                             ui.updateTextArea(0,"<V>".. winner .. "\n<font size='13'><R>" .. jokenpo.players[1][2] .. " <PT>|<J> " .. jokenpo.tie .. " | <BV>" .. jokenpo.players[2][2],nil)
  276.                         end
  277.                         jokenpo.newMapCD = os.time() + 25e2
  278.                     end
  279.                 end
  280.             end
  281.         end
  282.     end
  283. }
  284.  
  285. eventNewPlayer = function(n)
  286.     jokenpo.eventNewPlayer(n)
  287. end
  288. table.foreach(tfm.get.room.playerList,eventNewPlayer)
  289.  
  290. eventKeyboard = function(n,k,d,x,y)
  291.     jokenpo.eventKeyboard(n,k,d,x,y)
  292. end
  293.  
  294. eventLoop = function(currentTime,timeLeft)
  295.     jokenpo.eventLoop(currentTime)
  296. end
  297.  
  298. jokenpo.init()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement