Advertisement
Guest User

Untitled

a guest
Jun 29th, 2017
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.59 KB | None | 0 0
  1. builder = "НИК"
  2.  
  3. look = 0
  4.  
  5. --[[
  6. 0 = wood
  7. 1 = ice
  8. 2 = tramp
  9. 3 = lava
  10. 4 = choc
  11. ]]
  12.  
  13. custom = false
  14.  
  15. fric = 0.3 -- friction
  16. res = 0.2 -- restitution
  17. col = nil -- color
  18. hei = 10 -- height
  19.  
  20. fric_stored = 0
  21. res_stored = 0
  22. col_stored = nil
  23.  
  24. point_x=nil
  25. point_y=nil
  26.  
  27. gNum = 0
  28.  
  29. system.bindMouse(builder, true)
  30.  
  31. for _,v in pairs({32, 8, 49, 50, 51, 52, 53, 54}) do
  32. tfm.exec.bindKeyboard(builder, v, true, true)
  33. end
  34.  
  35. system.disableChatCommandDisplay("height", true)
  36. system.disableChatCommandDisplay("custom", true)
  37.  
  38. function eventMouse(name, x, y)
  39. tfm.exec.displayParticle(9, x, y, 0, 0, 0, 0)
  40. if point_x == nil then
  41. point_x = x
  42. point_y = y
  43. else
  44. makeGround(x,y,length(point_x,point_y,x,y), angle(point_x, point_y,x,y))
  45. end
  46. end
  47.  
  48. function eventNewGame()
  49. gNum = 0
  50. point_x=nil
  51. point_y=nil
  52. end
  53.  
  54. function eventChatCommand(name, cmd)
  55. local args = {}
  56. for arg in cmd:gmatch("%S+") do
  57. table.insert(args, arg)
  58. end
  59. if args[1] == "custom" then
  60. ui.addPopup(1, 2, "Restitution:", name, 726, 20, 70)
  61. system.bindMouse(builder, false)
  62. point_x=nil
  63. point_y=nil
  64. col=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, 646, 20, 150)
  80. elseif id == 3 then
  81. if answer:len() > 5 then
  82. col = '0x'..answer
  83. end
  84. ui.addPopup(4, 1, "Would you like to add this to a hotkey (6)?", name, 551, 20, 245)
  85. elseif id == 4 then
  86. if answer == "yes" then
  87. fric_stored = fric
  88. res_stored = res
  89. col_stored = col
  90. custom = true
  91. end
  92. system.bindMouse(builder, true)
  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