Advertisement
Eliaseeg

Football

Aug 7th, 2015
384
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.11 KB | None | 0 0
  1. local map = '<C><P L="2000" /><Z><S><S L="21" o="b0c6d1" H="399" X="11" Y="200" T="12" P="0,0,0.3,0.2,0,0,0,0" /><S P="0,0,0.3,0.2,0,0,0,0" L="21" o="b0c6d1" X="1990" Y="200" T="12" H="399" /><S L="21" o="b0c6d1" X="1001" H="2000" Y="390" T="12" P="0,0,0.3,0.2,90,0,0,0" /></S><D /><O /></Z></C>'
  2. local taked = false
  3. local mice = {}
  4. local ball
  5. local haveTheBall
  6.  
  7. function main()
  8.     tfm.exec.disableAutoShaman(true)
  9.     tfm.exec.disableAutoNewGame(true)
  10.     tfm.exec.disableAutoTimeLeft(true)
  11.     math.randomseed(os.time())
  12.     tfm.exec.newGame(map)
  13.     table.foreach(tfm.get.room.playerList, eventNewPlayer)
  14.     ball = tfm.exec.addShamanObject(601, 1000, 100, 0, 0, 0, true)
  15. end
  16.  
  17. function eventNewPlayer(name)
  18.     local pos = {
  19.         {1100, 300},
  20.         {900, 300}
  21.     }
  22.     mice[name] = {
  23.         haveBall = false
  24.     }
  25.     tfm.exec.movePlayer(name, pos[math.random(#pos)][1], pos[math.random(#pos)][2])
  26.     for i=1,100 do
  27.         tfm.exec.bindKeyboard(name, i, true, true)
  28.     end
  29. end
  30.  
  31. function eventKeyboard(name, key, down, mouseX, mouseY)
  32.     if key == 32 then
  33.         if not taked then
  34.             if pythag(mouseX, mouseY, tfm.get.room.objectList[ball].x, tfm.get.room.objectList[ball].y, 40) and not mice[name].haveBall then
  35.                 particles(3, mouseX, mouseY)
  36.                 tfm.exec.removeObject(ball)
  37.                 haveTheBall = name
  38.                 mice[name].haveBall = true
  39.                 taked = true
  40.             end
  41.         else
  42.             if name ~= haveTheBall then
  43.                 if pythag(mouseX, mouseY, tfm.get.room.playerList[haveTheBall].x, tfm.get.room.playerList[haveTheBall].y, 20) then
  44.                     mice[haveTheBall].haveBall = false
  45.                     taked = true
  46.                     mice[name].haveBall = true
  47.                     haveTheBall = name
  48.                     particles(3, mouseX, mouseY)
  49.                 end
  50.             else
  51.                 ball = tfm.exec.addShamanObject(601, mouseX, mouseY, 5, 5, 0, true)
  52.                 mice[haveTheBall].haveBall = false
  53.                 particles(3, mouseX, mouseY)
  54.                 taked = false
  55.                 haveTheBall = nil
  56.             end
  57.         end
  58.     end
  59. end
  60.  
  61. function particles(id, x, y)
  62.     for i=1,3 do
  63.         tfm.exec.displayParticle(id, x, y, math.random(-3,3), -9, 0,math.random(8,15)/10, nil)
  64.     end
  65. end
  66.  
  67. function pythag(x1,y1,x2,y2,r)
  68.     local x=x2-x1
  69.     local y=y2-y1
  70.     local r=r+r
  71.     return x*x+y*y<r*r
  72. end
  73.  
  74. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement