Advertisement
Hachem16

Build battle v2

Dec 20th, 2015
936
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 9.34 KB | None | 0 0
  1. admin = "Abdeltif"
  2. default = {width = 50, height = 50}
  3. prot = {}
  4. prot[0] = {
  5.     type = 0,
  6.     width = default.width,
  7.     height = default.height,
  8.     foreground = false,
  9.     friction = 0.3,
  10.     restitution = 0.2,
  11.     angle = 0,
  12.     miceCollision = true,
  13.     groundCollision = true,
  14.     dynamic = false,
  15.     fixedRotation = false,
  16.     mass = 0,
  17.     linearDamping = 0,
  18.     angularDamping = 0,
  19. }
  20. prot[1] = {
  21.     type = 1,
  22.     width = default.width,
  23.     height = default.height,
  24.     foreground = false,
  25.     friction = 0,
  26.     restitution = 0.2,
  27.     angle = 0,
  28.     miceCollision = true,
  29.     groundCollision = true,
  30.     dynamic = false,
  31.     fixedRotation = false,
  32.     mass = 0,
  33.     linearDamping = 0,
  34.     angularDamping = 0,
  35. }
  36. prot[2] = {
  37.     type = 2,
  38.     width = default.width,
  39.     height = default.height,
  40.     foreground = false,
  41.     friction = 0,
  42.     restitution = 1.2,
  43.     angle = 0,
  44.     miceCollision = true,
  45.     groundCollision = true,
  46.     dynamic = false,
  47.     fixedRotation = false,
  48.     mass = 0,
  49.     linearDamping = 0,
  50.     angularDamping = 0,
  51. }
  52. prot[3] = {
  53.     type = 3,
  54.     width = default.width,
  55.     height = default.height,
  56.     foreground = false,
  57.     friction = 0,
  58.     restitution = 20,
  59.     angle = 0,
  60.     miceCollision = true,
  61.     groundCollision = true,
  62.     dynamic = false,
  63.     fixedRotation = false,
  64.     mass = 0,
  65.     linearDamping = 0,
  66.     angularDamping = 0,
  67. }
  68. prot[4] = {
  69.     type = 4,
  70.     width = default.width,
  71.     height = default.height,
  72.     foreground = false,
  73.     friction = 20,
  74.     restitution = 0.2,
  75.     angle = 0,
  76.     miceCollision = true,
  77.     groundCollision = true,
  78.     dynamic = false,
  79.     fixedRotation = false,
  80.     mass = 0,
  81.     linearDamping = 0,
  82.     angularDamping = 0,
  83. }
  84. prot[5] = {
  85.     type = 5,
  86.     width = default.width,
  87.     height = default.height,
  88.     foreground = false,
  89.     friction = 0.3,
  90.     restitution = 0.2,
  91.     angle = 0,
  92.     miceCollision = true,
  93.     groundCollision = true,
  94.     dynamic = false,
  95.     fixedRotation = false,
  96.     mass = 0,
  97.     linearDamping = 0,
  98.     angularDamping = 0,
  99. }
  100. prot[6] = {
  101.     type = 6,
  102.     width = default.width,
  103.     height = default.height,
  104.     foreground = false,
  105.     friction = 0.3,
  106.     restitution = 0.2,
  107.     angle = 0,
  108.     miceCollision = true,
  109.     groundCollision = true,
  110.     dynamic = false,
  111.     fixedRotation = false,
  112.     mass = 0,
  113.     linearDamping = 0,
  114.     angularDamping = 0,
  115. }
  116. prot[7] = {
  117.     type = 7,
  118.     width = default.width,
  119.     height = default.height,
  120.     foreground = false,
  121.     friction = 0.1,
  122.     restitution = 0.2,
  123.     angle = 0,
  124.     miceCollision = true,
  125.     groundCollision = true,
  126.     dynamic = false,
  127.     fixedRotation = false,
  128.     mass = 0,
  129.     linearDamping = 0,
  130.     angularDamping = 0,
  131. }
  132. prot[8] = {
  133.     type = 8,
  134.     width = default.width,
  135.     height = default.height,
  136.     foreground = false,
  137.     friction = 0.3,
  138.     restitution = 0.2,
  139.     angle = 0,
  140.     miceCollision = false,
  141.     groundCollision = true,
  142.     dynamic = false,
  143.     fixedRotation = false,
  144.     mass = 0,
  145.     linearDamping = 0,
  146.     angularDamping = 0,
  147. }
  148. prot[9] = {
  149.     type = 9,
  150.     width = default.width,
  151.     height = default.height,
  152.     foreground = false,
  153. }
  154. prot[10] = {
  155.     type = 10,
  156.     width = default.width,
  157.     height = default.height,
  158.     foreground = false,
  159.     friction = 0.3,
  160.     restitution = 0,
  161.     angle = 0,
  162.     miceCollision = true,
  163.     groundCollision = true,
  164.     dynamic = false,
  165.     fixedRotation = false,
  166.     mass = 0,
  167.     linearDamping = 0,
  168.     angularDamping = 0,
  169. }
  170. prot[11] = {
  171.     type = 11,
  172.     width = default.width,
  173.     height = default.height,
  174.     foreground = false,
  175.     friction = 0.05,
  176.     restitution = 0.1,
  177.     angle = 0,
  178.     miceCollision = true,
  179.     groundCollision = true,
  180.     dynamic = false,
  181.     fixedRotation = false,
  182.     mass = 0,
  183.     linearDamping = 0,
  184.     angularDamping = 0,
  185. }
  186. prot[12] = {
  187.     type = 12,
  188.     width = default.width,
  189.     height = default.height,
  190.     color = 0x5F58F2,
  191.     foreground = false,
  192.     friction = 0.3,
  193.     restitution = 0.2,
  194.     angle = 0,
  195.     miceCollision = true,
  196.     groundCollision = true,
  197.     dynamic = false,
  198.     fixedRotation = false,
  199.     mass = 0,
  200.     linearDamping = 0,
  201.     angularDamping = 0,
  202. }
  203. prot[13] = {
  204.     type = 13,
  205.     width = default.width,
  206.     color = 0x0FF0F0,
  207.     foreground = false,
  208.     friction = 0.3,
  209.     restitution = 0.2,
  210.     angle = 0,
  211.     miceCollision = true,
  212.     groundCollision = true,
  213.     dynamic = false,
  214.     fixedRotation = false,
  215.     mass = 0,
  216.     linearDamping = 0,
  217.     angularDamping = 0,
  218. }
  219. id = 0
  220. gnum = 1
  221. players = {}
  222. sparkles = {}
  223. roles = {
  224.     "many",
  225.     "whole"
  226. }
  227. grounds = {
  228.     wood = 0,
  229.     ice = 1,
  230.     trampoline = 2,
  231.     lava = 3,
  232.     chocolate = 4,
  233.     earth = 5,
  234.     grass = 6,
  235.     sand = 7,
  236.     cloud = 8,
  237.     water = 9,
  238.     stone = 10,
  239.     snow = 11,
  240.     rectangle = 12,
  241.     circle = 13,
  242. }
  243. function eventNewPlayer(name)
  244.     system.bindMouse(name, true)
  245.     system.bindKeyboard(name, 17 , false, true)
  246.     players[name] = {mode = "whole", ids = {}, gtype = 1, color = 0xF45F63, hold = false, height = 10}
  247. end
  248. function eventKeyboard(name, key, down, x, y)
  249.     if key == 17 and down then
  250.         players[name].hold = true
  251.         system.bindKeyboard(name, 17, false, true)
  252.     elseif key==17 and not down then
  253.         players[name].hold = false
  254.         system.bindKeyboard(name, 17, true, true)
  255.     end
  256. end
  257. function eventPlayerLeft(name)
  258.     for k,v in pairs(players[name].ids) do
  259.         tfm.exec.removePhysicObject(v)
  260.         gnum = gnum - 1
  261.     end
  262.     players[name] = nil
  263. end
  264. function getPlayerNumber()
  265.     local n = 0
  266.     for k,v in pairs(players) do
  267.         n = n + 1
  268.     end
  269.     return n
  270. end
  271.  
  272. function eventMouse(name, x, y)
  273.     if players[name].hold and players[name].started_drawing then
  274.         players[name].firstPoint = players[name].lastPoint
  275.         players[name].lastPoint = {x=x, y=y}
  276.         role_f[players[name].mode](name, players[name].firstPoint.x,players[name].firstPoint.y,players[name].lastPoint.x,players[name].lastPoint.y)
  277.         players[name].firstPoint = nil
  278.     elseif players[name].firstPoint then
  279.         players[name].lastPoint = {x=x, y=y}
  280.         role_f[players[name].mode](name, players[name].firstPoint.x,players[name].firstPoint.y,players[name].lastPoint.x,players[name].lastPoint.y)
  281.         players[name].firstPoint = nil
  282.         players[name].started_drawing = true
  283.     else
  284.         players[name].firstPoint = {x=x, y=y}
  285.     end
  286. end
  287.  
  288. function ground_draw(name, x, y, x2, y2)
  289.     if players[name].laser then
  290.         for i=players[name].laser.start, players[name].laser.stop do
  291.             gnum = gnum - 1
  292.             tfm.exec.removePhysicObject(i)
  293.         end
  294.     end
  295.     local num = math.ceil(430/(getPlayerNumber()*2.5))
  296.     local xlenght = x2-x
  297.     local ylenght = y2-y
  298.     local lenght = math.sqrt((xlenght^2)+(ylenght^2))
  299.     local angle = math.deg(math.atan(ylenght/xlenght))
  300.     local ground = prot[players[name].gtype] or {}
  301.     ground.width = 10
  302.     ground.height = players[name].height
  303.     ground.angle = angle
  304.     ground.color = players[name].color
  305.     players[name].laser = {start = id}
  306.     for i=0,num do
  307.         local lx = xlenght/num * i + x
  308.         local ly = ylenght/num * i + y
  309.         local lx = math.abs(lx)
  310.         local ly = math.abs(ly)
  311.         if gnum < 430 then
  312.             players[name].ids[#players[name].ids+1] = id
  313.             tfm.exec.addPhysicObject(id, lx, ly, ground)
  314.             id = id + 1
  315.             gnum = gnum + 1
  316.         else
  317.             break
  318.         end
  319.     end
  320.     players[name].laser.stop = id
  321. end
  322. function whole_ground_draw(name, x, y, x2, y2)
  323.     local num = 30
  324.     local xlenght = x2-x
  325.     local ylenght = y2-y
  326.     local lenght = math.sqrt((xlenght^2)+(ylenght^2))
  327.     local angle = math.deg(math.atan(ylenght/xlenght))
  328.     local joint = {
  329.     type=0,
  330.     point1=x..","..y,
  331.     point2=x2..","..y2,
  332.     frequency=10,
  333.     damping=0.2,
  334.     line=5,
  335.     color= 0xFF2222,
  336.     alpha=1,
  337.     foreground=true
  338. }
  339.     local lx = x+xlenght/2
  340.     local ly = y+ylenght/2
  341.     local width  = lenght
  342.     local ground = prot[players[name].gtype] or {}
  343.     ground.angle = angle
  344.     ground.width = width
  345.     ground.height = players[name].height
  346.     ground.color = players[name].color
  347.     if gnum < 430 then
  348.         players[name].ids[#players[name].ids+1] = id
  349.         tfm.exec.addPhysicObject(id , lx, ly, ground)
  350.         id = id + 1
  351.         gnum = gnum + 1
  352.     end
  353. end
  354. function eventChatCommand(name, cmd)
  355.     local args = {}
  356.     for arg in string.gmatch(cmd, "[%S]+") do
  357.         args[#args+1] = arg
  358.     end
  359.     if args[1] == "undo" then
  360.         if type(tonumber(args[2]))=="number" then
  361.             local num = (#players[name].ids - tonumber(args[2])+1)>=1 and (#players[name].ids-tonumber(args[2])+1) or 1
  362.             for i=#players[name].ids,num, -1 do
  363.                 tfm.exec.removePhysicObject(players[name].ids[i])
  364.                 players[name].ids[i] = nil
  365.                 gnum = gnum - 1
  366.             end
  367.         elseif args[2] == "all" then
  368.             for i=1,#players[name].ids do
  369.                 tfm.exec.removePhysicObject(players[name].ids[i])
  370.                 players[name].ids[i] = nil
  371.                 gnum = gnum - 1
  372.             end
  373.         else
  374.             tfm.exec.removePhysicObject(players[name].ids[#players[name].ids])
  375.             players[name].ids[#players[name].ids] = nil
  376.             gnum = gnum - 1
  377.         end
  378.     elseif args[1] == "clear" and name == admin then
  379.         for i=1,id do
  380.             tfm.exec.removePhysicObject(i)
  381.             gnum = gnum - 1
  382.         end
  383.         for k,v in pairs(players) do
  384.             players[k].ids = {}
  385.         end
  386.     elseif args[1] == "set" then
  387.         if args[2] == "mode" then
  388.             if role_f[args[3]] then
  389.                 players[name].mode = args[3]
  390.             end
  391.         elseif args[2] == "ground" then
  392.             if tonumber(args[3]) then
  393.                 players[name].gtype = args[3]
  394.             elseif grounds[args[3]] then
  395.                 players[name].gtype = grounds[args[3]]
  396.             end
  397.         elseif args[2] == "color" then
  398.             ui.showColorPicker(1, name, players[name].color, "Choose!")
  399.         elseif args[2] == "height" then
  400.             if tonumber(args[3]) then
  401.                 players[name].height = tonumber(args[3])
  402.             end
  403.         end
  404.     end
  405. end
  406. function eventColorPicked(id ,name, color)
  407.     if id == 1 then
  408.         players[name].color = color
  409.     end
  410. end
  411. function init()
  412.     role_f = {
  413.         many = ground_draw,
  414.         whole = whole_ground_draw,
  415.     }
  416. end
  417. init()
  418. for k,v in pairs({"set", "undo", "clear"}) do system.disableChatCommandDisplay(v, true) end
  419. for k,v in pairs(tfm.get.room.playerList) do eventNewPlayer(k) end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement