Advertisement
Unlocker001_TFM

Tic Tac Toe

May 4th, 2018
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 14.03 KB | None | 0 0
  1.  
  2. map = [[<C><P DS="m;17,350,77,366,138,380,216,360,310,361,392,372,482,372,578,379,682,377,751,356" D="x_transformice/x_maps/x_rentree2015/map-classe.jpg" /><Z><S><S P="0,0,0.5,0.2,15,0,0,0" L="147" H="10" lua="0" Y="369" T="0" m="" X="67" /><S P="0,0,0.3,0.2,0,0,0,0" L="155" H="10" Y="379" T="0" m="" X="433" /><S P="0,0,0.3,0.2,-2,0,0,0" L="200" H="10" Y="383" T="0" m="" X="608" /><S P="0,0,0.3,0.2,-20,0,0,0" L="80" H="10" Y="382" T="0" m="" X="157" /><S P="0,0,0.3,0.2,0,0,0,0" L="160" H="10" Y="369" T="0" m="" X="274" /><S P="0,0,0.5,0.2,-15,0,0,0" L="120" H="10" Y="365" T="0" m="" X="744" /><S P="0,0,0.3,0.2,40,0,0,0" L="10" H="10" Y="381" T="0" m="" X="512" /><S P="0,0,0.3,0.2,50,0,0,0" L="14" H="10" Y="372" T="0" m="" X="354" /><S P="0,0,0,0,0,0,0,0" L="10" H="400" Y="200" T="0" m="" X="-5" /><S P="0,0,0,0,0,0,0,0" L="10" H="400" Y="200" T="0" m="" X="805" /><S L="800" o="9b612c" X="400" H="127" Y="395" T="12" P="0,0,0.3,0.2,0,0,0,0" /></S><D><P C="ffd73d" Y="332" T="19" P="0,0" X="765" /><P C="ff8630" Y="331" T="19" P="0,0" X="41" /><DS Y="318" X="400" /></D><O /></Z></C>]]
  3. tfm.exec.disableAutoNewGame(true)
  4. tfm.exec.disableAfkDeath(true)
  5. tfm.exec.disableAutoShaman(true)
  6. timeNewRound=false
  7. NewGame=false
  8. square={{x1=320,x2=380,y1=95 ,y2=155,id=1,a=""},{x1=381,x2=440,y1=95 ,y2=155,id=2,a=""},{x1=441,x2=500,y1=95 ,y2=155,id=3,a=""},{x1=320,x2=380,y1=156,y2=214,id=4,a=""},{x1=381,x2=440,y1=156,y2=214,id=5,a=""},{x1=441,x2=500,y1=156,y2=214,id=6,a=""},{x1=320,x2=380,y1=215,y2=274,id=7,a=""},{x1=381,x2=440,y1=215,y2=274,id=8,a=""},{x1=441,x2=500,y1=215,y2=274,id=9,a=""}}
  9. chair={{x1=0,x2=80,y1=250,y2=330,boolean=false,player="Space",bl=false},{x1=720,x2=800,y1=250,y2=330,boolean=false,player="Space",bl=false}}
  10. idsWin={{1,2,3},{4,5,6},{7,8,9},{1,5,9},{3,5,7},{1,4,7},{2,5,8},{3,6,9}}
  11. jointTables={{point1={x=331,y=127},point2={x=491,y=127}},{point1={x=331,y=187},point2={x=491,y=187}},{point1={x=331,y=247},point2={x=491,y=247}},{point1={x=491,y=264},point2={x=331,y=105}},{point1={x=331,y=265},point2={x=491,y=106}},{point1={x=351,y=111},point2={x=351,y=264}},{point1={x=412,y=111},point2={x=412,y=264}},{point1={x=471,y=111},point2={x=471,y=264}}}
  12. tb_moves={200,250,300,350,400,450,500,550,600}
  13. welcome_msg = "<rose>Welcome to <j>Tic-Tac-Toc game. !</j></rose><br><fc>Type !help to display info about the minigame.</fc>"
  14. t=0
  15. tt=5
  16. t_win=true
  17. canSpace=false
  18. csp=false
  19. cspt=0
  20. mice = 0
  21. nameW=""
  22.  
  23.  
  24. function ConSy(ty)
  25.   local co, s = idsWin, square
  26.   local a1,a2,a3,type="","","",""
  27.   local aX={"","",""}
  28.   local aO={"","",""}
  29.   for i=1,#co do
  30.     for j,v in pairs(s) do
  31.       if     s[j].id == co[i][1] and s[j].a == "X"  then aX[1]=co[i][1]
  32.       elseif s[j].id == co[i][2] and s[j].a == "X"  then aX[2]=co[i][2]
  33.       elseif s[j].id == co[i][3] and s[j].a == "X"  then aX[3]=co[i][3]
  34.       elseif s[j].id == co[i][1] and s[j].a == "O"  then aO[1]=co[i][1]
  35.       elseif s[j].id == co[i][2] and s[j].a == "O"  then aO[2]=co[i][2]
  36.       elseif s[j].id == co[i][3] and s[j].a == "O"  then aO[3]=co[i][3]
  37.       end
  38.       if aX[1] ~= "" and aX[2] ~= "" and aX[3] ~= "" then
  39.         if ty == "type" then return 1
  40.         elseif ty == "id" then return i
  41.         end
  42.       elseif aO[1] ~= "" and aO[2] ~= "" and aO[3] ~= "" then
  43.         if ty == "type" then return 2
  44.         elseif ty == "id" then return i
  45.         end
  46.       end
  47.     end
  48.     aX={"","",""}
  49.     aO={"","",""}
  50.   end
  51. end
  52.  
  53. function WinPlayer(n,id)
  54.   local jo = jointTables
  55.   chair[1].bl,chair[2].bl=false,false
  56.   ui.removeTextArea(100, nil)
  57.   tfm.exec.addJoint(1,0,0,{type=0,point1=jo[id].point1.x..","..jo[id].point1.y,point2=jo[id].point2.x..","..jo[id].point2.y,line=4,color=(n == 1 and "0xF52E2E" or "0x5CA4D4"),foreground=true})
  58.   NewGame=true
  59. end
  60.  
  61.  
  62. function eventLoop(time,m)
  63.   if NewGame then
  64.     t=t+1
  65.   if t == 5 and t_win then
  66.     tfm.exec.addJoint(1,0,0,{type=0,point1=0,0,point2=0,0,line=4,color=nil,foreground=true})
  67.     nameW = chair[ConSy("type")].player
  68.     tfm.exec.chatMessage("<vb>"..nameW.."<rose> Won the Game!!</rose>")
  69.     tfm.exec.giveCheese(nameW)
  70.     tfm.exec.playerVictory(nameW)
  71.     ui.addTextArea(50,"<p align='center'><font size ='40'>"..nameW.." Won the Game</font></p>",nil,94,148,615,95,nil,nil,0,false)
  72.     for i=1,9 do
  73.       ui.removeTextArea(i, nil)
  74.     end
  75.     t_win=false
  76.   elseif t == 20 then
  77.     for i=1,9 do
  78.       ui.removeTextArea(i, nil)
  79.     end
  80.     tfm.exec.addJoint(1,0,0,{type=0,point1=0,0,point2=0,0,line=4,color=nil,foreground=true})
  81.     ui.addTextArea(50,"<p align='center'><font size ='35'>Next round starts in "..tt.." seconds</font></p>",nil,94,148,615,95,nil,nil,0,false)
  82.   elseif t == 30 then
  83.     ui.removeTextArea(50, nil)
  84.     tfm.exec.newGame(map)
  85.     tfm.exec.chatMessage("<rose>New round !</rose>")
  86.   end
  87.   if t > 5 and t < 19 then
  88.     for i=0,20 do
  89.       tfm.exec.displayParticle(21,math.random(0,800),math.random(0,400),0,math.random(1.1),0,math.random(0.22))
  90.       tfm.exec.displayParticle(22,math.random(0,800),math.random(0,400),0,math.random(1.1),0,math.random(0.22))
  91.       tfm.exec.displayParticle(23,math.random(0,800),math.random(0,400),0,math.random(1.1),0,math.random(0.22))
  92.       tfm.exec.displayParticle(24,math.random(0,800),math.random(0,400),0,math.random(1.1),0,math.random(0.22))
  93.     end
  94.   end
  95.   if t == 22 or t == 24 or t == 26 or t == 28 then
  96.     tt=tt-1
  97.     ui.addTextArea(50,"<p align='center'><font size ='35'>Next round starts in "..tt.." seconds</font></p>",nil,94,148,615,95,nil,nil,0,false)
  98.   end
  99.   end
  100.   if csp then
  101.     cspt = cspt + 1
  102.     if cspt == 2 then
  103.       canSpace = true
  104.       cspt = 0
  105.       csp = false
  106.     end
  107.   end
  108. end
  109.  
  110. function eventPlayerWon(n,timeElapsed, timeElapsedSinceRespawn)
  111.   tfm.exec.respawnPlayer(n)
  112. end
  113.  
  114. function eventNewGame()
  115.   ui.setMapName("<rose>#xo </rose><v>Module")
  116.   for i=1,9 do
  117.     square[i].a=""
  118.   end
  119.   for i=1,2 do
  120.     chair[i].boolean=false
  121.     chair[i].bl=false
  122.     chair[i].player="Space"
  123.   end
  124.   NewGame=false
  125.   t_win=true
  126.   nameW=""
  127.   t=0
  128.   tt=5
  129.   timeNewRound=false
  130.   RefrchNames(nil)
  131.   for n,p in pairs(tfm.get.room.playerList) do
  132.     tfm.exec.movePlayer(n,tb_moves[math.random(#tb_moves)],320)
  133.     tfm.exec.setNameColor (n,0xFFCB00)
  134.   end
  135.   csp = true
  136. end
  137.  
  138. function numberSquare(n,Nx,Ny)
  139.   for i,t in pairs(square) do
  140.     if ((Nx >= square[i].x1 and Nx <= square[i].x2) and (Ny >= square[i].y1 and Ny <= square[i].y2)) then
  141.         return square[i].id
  142.     end
  143.   end
  144. end
  145.  
  146. function Menu(n)
  147.   if (chair[1].player ~= "Space" and chair[2].player ~= "Space") and t < 5  then
  148.     s=square
  149.     ui.addTextArea(1,"<p align='center'>"..(s[1].a == "X" and "<font size='42' color='#F52E2E'>"..s[1].a.."" or s[1].a == "O" and "<font size='40' color='#5CA4D4'>"..s[1].a or "").."</p></font>",n,326,100,50,50,-1,16777215,0.9,false)
  150.     ui.addTextArea(2,"<p align='center'>"..(s[2].a == "X" and "<font size='42' color='#F52E2E'>"..s[2].a.."" or s[2].a == "O" and "<font size='40' color='#5CA4D4'>"..s[2].a or "").."</p></font>",n,386,100,50,50,-1,16777215,0.9,false)
  151.     ui.addTextArea(3,"<p align='center'>"..(s[3].a == "X" and "<font size='42' color='#F52E2E'>"..s[3].a.."" or s[3].a == "O" and "<font size='40' color='#5CA4D4'>"..s[3].a or "").."</p></font>",n,446,100,50,50,-1,16777215,0.9,false)
  152.     ui.addTextArea(4,"<p align='center'>"..(s[4].a == "X" and "<font size='42' color='#F52E2E'>"..s[4].a.."" or s[4].a == "O" and "<font size='40' color='#5CA4D4'>"..s[4].a or "").."</p></font>",n,326.5,160,50,50,-1,16777215,0.9,false)
  153.     ui.addTextArea(5,"<p align='center'>"..(s[5].a == "X" and "<font size='42' color='#F52E2E'>"..s[5].a.."" or s[5].a == "O" and "<font size='40' color='#5CA4D4'>"..s[5].a or "").."</p></font>",n,386.5,160,50,50,-1,16777215,0.9,false)
  154.     ui.addTextArea(6,"<p align='center'>"..(s[6].a == "X" and "<font size='42' color='#F52E2E'>"..s[6].a.."" or s[6].a == "O" and "<font size='40' color='#5CA4D4'>"..s[6].a or "").."</p></font>",n,446.5,160,50,50,-1,16777215,0.9,false)
  155.     ui.addTextArea(7,"<p align='center'>"..(s[7].a == "X" and "<font size='42' color='#F52E2E'>"..s[7].a.."" or s[7].a == "O" and "<font size='40' color='#5CA4D4'>"..s[7].a or "").."</p></font>",n,326.5,220,50,50,-1,16777215,0.9,false)
  156.     ui.addTextArea(8,"<p align='center'>"..(s[8].a == "X" and "<font size='42' color='#F52E2E'>"..s[8].a.."" or s[8].a == "O" and "<font size='40' color='#5CA4D4'>"..s[8].a or "").."</p></font>",n,386.5,220,50,50,-1,16777215,0.9,false)
  157.     ui.addTextArea(9,"<p align='center'>"..(s[9].a == "X" and "<font size='42' color='#F52E2E'>"..s[9].a.."" or s[9].a == "O" and "<font size='40' color='#5CA4D4'>"..s[9].a or "").."</p></font>",n,446.5,220,50,50,-1,16777215,0.9,false)
  158.   end
  159. end
  160.  
  161. function RefrchNames(n)
  162.   ui.addTextArea(10,"<p align='center'>["..chair[1].player.."]",n,-5,340,90,20,nil,nil,0,true)
  163.   tfm.exec.setNameColor (chair[1].player,0xF52E2E)
  164.   ui.addTextArea(20,"<p align='center'>["..chair[2].player.."]",n,720,340,90,20,nil,nil,0,true)
  165.   tfm.exec.setNameColor (chair[2].player,0x5CA4D4)
  166. end
  167.  
  168. function eventNewPlayer(n)
  169.   mice = mice + 1
  170.   for i,key in pairs({32}) do
  171.     tfm.exec.bindKeyboard(n,key,true,true)  
  172.     system.bindMouse(n,true)
  173.   end
  174.   Menu(n)
  175.   RefrchNames(n)
  176.   tfm.exec.respawnPlayer(n)
  177.   tfm.exec.movePlayer(n,tb_moves[math.random(#tb_moves)],320)
  178.   RP()
  179.   tfm.exec.setNameColor (n,0xFFCB00)
  180.   tfm.exec.chatMessage(welcome_msg,n)
  181.   ui.addTextArea(-1, "<p align='center'><a href='event:show'>Menu »</a></p>", n, 10, 30, 60, 18, 0x142b2e, 0x8a583c, 1, true)
  182. end
  183.  
  184. for n in pairs (tfm.get.room.playerList) do
  185.   mice = mice + 1
  186.   for i,key in pairs({32}) do
  187.     tfm.exec.bindKeyboard(n,key,true,true)  
  188.     system.bindMouse(n,true)
  189.     tfm.exec.chatMessage(welcome_msg,n)
  190.   end
  191.   ui.addTextArea(-1, "<p align='center'><a href='event:show'>Menu »</a></p>", n, 10, 30, 60, 18, 0x142b2e, 0x8a583c, 1, true)
  192. end
  193.  
  194.  
  195.  
  196. function open_help(n,page)
  197.   if page == 1 then
  198.     ui.addTextArea(-800, "<a href='event:help_cmd'>Commands</a>", n, 175, 123, 100, 20, 0x3f2b1d, 0x1f1813, 1, true)
  199.     ui.addTextArea(-801, "\nWelcome to <vp>Tic-Tac-Toc</vp> game.\n\n\n\nChoose a chair and press spacebar and use the mouse to play the game.\n<p align='center'><font size='100'>#<font color='#F52E2E'>X<font color='#5CA4D4'>O</font></p>\n", n, 252, 103, 293, 220, 0x142b2e, 0x8a583c, 1, true)
  200.   elseif page == 2 then
  201.     ui.addTextArea(-800, "<a href='event:help_open'>Home</a>", n, 207, 123, 100, 20, 0x3f2b1d, 0x1f1813, 1, true)
  202.     ui.addTextArea(-801, "\n<p align='center'><font size='20'>Commands</p><p align='left'>\n<j>General commands :</j>\n  !help : Display info about the minigame.\n", n, 252, 103, 293, 220, 0x142b2e, 0x8a583c, 1, true)
  203.   end
  204.   ui.addTextArea(-802, "<p align='center'>Help</p>", n, 248, 81, 305, 21, 0x3f2b1d, 0x1f1813, 1, true)
  205.   ui.addTextArea(-803, "<p align='center'><a href='event:help_close'>X</a></p>", n, 529, 83, 29, 18, 0x324650, 0x000000, 0, true)
  206. end
  207.  
  208.  
  209. function eventTextAreaCallback(id,n,event)
  210.   if event == "show" then
  211.     ui.addTextArea(-1, "<p align='center'><j><a href='event:hide'>Menu «</a></j>  |  <a href='event:help_open'>Help</a>", n, 10, 30, 120, 18, 0x142b2e, 0x8a583c, 1, true)
  212.   elseif event == "hide" then
  213.     ui.addTextArea(-1, "<p align='center'><a href='event:show'>Menu »</a></p>", n, 10, 30, 60, 18, 0x142b2e, 0x8a583c, 1, true)
  214.   elseif event == "help_open" then
  215.     open_help(n,1)
  216.   elseif event == "help_cmd" then
  217.     open_help(n,2)
  218.   elseif event == "help_close" then
  219.     for i=800,803 do
  220.       ui.removeTextArea(-1*i, n)
  221.     end
  222.   end
  223. end
  224.  
  225.  
  226.  
  227. function eventKeyboard(n,key,down,Px,Py)
  228.   if key == 32 and canSpace then
  229.     if ((Px > chair[1].x1 and Px < chair[1].x2) and (Py > chair[1].y1 and Py < chair[1].y2)) and not chair[1].boolean and n ~= chair[2].player then
  230.         selectPlayer(n,1)
  231.     elseif ((Px > chair[2].x1 and Px < chair[2].x2) and (Py > chair[2].y1 and Py < chair[2].y2)) and not chair[2].boolean and n ~= chair[1].player then
  232.         selectPlayer(n,2)
  233.     end
  234.     RefrchNames(nil)
  235.   end
  236. end
  237.  
  238. function RP()
  239.   if chair[1].player ~= "Space" or chair[2].player ~= "Space" then
  240.     ui.addTextArea(100,"",nil,(chair[1].bl and 9 or 730),268,65,65,-1,-1,1,true)
  241.   else
  242.     ui.removeTextArea(100, nil)
  243.   end
  244. end
  245.  
  246. function eventMouse(n,Mx,My)
  247.   id=numberSquare(n,Mx,My)
  248.   s=square
  249.   nn=0
  250.   if (n == chair[1].player or n == chair[2].player) and (chair[1].player ~= "Space" and chair[2].player ~= "Space") and (id ~= nil) and square[id].a == "" and chair[n == chair[1].player and 1 or 2].bl then
  251.     square[id].a=(n == chair[1].player and "X" or n == chair[2].player and "O")
  252.     chair[(n == chair[1].player and 1 or 2)].bl=false
  253.     chair[(n == chair[1].player and 2 or 1)].bl=true
  254.     RP()
  255.     Menu(nil)
  256.     if ConSy("type") ~= nil and ConSy("id") ~= nil then
  257.       WinPlayer(ConSy("type"),ConSy("id"))
  258.     end
  259.    
  260.     for i=1,#s do
  261.       if s[i].a ~= "" then
  262.         nn=nn+1
  263.       end
  264.     end
  265.     if (nn == 9) and (ConSy("type") == nil and ConSy("id") == nil) then
  266.       for i=1,9 do
  267.         ui.removeTextArea(i, nil)
  268.       end
  269.       t=19
  270.       NewGame=true
  271.     end
  272.   end
  273. end
  274.  
  275. function selectPlayer(n,id)
  276.   if id == 1 then
  277.     tfm.exec.chatMessage("<vp>"..n.."</vp><j> is playing with <font color='#FF2300'>X</font></j> !")
  278.   else
  279.     tfm.exec.chatMessage("<vp>"..n.."</vp><j> is playing with <font color='#0094FF'>O</font></j> !")
  280.   end
  281.   chair[id].player=n
  282.   chair[id].boolean=true
  283.   RefrchNames(n)
  284.   if chair[1].player ~= "Space" and chair[2].player ~= "Space" then
  285.     canSpace=false
  286.     Menu(nil)
  287.     chair[1].bl=true
  288.     RP()
  289.   end
  290. end
  291.  
  292.  
  293. function eventPlayerDied(n)
  294.   Menu(n)
  295.   RefrchNames(n)
  296.   tfm.exec.respawnPlayer(n)
  297.   RP()
  298.   tfm.exec.setNameColor (n,0xFFCB00)
  299. end
  300.  
  301. function eventPlayerLeft(n)
  302.   if n == chair[1].player or n == chair[2].player then
  303.     nameW = (n == chair[1].player and chair[2].player or chair[1].player)
  304.     giveGiftsWon(nameW)
  305.     NewGame=true
  306.     t=6
  307.   end
  308.   mice = mice - 1
  309. end
  310.  
  311. function eventChatCommand(n,cmd)
  312.   if cmd == "skip" and n == "Turkitutu" then
  313.     t=19
  314.     NewGame=true
  315.   end
  316.   if cmd == "help" then
  317.     eventTextAreaCallback(0,n,"help_open")
  318.   end
  319. end
  320.  
  321. tfm.exec.newGame(map)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement