Advertisement
daaa

Untitled

Jun 19th, 2017
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.29 KB | None | 0 0
  1. MaxDistance = 512
  2. Tool = script.Parent
  3. TouchDamage = 99
  4. DirectDamage = 99
  5.  
  6. function fireLaser(pos, target, obj)
  7. local part = Instance.new("Part")
  8. part.Anchored = true
  9. part.CanCollide = false
  10. part.formFactor = "Symmetric"
  11. part.TopSurface = 0
  12. part.BottomSurface = 0
  13. part.BrickColor = BrickColor.new("Institutional white")
  14. part.Transparency = 0.5
  15. part.Name = "Laser Shot"
  16. part.Locked = true
  17. part.Size = Vector3.new(1,1,(pos - obj.Position).magnitude)
  18. part.CFrame = CFrame.new(((obj.Position + pos)/2) + 1 * (pos - obj.Position).unit, pos)
  19.  
  20. local mesh = Instance.new("BlockMesh")
  21. mesh.Scale = Vector3.new(3,3,1)
  22. mesh.Parent = part
  23.  
  24. part.Parent = workspace
  25. --Optional: Laser will damage others than the target.
  26. --part.Touched:connect(onTouch)
  27. local h = getHumanoid(target.Parent)
  28. local player = game.Players:findFirstChild(Tool.Parent.Name)
  29. if player ~= nil and h ~= nil and target.Parent ~= Tool.Parent then
  30. tagHumanoid(h, player)
  31. h:takeDamage(DirectDamage)
  32. wait(0.05)
  33. untagHumanoid(h)
  34. elseif player ~= nil and h==nil and target.Parent ~= Tool.Parent then
  35. if target:getMass() <= 216 then
  36. burn(target, part)
  37. end
  38. else
  39. getTarget(pos)
  40. end
  41.  
  42. for v=1, 10 do
  43. part.Transparency = 0.1 * v
  44. wait(0.05)
  45. end
  46.  
  47.  
  48. part:remove()
  49. end
  50.  
  51. function burn(obj, laser)
  52. print 'damaged'
  53. end
  54.  
  55. function getTarget(pos)
  56. local child = workspace:getChildren()
  57. for i,v in pairs(child) do
  58. local h = getHumanoid(v)
  59. if h ~= nil and v ~= Tool.Parent then
  60. local torso = v:findFirstChild("Torso")
  61. if torso ~= nil then
  62. if (torso.Position - pos).magnitude <= 3 then
  63. local player = game.Players:findFirstChild(Tool.Parent.Name)
  64. if player ~= nil then
  65. tagHumanoid(h, player)
  66. end
  67. h:takeDamage(DirectDamage)
  68. wait(0.05)
  69. untagHumanoid(h)
  70. end
  71. end
  72. end
  73. end
  74. end
  75.  
  76.  
  77. function getHumanoid(obj)
  78. local child = obj:getChildren()
  79. for i=1, #child do
  80. if child[i].className == "Humanoid" then
  81. return child[i]
  82. end
  83. end
  84. return nil
  85. end
  86.  
  87. db = false
  88. function onTouch(hit)
  89. if db then return end
  90. db = true
  91. if hit.Parent ~= Tool.Parent then
  92. local h = getHumanoid(hit.Parent)
  93. if h ~= nil then
  94. local player = game.Players:findFirstChild(Tool.Parent.Name)
  95. if player ~= nil then
  96. tagHumanoid(h, player)
  97. end
  98. h:takeDamage(TouchDamage)
  99. wait(0.1)
  100. untagHumanoid(h)
  101. end
  102. end
  103. wait(0.9)
  104. db = false
  105. end
  106.  
  107.  
  108. function tagHumanoid(humanoid, player)
  109. local creator_tag = Instance.new("ObjectValue")
  110. creator_tag.Value = player
  111. creator_tag.Name = "creator"
  112. creator_tag.Parent = humanoid
  113. end
  114.  
  115. function untagHumanoid(humanoid)
  116. if humanoid ~= nil then
  117. local tag = humanoid:findFirstChild("creator")
  118. if tag ~= nil then
  119. tag.Parent = nil
  120. end
  121. end
  122. end
  123.  
  124. enabled = true
  125. function onActivated(mouse)
  126. if not enabled or mouse.Target == nil then return end
  127. enabled = false
  128. local handle = Tool:findFirstChild("Particle")
  129. local human = Tool.Parent:findFirstChild("Humanoid")
  130. if handle ~= nil and human ~= nil then
  131. if (handle.Position - human.TargetPoint).magnitude <= MaxDistance then
  132. script.Parent.Closed1.Transparency = 1
  133. script.Parent.Closed2.Transparency = 1
  134. script.Parent.Open1.Transparency = 0
  135. script.Parent.Open2.Transparency = 0
  136. script.Parent.Eye2.Transparency = 1
  137. script.Parent.FirePart.Fire.Enabled = true
  138. script.Parent.Particle.ParticleEmitter.Enabled = true
  139. enabled = true
  140. wait(1)
  141. script.Parent.Eye2.Transparency = 0
  142. script.Parent.FirePart.Fire.Enabled = false
  143. script.Parent.Closed1.Transparency = 0
  144. script.Parent.Closed2.Transparency = 0
  145. script.Parent.Open1.Transparency = 1
  146. script.Parent.Open2.Transparency = 1
  147. script.Parent.Particle.ParticleEmitter.Enabled = false
  148. fireLaser(human.TargetPoint, mouse.Target, handle)
  149. end
  150. end
  151. end
  152.  
  153. mouseabled = true
  154. function onButton1Down(mouse)
  155. if not mouseabled or mouse.Target == nil then return end
  156. mouseabled = false
  157. mouse.Icon = "rbxasset://textures/GunWaitCursor.png"
  158. wait(0.5)
  159. mouseabled = true
  160. mouse.Icon = "rbxasset://textures/GunCursor.png"
  161. end
  162.  
  163. zoom = false
  164. function onKeyDown(key)
  165. key:lower()
  166. if key == "q" then
  167. if not zoom then
  168. zoom = true
  169.  
  170. local obj = Instance.new("Part")
  171. obj.Parent = Tool.Parent
  172. obj.Size = Vector3.new(1,1,1)
  173. obj.Transparency = 1
  174. obj.CanCollide = false
  175. obj.Anchored = true
  176. obj.Name = "Zoom"
  177. obj.CFrame = CFrame.new(Tool.Parent.Humanoid.TargetPoint)
  178.  
  179. cam = workspace.CurrentCamera:Clone()
  180. cam.Parent = workspace
  181. workspace.CurrentCamera.CameraSubject = obj
  182. workspace.CurrentCamera.CameraType = 4
  183. else
  184. zoom = false
  185.  
  186. local check = Tool.Parent:findFirstChild("Zoom")
  187. if check ~= nil then
  188. check:remove()
  189. end
  190.  
  191. workspace.CurrentCamera.CameraSubject = Tool.Parent.Humanoid
  192. workspace.CurrentCamera:Remove()
  193. workspace.CurrentCamera = cam
  194. end
  195. end
  196. end
  197.  
  198. function onSelected(mouse)
  199. connection = script.Parent.Activated:connect(function() onActivated(mouse) end)
  200. mouse.KeyDown:connect(onKeyDown)
  201. mouse.Button1Down:connect(function() onButton1Down(mouse) end)
  202.  
  203. mouse.Icon = "rbxasset://textures/GunCursor.png"
  204. end
  205.  
  206. function onDeselected()
  207. connection:disconnect()
  208. end
  209.  
  210. script.Parent.Equipped:connect(onSelected)
  211. script.Parent.Unequipped:connect(onDeselected)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement