Advertisement
Guest User

Construction script

a guest
Jul 20th, 2015
16
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.62 KB | None | 0 0
  1.  
  2. builder = "Username" -- REPLACE WITH YOUR OWN USERNAME (EG "Jamesqwartz")
  3.  
  4. look = 0
  5.  
  6. --[[
  7.  0 = wood
  8.  1 = ice
  9.  2 = tramp
  10.  3 = lava
  11.  4 = choc
  12. ]]
  13.  
  14. custom = false
  15.  
  16. fric = 0.3 -- friction
  17. res = 0.2 -- restitution
  18. col = nil -- color
  19. hei = 10 -- height
  20.  
  21. fric_stored = 0
  22. res_stored = 0
  23. col_stored = nil
  24.  
  25. point_x=nil
  26. point_y=nil
  27.  
  28. gNum = 0
  29.  
  30. system.bindMouse(builder, true)
  31.  
  32. for _,v in pairs({32, 8, 49, 50, 51, 52, 53, 54}) do
  33.     tfm.exec.bindKeyboard(builder, v, true, true)
  34. end
  35.  
  36. system.disableChatCommandDisplay("height", true)
  37. system.disableChatCommandDisplay("custom", true)
  38.  
  39. function eventMouse(name, x, y)
  40.     tfm.exec.displayParticle(9, x, y, 0, 0, 0, 0)
  41.     if point_x == nil then
  42.         point_x = x
  43.         point_y = y
  44.     else
  45.         makeGround(x,y,length(point_x,point_y,x,y), angle(point_x, point_y,x,y))
  46.     end
  47. end
  48.  
  49. function eventNewGame()
  50.     gNum = 0
  51.     point_x=nil
  52.     point_y=nil
  53. end
  54.  
  55. function eventChatCommand(name, cmd)
  56.     local args = {}
  57.     for arg in cmd:gmatch("%S+") do
  58.         table.insert(args, arg)
  59.     end
  60.     if args[1] == "custom" then
  61.         ui.addPopup(1, 2, "Restitution:", name, 726, 20, 70)
  62.         system.bindMouse(builder, false)
  63.         point_x=nil
  64.         point_y=nil
  65.         look = 12
  66.     elseif args[1] == "height" then
  67.         if args[2] then
  68.             hei = tonumber(args[2]) or 0
  69.         end
  70.     end
  71. end
  72.  
  73. function eventPopupAnswer(id, name, answer)
  74.     if id == 1 then
  75.         res = tonumber(answer)
  76.         ui.addPopup(2, 2, "Friction:", name, 726, 20, 70)
  77.     elseif id == 2 then
  78.         fric = tonumber(answer)
  79.         ui.addPopup(3, 2, "Colour eg. FF0000 (if left blank it will be invisible):", name, 700, 20)
  80.     elseif id == 3 then
  81.         system.bindMouse(builder, true)
  82.         if answer:len() > 5 then
  83.             col = '0x'..answer
  84.         end
  85.         ui.addPopup(4, 1, "Would you like to add this to a hotkey (6)?", name, 700, 20)
  86.     elseif id == 4 then
  87.         if answer == "yes" then
  88.             fric_stored = fric
  89.             res_stored  = res
  90.             col_stored = col
  91.             custom = true
  92.         end
  93.     end
  94. end
  95.  
  96. function eventKeyboard(name, key, down, x, y)
  97.     if key == 32 then
  98.         for i=1, gNum do
  99.             tfm.exec.removePhysicObject(i)
  100.         end
  101.         gNum = 0
  102.     elseif key == 8 then
  103.         tfm.exec.removePhysicObject(gNum)
  104.         gNum = gNum - 1
  105.     elseif key == 49 then
  106.         look = 0
  107.         fric = 0.3
  108.         res = 0.2
  109.         col = nil
  110.     elseif key == 50 then
  111.         look = 1
  112.         fric = 0
  113.         res  = 0.2
  114.         col = nil
  115.     elseif key == 51 then
  116.         look = 2
  117.         fric = 0
  118.         res = 1.2
  119.         col = nil
  120.     elseif key == 52 then
  121.         look = 3
  122.         fric = 0
  123.         res = 20
  124.         col = nil
  125.     elseif key == 53 then
  126.         look = 4
  127.         fric = 20
  128.         res = 0.2
  129.         col = nil
  130.     elseif key == 54 then
  131.         if custom then
  132.             look = 12
  133.             fric = fric_stored
  134.             res = res_stored
  135.             col = col_stored
  136.         end
  137.     end
  138. end
  139.  
  140. function makeGround(x,y,length,ang)
  141.     gNum = gNum + 1
  142.     final_x = ((x + point_x)/2)
  143.     final_y = ((y + point_y)/2)
  144.     tfm.exec.addPhysicObject(gNum, final_x, final_y, {type=look or 0, width=length, height = hei, angle=ang, color = col ,friction=fric or 0.3, restitution=res or 0.2})
  145.     point_x=nil
  146.     point_y=nil
  147. end
  148.  
  149. function length(x1, y1, x2, y2)
  150.     lx = (x2 - x1)^2
  151.     ly = (y2 - y1)^2
  152.     return math.sqrt(lx+ly)
  153. end
  154.  
  155. function angle(x1, y1, x2, y2)
  156.     lx = x2 - x1
  157.     ly = y2 - y1
  158.     return math.deg(math.atan2(ly,lx))
  159. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement