Guest User

Rocket Launcher

a guest
Feb 11th, 2020
5,443
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 26.67 KB | None | 0 0
  1.  
  2. --Converted with ttyyuu12345's model to script plugin v4
  3. function sandbox(var,func)
  4. local env = getfenv(func)
  5. local newenv = setmetatable({},{
  6. __index = function(self,k)
  7. if k=="script" then
  8. return var
  9. else
  10. return env[k]
  11. end
  12. end,
  13. })
  14. setfenv(func,newenv)
  15. return func
  16. end
  17. cors = {}
  18. mas = Instance.new("Model",game:GetService("Lighting"))
  19. Tool0 = Instance.new("Tool")
  20. Part1 = Instance.new("Part")
  21. SpecialMesh2 = Instance.new("SpecialMesh")
  22. Script3 = Instance.new("Script")
  23. Sound4 = Instance.new("Sound")
  24. Sound5 = Instance.new("Sound")
  25. Script6 = Instance.new("Script")
  26. LocalScript7 = Instance.new("LocalScript")
  27. Configuration8 = Instance.new("Configuration")
  28. NumberValue9 = Instance.new("NumberValue")
  29. IntValue10 = Instance.new("IntValue")
  30. NumberValue11 = Instance.new("NumberValue")
  31. IntValue12 = Instance.new("IntValue")
  32. IntValue13 = Instance.new("IntValue")
  33. IntValue14 = Instance.new("IntValue")
  34. ModuleScript15 = Instance.new("ModuleScript")
  35. Tool0.Name = "RocketLauncher"
  36. Tool0.Parent = mas
  37. Tool0.TextureId = "http://www.roblox.com/asset/?id=90021376"
  38. Tool0.CanBeDropped = false
  39. Tool0.Grip = CFrame.new(0.699999988, 0, -0.5, 0, 0, -1, -1, 0, 0, 0, 1, 0)
  40. Tool0.GripForward = Vector3.new(1, -0, -0)
  41. Tool0.GripPos = Vector3.new(0.699999988, 0, -0.5)
  42. Tool0.GripRight = Vector3.new(0, -1, 0)
  43. Tool0.GripUp = Vector3.new(0, 0, 1)
  44. Part1.Name = "Handle"
  45. Part1.Parent = Tool0
  46. Part1.CFrame = CFrame.new(-3.4439671, 2.42002392, -6.60587978, 1, 0, 0, 0, 6.30170107e-05, 1.00000024, 0, -1.00000024, 6.30170107e-05)
  47. Part1.Orientation = Vector3.new(-90, 0, 0)
  48. Part1.Position = Vector3.new(-3.4439671, 2.42002392, -6.60587978)
  49. Part1.Rotation = Vector3.new(-90, 0, 0)
  50. Part1.Size = Vector3.new(4.92000628, 0.740000546, 0.839999795)
  51. Part1.BottomSurface = Enum.SurfaceType.Smooth
  52. Part1.TopSurface = Enum.SurfaceType.Smooth
  53. Part1.FormFactor = Enum.FormFactor.Custom
  54. Part1.formFactor = Enum.FormFactor.Custom
  55. SpecialMesh2.Parent = Part1
  56. SpecialMesh2.MeshId = "rbxasset://fonts/rocketlauncher.mesh"
  57. SpecialMesh2.Scale = Vector3.new(0.75, 0.75, 0.75)
  58. SpecialMesh2.TextureId = "rbxasset://textures/rocketlaunchertex.png"
  59. SpecialMesh2.MeshType = Enum.MeshType.FileMesh
  60. Script3.Parent = Tool0
  61. table.insert(cors,sandbox(Script3,function()
  62. local tool = script.Parent
  63. local canFire = true
  64. local gunWeld
  65.  
  66. -----------------
  67. --| Constants |--
  68. -----------------
  69.  
  70. local GRAVITY_ACCELERATION = 196.2
  71.  
  72. local RELOAD_TIME = tool.Configurations.ReloadTime.Value -- Seconds until tool can be used again
  73. local ROCKET_SPEED = tool.Configurations.RocketSpeed.Value -- Speed of the projectile
  74.  
  75. local MISSILE_MESH_ID = 'http://www.roblox.com/asset/?id=2251534'
  76. local MISSILE_MESH_SCALE = Vector3.new(0.35, 0.35, 0.25)
  77. local ROCKET_PART_SIZE = Vector3.new(1.2, 1.2, 3.27)
  78.  
  79. local RocketScript = script:WaitForChild('Rocket')
  80. local SwooshSound = script:WaitForChild('Swoosh')
  81. local BoomSound = script:WaitForChild('Boom')
  82.  
  83. local attackCooldown = tool.Configurations.AttackCooldown.Value
  84. local damage = tool.Configurations.Damage.Value
  85. local reloadTime = tool.Configurations.ReloadTime.Value
  86.  
  87. local function createEvent(eventName)
  88. local event = game.ReplicatedStorage:FindFirstChild(eventName)
  89. if not event then
  90. event = Instance.new("RemoteEvent", game.ReplicatedStorage)
  91. event.Name = eventName
  92. end
  93. return event
  94. end
  95.  
  96. local updateEvent = createEvent("ROBLOX_RocketUpdateEvent")
  97. local equipEvent = createEvent("ROBLOX_RocketEquipEvent")
  98. local unequipEvent = createEvent("ROBLOX_RocketUnequipEvent")
  99. local fireEvent = createEvent("ROBLOX_RocketFireEvent")
  100.  
  101. updateEvent.OnServerEvent:connect(function(player, neckC0, rshoulderC0)
  102. local character = player.Character
  103. local humanoid = character.Humanoid
  104.  
  105. if humanoid.Health <= 0 then return end
  106.  
  107. if humanoid.RigType == Enum.HumanoidRigType.R6 then
  108. character.Torso.Neck.C0 = neckC0
  109. character.Torso:FindFirstChild("Right Shoulder").C0 = rshoulderC0
  110. gunWeld = character:FindFirstChild("Right Arm"):WaitForChild("RightGrip")
  111.  
  112. elseif humanoid.RigType == Enum.HumanoidRigType.R15 then
  113. character.Head.Neck.C0 = neckC0
  114. character.RightUpperArm.RightShoulder.C0 = rshoulderC0
  115. gunWeld = character.RightHand:WaitForChild("RightGrip")
  116. end
  117. end)
  118.  
  119. equipEvent.OnServerEvent:connect(function(player)
  120. player.Character.Humanoid.AutoRotate = false
  121. end)
  122.  
  123. unequipEvent.OnServerEvent:connect(function(player)
  124. player.Character.Humanoid.AutoRotate = true
  125. end)
  126.  
  127. --NOTE: We create the rocket once and then clone it when the player fires
  128. local Rocket = Instance.new('Part') do
  129. -- Set up the rocket part
  130. Rocket.Name = 'Rocket'
  131. Rocket.FormFactor = Enum.FormFactor.Custom --NOTE: This must be done before changing Size
  132. Rocket.Size = ROCKET_PART_SIZE
  133. Rocket.CanCollide = false
  134.  
  135. -- Add the mesh
  136. local mesh = Instance.new('SpecialMesh', Rocket)
  137. mesh.MeshId = MISSILE_MESH_ID
  138. mesh.Scale = MISSILE_MESH_SCALE
  139.  
  140. -- Add fire
  141. local fire = Instance.new('Fire', Rocket)
  142. fire.Heat = 5
  143. fire.Size = 2
  144.  
  145. -- Add a force to counteract gravity
  146. local bodyForce = Instance.new('BodyForce', Rocket)
  147. bodyForce.Name = 'Antigravity'
  148. bodyForce.force = Vector3.new(0, Rocket:GetMass() * GRAVITY_ACCELERATION, 0)
  149.  
  150. -- Clone the sounds and set Boom to PlayOnRemove
  151. local swooshSoundClone = SwooshSound:Clone()
  152. swooshSoundClone.Parent = Rocket
  153. local boomSoundClone = BoomSound:Clone()
  154. boomSoundClone.PlayOnRemove = true
  155. boomSoundClone.Parent = Rocket
  156.  
  157. -- Finally, clone the rocket script and enable it
  158. -- local rocketScriptClone = RocketScript:Clone()
  159. -- rocketScriptClone.Parent = Rocket
  160. -- rocketScriptClone.Disabled = false
  161. end
  162.  
  163.  
  164. fireEvent.OnServerEvent:connect(function(player, target)
  165. if canFire and player.Character == tool.Parent then
  166. canFire = false
  167.  
  168. -- Create a clone of Rocket and set its color
  169. local rocketClone = Rocket:Clone()
  170. --game.Debris:AddItem(rocketClone, 30)
  171. rocketClone.BrickColor = player.TeamColor
  172. rocketClone.Touched:connect(function(hit)
  173. if hit and hit.Parent and hit.Parent ~= player.Character and hit.Parent ~= tool then
  174. local explosion = Instance.new("Explosion", game.Workspace)
  175. explosion.Position = rocketClone.Position
  176. rocketClone:Destroy()
  177. end
  178. end)
  179.  
  180. spawn(function()
  181. wait(30)
  182. if rocketClone then rocketClone:Destroy() end
  183. end)
  184.  
  185. -- Position the rocket clone and launch!
  186. local spawnPosition = (tool.Handle.CFrame * CFrame.new(2, 0, 0)).p
  187. rocketClone.CFrame = CFrame.new(spawnPosition, target) --NOTE: This must be done before assigning Parent
  188. rocketClone.Velocity = rocketClone.CFrame.lookVector * ROCKET_SPEED --NOTE: This should be done before assigning Parent
  189. rocketClone.Parent = game.Workspace
  190.  
  191. -- Attach creator tags to the rocket early on
  192. local creatorTag = Instance.new('ObjectValue', rocketClone)
  193. creatorTag.Value = player
  194. creatorTag.Name = 'creator' --NOTE: Must be called 'creator' for website stats
  195. local iconTag = Instance.new('StringValue', creatorTag)
  196. iconTag.Value = tool.TextureId
  197. iconTag.Name = 'icon'
  198.  
  199. delay(attackCooldown, function()
  200. canFire = true
  201. end)
  202. end
  203. end)
  204. end))
  205. Sound4.Name = "Boom"
  206. Sound4.Parent = Script3
  207. Sound4.SoundId = "rbxasset://sounds/collide.wav"
  208. Sound4.Volume = 1
  209. Sound5.Name = "Swoosh"
  210. Sound5.Parent = Script3
  211. Sound5.Looped = true
  212. Sound5.SoundId = "rbxasset://sounds/Rocket whoosh 01.wav"
  213. Sound5.Volume = 0.69999998807907
  214. Script6.Name = "Rocket"
  215. Script6.Parent = Script3
  216. table.insert(cors,sandbox(Script6,function()
  217. -----------------
  218. --| Constants |--
  219. -----------------
  220. local BLAST_RADIUS = script.Parent.Parent.Configurations.BlastRadius.Value -- Blast radius of the explosion
  221. local BLAST_DAMAGE = script.Parent.Parent.Configurations.Damage.Value -- Amount of damage done to players
  222. local BLAST_FORCE = script.Parent.Parent.Configurations.BlastForce.Value -- Amount of force applied to parts
  223.  
  224. local IGNORE_LIST = {rocket = 1, handle = 1, effect = 1, water = 1} -- Rocket will fly through things named these
  225. --NOTE: Keys must be lowercase, values must evaluate to true
  226.  
  227. -----------------
  228. --| Variables |--
  229. -----------------
  230.  
  231. local DebrisService = game:GetService('Debris')
  232. local PlayersService = game:GetService('Players')
  233.  
  234. local Rocket = script.Parent
  235.  
  236. local CreatorTag = Rocket:WaitForChild('creator', 60)
  237. local SwooshSound = Rocket:WaitForChild('Swoosh', 60)
  238.  
  239. -----------------
  240. --| Functions |--
  241. -----------------
  242.  
  243. -- Removes any old creator tags and applies a new one to the target
  244. local function ApplyTags(target)
  245. while target:FindFirstChild('creator') do
  246. target.creator:Destroy()
  247. end
  248.  
  249. local creatorTagClone = CreatorTag:Clone()
  250. DebrisService:AddItem(creatorTagClone, 1.5)
  251. creatorTagClone.Parent = target
  252. end
  253.  
  254. -- Returns the ancestor that contains a Humanoid, if it exists
  255. local function FindCharacterAncestor(subject)
  256. if subject and subject ~= game.Workspace then
  257. local humanoid = subject:FindFirstChild('Humanoid')
  258. if humanoid then
  259. return subject, humanoid
  260. else
  261. return FindCharacterAncestor(subject.Parent)
  262. end
  263. end
  264. return nil
  265. end
  266.  
  267. -- Customized explosive effect that doesn't affect teammates and only breaks joints on dead parts
  268. local function OnExplosionHit(hitPart, hitDistance, blastCenter)
  269. if hitPart and hitDistance then
  270. local character, humanoid = FindCharacterAncestor(hitPart.Parent)
  271.  
  272. if character then
  273. local myPlayer = CreatorTag.Value
  274. if myPlayer and not myPlayer.Neutral then -- Ignore friendlies caught in the blast
  275. local player = PlayersService:GetPlayerFromCharacter(character)
  276. if player and player ~= myPlayer and player.TeamColor == Rocket.BrickColor then
  277. return
  278. end
  279. end
  280. end
  281.  
  282. if humanoid and humanoid.Health > 0 then -- Humanoids are tagged and damaged
  283. if hitPart.Name == 'Torso' then
  284. ApplyTags(humanoid)
  285. humanoid:TakeDamage(BLAST_DAMAGE)
  286. end
  287. else -- Loose parts and dead parts are blasted
  288. if hitPart.Name ~= 'Handle' then
  289. hitPart:BreakJoints()
  290. local blastForce = Instance.new('BodyForce', hitPart) --NOTE: We will multiply by mass so bigger parts get blasted more
  291. blastForce.force = (hitPart.Position - blastCenter).unit * BLAST_FORCE * hitPart:GetMass()
  292. DebrisService:AddItem(blastForce, 0.1)
  293. end
  294. end
  295. end
  296. end
  297.  
  298. local function OnTouched(otherPart)
  299. if Rocket and otherPart then
  300. -- Fly through anything in the ignore list
  301. if IGNORE_LIST[string.lower(otherPart.Name)] then
  302. return
  303. end
  304.  
  305. local myPlayer = CreatorTag.Value
  306. if myPlayer then
  307. -- Fly through the creator
  308. if myPlayer.Character and myPlayer.Character:IsAncestorOf(otherPart) then
  309. return
  310. end
  311.  
  312. -- Fly through friendlies
  313. if not myPlayer.Neutral then
  314. local character = FindCharacterAncestor(otherPart.Parent)
  315. local player = PlayersService:GetPlayerFromCharacter(character)
  316. if player and player ~= myPlayer and player.TeamColor == Rocket.BrickColor then
  317. return
  318. end
  319. end
  320. end
  321.  
  322. -- Fly through terrain water
  323. if otherPart == game.Workspace.Terrain then
  324. --NOTE: If the rocket is large, then the simplifications made here will cause it to fly through terrain in some cases
  325. local frontOfRocket = Rocket.Position + (Rocket.CFrame.lookVector * (Rocket.Size.Z / 2))
  326. local cellLocation = game.Workspace.Terrain:WorldToCellPreferSolid(frontOfRocket)
  327. local cellMaterial = game.Workspace.Terrain:GetCell(cellLocation.X, cellLocation.Y, cellLocation.Z)
  328. if cellMaterial == Enum.CellMaterial.Water or cellMaterial == Enum.CellMaterial.Empty then
  329. return
  330. end
  331. end
  332.  
  333. -- Create the explosion
  334. local explosion = Instance.new('Explosion')
  335. explosion.BlastPressure = 0 -- Completely safe explosion
  336. explosion.BlastRadius = BLAST_RADIUS
  337. explosion.ExplosionType = Enum.ExplosionType.NoCraters
  338. explosion.Position = Rocket.Position
  339. explosion.Parent = game.Workspace
  340.  
  341. -- Connect custom logic for the explosion
  342. explosion.Hit:connect(function(hitPart, hitDistance) OnExplosionHit(hitPart, hitDistance, explosion.Position) end)
  343.  
  344. -- Move this script and the creator tag (so our custom logic can execute), then destroy the rocket
  345. script.Parent = explosion
  346. CreatorTag.Parent = script
  347. Rocket:Destroy()
  348. end
  349. end
  350.  
  351. --------------------
  352. --| Script Logic |--
  353. --------------------
  354.  
  355. SwooshSound:Play()
  356.  
  357. Rocket.Touched:connect(OnTouched)
  358.  
  359. end))
  360. LocalScript7.Parent = Tool0
  361. table.insert(cors,sandbox(LocalScript7,function()
  362. -- Variables for services
  363. local render = game:GetService("RunService").RenderStepped
  364. local contextActionService = game:GetService("ContextActionService")
  365. local userInputService = game:GetService("UserInputService")
  366.  
  367. local player = game.Players.LocalPlayer
  368. local mouse = player:GetMouse()
  369. local Tool = script.Parent
  370.  
  371. -- Variables for Module Scripts
  372. local screenSpace = require(Tool:WaitForChild("ScreenSpace"))
  373.  
  374. local connection
  375.  
  376. local neck, shoulder, oldNeckC0, oldShoulderC0
  377.  
  378. local mobileShouldTrack = true
  379.  
  380. -- Thourough check to see if a character is sitting
  381. local function amISitting(character)
  382. return character.Humanoid.SeatPart ~= nil
  383. end
  384.  
  385. -- Function to call on renderstepped. Orients the character so it is facing towards
  386. -- the player mouse's position in world space. If character is sitting then the torso
  387. -- should not track
  388. local function frame(mousePosition)
  389. -- Special mobile consideration. We don't want to track if the user was touching a ui
  390. -- element such as the movement controls. Just return out of function if so to make sure
  391. -- character doesn't track
  392. if not mobileShouldTrack then return end
  393.  
  394. --This math is completely wrong with R15. We're better off just not doing it at all
  395. if player.Character.Humanoid.RigType == Enum.HumanoidRigType.R15 then
  396. return
  397. end
  398.  
  399. -- Make sure character isn't swiming. If the character is swimming the following code will
  400. -- not work well; the character will not swim correctly. Besides, who shoots underwater?
  401. if player.Character.Humanoid:GetState() ~= Enum.HumanoidStateType.Swimming then
  402. local torso = player.Character.HumanoidRootPart
  403. local head = player.Character.Head
  404.  
  405. local toMouse = (mousePosition - head.Position).unit
  406. local angle = math.acos(toMouse:Dot(Vector3.new(0,1,0)))
  407.  
  408. local neckAngle = angle
  409.  
  410. -- Limit how much the head can tilt down. Too far and the head looks unnatural
  411. if math.deg(neckAngle) > 110 then
  412. neckAngle = math.rad(110)
  413. end
  414. neck.C0 = CFrame.new(0,1,0) * CFrame.Angles(math.pi - neckAngle,math.pi,0)
  415.  
  416. -- Calculate horizontal rotation
  417. local arm do
  418. arm = player.Character:FindFirstChild("Right Arm") or
  419. player.Character:FindFirstChild("RightUpperArm")
  420. end
  421. local fromArmPos = torso.Position + torso.CFrame:vectorToWorldSpace(Vector3.new(
  422. torso.Size.X/2 + arm.Size.X/2, torso.Size.Y/2 - arm.Size.Z/2, 0))
  423. local toMouseArm = ((mousePosition - fromArmPos) * Vector3.new(1,0,1)).unit
  424. local look = (torso.CFrame.lookVector * Vector3.new(1,0,1)).unit
  425. local lateralAngle = math.acos(toMouseArm:Dot(look))
  426.  
  427. -- Check for rogue math
  428. if tostring(lateralAngle) == "-1.#IND" then
  429. lateralAngle = 0
  430. end
  431.  
  432. -- Handle case where character is sitting down
  433. if player.Character.Humanoid:GetState() == Enum.HumanoidStateType.Seated then
  434.  
  435. local cross = torso.CFrame.lookVector:Cross(toMouseArm)
  436. if lateralAngle > math.pi/2 then
  437. lateralAngle = math.pi/2
  438. end
  439. if cross.Y < 0 then
  440. lateralAngle = -lateralAngle
  441. end
  442. end
  443.  
  444. -- Turn shoulder to point to mouse
  445. shoulder.C0 = CFrame.new(1,0.5,0) * CFrame.Angles(math.pi/2 - angle,math.pi/2 + lateralAngle,0)
  446.  
  447. -- If not sitting then aim torso laterally towards mouse
  448. if not amISitting(player.Character) then
  449. torso.CFrame = CFrame.new(torso.Position, torso.Position + (Vector3.new(
  450. mousePosition.X, torso.Position.Y, mousePosition.Z)-torso.Position).unit)
  451. end
  452. end
  453. end
  454.  
  455. -- Function to bind to render stepped if player is on PC
  456. local function pcFrame()
  457. frame(mouse.Hit.p)
  458. end
  459.  
  460. -- Function to bind to touch moved if player is on mobile
  461. local function mobileFrame(touch, processed)
  462. -- Check to see if the touch was on a UI element. If so, we don't want to update anything
  463. if not processed then
  464. -- Calculate touch position in world space. Uses Stravant's ScreenSpace Module script
  465. -- to create a ray from the camera.
  466. local test = screenSpace.ScreenToWorld(touch.Position.X, touch.Position.Y, 1)
  467. local nearPos = game.Workspace.CurrentCamera.CoordinateFrame:vectorToWorldSpace(screenSpace.ScreenToWorld(touch.Position.X, touch.Position.Y, 1))
  468. nearPos = game.Workspace.CurrentCamera.CoordinateFrame.p - nearPos
  469. local farPos = screenSpace.ScreenToWorld(touch.Position.X, touch.Position.Y,50)
  470. farPos = game.Workspace.CurrentCamera.CoordinateFrame:vectorToWorldSpace(farPos) * -1
  471. if farPos.magnitude > 900 then
  472. farPos = farPos.unit * 900
  473. end
  474. local ray = Ray.new(nearPos, farPos)
  475. local part, pos = game.Workspace:FindPartOnRay(ray, player.Character)
  476.  
  477. -- if a position was found on the ray then update the character's rotation
  478. if pos then
  479. frame(pos)
  480. end
  481. end
  482. end
  483.  
  484. local function OnActivated()
  485. local myModel = player.Character
  486. if Tool.Enabled and myModel and myModel:FindFirstChild('Humanoid') and myModel.Humanoid.Health > 0 then
  487. Tool.Enabled = false
  488. game.ReplicatedStorage.ROBLOX_RocketFireEvent:FireServer(mouse.Hit.p)
  489. wait(2)
  490.  
  491. Tool.Enabled = true
  492. end
  493. end
  494.  
  495. local oldIcon = nil
  496. -- Function to bind to equip event
  497. local function equip()
  498. local character = player.Character
  499. local humanoid = character.Humanoid
  500.  
  501. -- Setup joint variables
  502. if humanoid.RigType == Enum.HumanoidRigType.R6 then
  503. local torso = character.Torso
  504. neck = torso.Neck
  505. shoulder = torso["Right Shoulder"]
  506.  
  507. elseif humanoid.RigType == Enum.HumanoidRigType.R15 then
  508. neck = character.Head.Neck
  509. shoulder = character.RightUpperArm.RightShoulder
  510. end
  511.  
  512. oldNeckC0 = neck.C0
  513. oldShoulderC0 = shoulder.C0
  514.  
  515. -- Remember old mouse icon and update current
  516. oldIcon = mouse.Icon
  517. mouse.Icon = "http://www.roblox.com/asset/?id=79658449"
  518.  
  519. -- Bind TouchMoved event if on mobile. Otherwise connect to renderstepped
  520. if userInputService.TouchEnabled then
  521. connection = userInputService.TouchMoved:connect(mobileFrame)
  522. else
  523. connection = render:connect(pcFrame)
  524. end
  525.  
  526. -- Bind TouchStarted and TouchEnded. Used to determine if character should rotate
  527. -- during touch input
  528. userInputService.TouchStarted:connect(function(touch, processed)
  529. mobileShouldTrack = not processed
  530. end)
  531. userInputService.TouchEnded:connect(function(touch, processed)
  532. mobileShouldTrack = false
  533. end)
  534.  
  535. -- If game uses filtering enabled then need to update server while tool is
  536. -- held by character.
  537. if workspace.FilteringEnabled then
  538. while connection and connection.Connected do
  539. wait()
  540. game.ReplicatedStorage.ROBLOX_RocketUpdateEvent:FireServer(neck.C0, shoulder.C0)
  541. end
  542. end
  543. end
  544.  
  545. -- Function to bind to Unequip event
  546. local function unequip()
  547. if connection then connection:disconnect() end
  548.  
  549. mouse.Icon = oldIcon
  550.  
  551. neck.C0 = oldNeckC0
  552. shoulder.C0 = oldShoulderC0
  553. end
  554.  
  555. -- Bind tool events
  556. Tool.Equipped:connect(equip)
  557. Tool.Unequipped:connect(unequip)
  558. Tool.Activated:connect(OnActivated)
  559. end))
  560. Configuration8.Name = "Configurations"
  561. Configuration8.Parent = Tool0
  562. NumberValue9.Name = "AttackCooldown"
  563. NumberValue9.Parent = Configuration8
  564. NumberValue9.Value = 3
  565. IntValue10.Name = "Damage"
  566. IntValue10.Parent = Configuration8
  567. IntValue10.Value = 60
  568. NumberValue11.Name = "ReloadTime"
  569. NumberValue11.Parent = Configuration8
  570. NumberValue11.Value = 1
  571. IntValue12.Name = "BlastForce"
  572. IntValue12.Parent = Configuration8
  573. IntValue12.Value = 1000
  574. IntValue13.Name = "BlastRadius"
  575. IntValue13.Parent = Configuration8
  576. IntValue13.Value = 8
  577. IntValue14.Name = "RocketSpeed"
  578. IntValue14.Parent = Configuration8
  579. IntValue14.Value = 60
  580. ModuleScript15.Name = "ScreenSpace"
  581. ModuleScript15.Parent = Tool0
  582. table.insert(cors,sandbox(ModuleScript15,function()
  583. local PlayerMouse = Game:GetService('Players').LocalPlayer:GetMouse()
  584.  
  585. local ScreenSpace = {}
  586.  
  587. -- Getter functions, with a couple of hacks for Ipad pre-focus.
  588. function ScreenSpace.ViewSizeX()
  589. local x = PlayerMouse.ViewSizeX
  590. local y = PlayerMouse.ViewSizeY
  591. if x == 0 then
  592. return 1024
  593. else
  594. if x > y then
  595. return x
  596. else
  597. return y
  598. end
  599. end
  600. end
  601.  
  602. function ScreenSpace.ViewSizeY()
  603. local x = PlayerMouse.ViewSizeX
  604. local y = PlayerMouse.ViewSizeY
  605. if y == 0 then
  606. return 768
  607. else
  608. if x > y then
  609. return y
  610. else
  611. return x
  612. end
  613. end
  614. end
  615.  
  616. -- Nice getter for aspect ratio. Due to the checks in the ViewSize functions this
  617. -- will never fail with a divide by zero error.
  618. function ScreenSpace.AspectRatio()
  619. return ScreenSpace.ViewSizeX() / ScreenSpace.ViewSizeY()
  620. end
  621.  
  622. -- WorldSpace -> ScreenSpace. Raw function taking a world position and giving you the
  623. -- screen position.
  624. function ScreenSpace.WorldToScreen(at)
  625. local point = Workspace.CurrentCamera.CoordinateFrame:pointToObjectSpace(at)
  626. local aspectRatio = ScreenSpace.AspectRatio()
  627. local hfactor = math.tan(math.rad(Workspace.CurrentCamera.FieldOfView)/2)
  628. local wfactor = aspectRatio*hfactor
  629. --
  630. local x = (point.x/point.z) / -wfactor
  631. local y = (point.y/point.z) / hfactor
  632. --
  633. return Vector2.new(ScreenSpace.ViewSizeX()*(0.5 + 0.5*x), ScreenSpace.ViewSizeY()*(0.5 + 0.5*y))
  634. end
  635.  
  636. -- ScreenSpace -> WorldSpace. Raw function taking a screen position and a depth and
  637. -- converting it into a world position.
  638. function ScreenSpace.ScreenToWorld(x, y, depth)
  639. local aspectRatio = ScreenSpace.AspectRatio()
  640. local hfactor = math.tan(math.rad(Workspace.CurrentCamera.FieldOfView)/2)
  641. local wfactor = aspectRatio*hfactor
  642. --
  643. local xf, yf = x/ScreenSpace.ViewSizeX()*2 - 1, y/ScreenSpace.ViewSizeY()*2 - 1
  644. local xpos = xf * -wfactor * depth
  645. local ypos = yf * hfactor * depth
  646. --
  647. return Vector3.new(xpos, ypos, depth)
  648. end
  649.  
  650. -- ScreenSize -> WorldSize
  651. function ScreenSpace.ScreenWidthToWorldWidth(screenWidth, depth)
  652. local aspectRatio = ScreenSpace.AspectRatio()
  653. local hfactor = math.tan(math.rad(Workspace.CurrentCamera.FieldOfView)/2)
  654. local wfactor = aspectRatio*hfactor
  655. local sx = ScreenSpace.ViewSizeX()
  656. --
  657. return -(screenWidth / sx) * 2 * wfactor * depth
  658. end
  659. function ScreenSpace.ScreenHeightToWorldHeight(screenHeight, depth)
  660. local hfactor = math.tan(math.rad(Workspace.CurrentCamera.FieldOfView)/2)
  661. local sy = ScreenSpace.ViewSizeY()
  662. --
  663. return -(screenHeight / sy) * 2 * hfactor * depth
  664. end
  665.  
  666. -- WorldSize -> ScreenSize
  667. function ScreenSpace.WorldWidthToScreenWidth(worldWidth, depth)
  668. local aspectRatio = ScreenSpace.AspectRatio()
  669. local hfactor = math.tan(math.rad(Workspace.CurrentCamera.FieldOfView)/2)
  670. local wfactor = aspectRatio*hfactor
  671. local sx = ScreenSpace.ViewSizeX()
  672. --
  673. return -(worldWidth * sx) / (2 * wfactor * depth)
  674. end
  675. function ScreenSpace.WorldHeightToScreenHeight(worldHeight, depth)
  676. local hfactor = math.tan(math.rad(Workspace.CurrentCamera.FieldOfView)/2)
  677. local sy = ScreenSpace.ViewSizeY()
  678. --
  679. return -(worldHeight * sy) / (2 * hfactor * depth)
  680. end
  681.  
  682. -- WorldSize + ScreenSize -> Depth needed
  683. function ScreenSpace.GetDepthForWidth(screenWidth, worldWidth)
  684. local aspectRatio = ScreenSpace.AspectRatio()
  685. local hfactor = math.tan(math.rad(Workspace.CurrentCamera.FieldOfView)/2)
  686. local wfactor = aspectRatio*hfactor
  687. local sx, sy = ScreenSpace.ViewSizeX(), ScreenSpace.ViewSizeY()
  688. --
  689. return -(sx * worldWidth) / (screenWidth * 2 * wfactor)
  690. end
  691. function ScreenSpace.GetDepthForHeight(screenHeight, worldHeight)
  692. local hfactor = math.tan(math.rad(Workspace.CurrentCamera.FieldOfView)/2)
  693. local sy = ScreenSpace.ViewSizeY()
  694. --
  695. return -(sy * worldHeight) / (screenHeight * 2 * hfactor)
  696. end
  697.  
  698. -- ScreenSpace -> WorldSpace. Taking a screen height, and a depth to put an object
  699. -- at, and returning a size of how big that object has to be to appear that size
  700. -- at that depth.
  701. function ScreenSpace.ScreenToWorldByHeightDepth(x, y, screenHeight, depth)
  702. local aspectRatio = ScreenSpace.AspectRatio()
  703. local hfactor = math.tan(math.rad(Workspace.CurrentCamera.FieldOfView)/2)
  704. local wfactor = aspectRatio*hfactor
  705. local sx, sy = ScreenSpace.ViewSizeX(), ScreenSpace.ViewSizeY()
  706. --
  707. local worldHeight = -(screenHeight/sy) * 2 * hfactor * depth
  708. --
  709. local xf, yf = x/sx*2 - 1, y/sy*2 - 1
  710. local xpos = xf * -wfactor * depth
  711. local ypos = yf * hfactor * depth
  712. --
  713. return Vector3.new(xpos, ypos, depth), worldHeight
  714. end
  715.  
  716. -- ScreenSpace -> WorldSpace. Taking a screen width, and a depth to put an object
  717. -- at, and returning a size of how big that object has to be to appear that size
  718. -- at that depth.
  719. function ScreenSpace.ScreenToWorldByWidthDepth(x, y, screenWidth, depth)
  720. local aspectRatio = ScreenSpace.AspectRatio()
  721. local hfactor = math.tan(math.rad(Workspace.CurrentCamera.FieldOfView)/2)
  722. local wfactor = aspectRatio*hfactor
  723. local sx, sy = ScreenSpace.ViewSizeX(), ScreenSpace.ViewSizeY()
  724. --
  725. local worldWidth = (screenWidth/sx) * 2 * -wfactor * depth
  726. --
  727. local xf, yf = x/sx*2 - 1, y/sy*2 - 1
  728. local xpos = xf * -wfactor * depth
  729. local ypos = yf * hfactor * depth
  730. --
  731. return Vector3.new(xpos, ypos, depth), worldWidth
  732. end
  733.  
  734. -- ScreenSpace -> WorldSpace. Taking a screen height that you want that object to be
  735. -- and a world height that is the size of that object, and returning the position to
  736. -- put that object at to satisfy those.
  737. function ScreenSpace.ScreenToWorldByHeight(x, y, screenHeight, worldHeight)
  738. local aspectRatio = ScreenSpace.AspectRatio()
  739. local hfactor = math.tan(math.rad(Workspace.CurrentCamera.FieldOfView)/2)
  740. local wfactor = aspectRatio*hfactor
  741. local sx, sy = ScreenSpace.ViewSizeX(), ScreenSpace.ViewSizeY()
  742. --
  743. local depth = - (sy * worldHeight) / (screenHeight * 2 * hfactor)
  744. --
  745. local xf, yf = x/sx*2 - 1, y/sy*2 - 1
  746. local xpos = xf * -wfactor * depth
  747. local ypos = yf * hfactor * depth
  748. --
  749. return Vector3.new(xpos, ypos, depth)
  750. end
  751.  
  752. -- ScreenSpace -> WorldSpace. Taking a screen width that you want that object to be
  753. -- and a world width that is the size of that object, and returning the position to
  754. -- put that object at to satisfy those.
  755. function ScreenSpace.ScreenToWorldByWidth(x, y, screenWidth, worldWidth)
  756. local aspectRatio = ScreenSpace.AspectRatio()
  757. local hfactor = math.tan(math.rad(Workspace.CurrentCamera.FieldOfView)/2)
  758. local wfactor = aspectRatio*hfactor
  759. local sx, sy = ScreenSpace.ViewSizeX(), ScreenSpace.ViewSizeY()
  760. --
  761. local depth = - (sx * worldWidth) / (screenWidth * 2 * wfactor)
  762. --
  763. local xf, yf = x/sx*2 - 1, y/sy*2 - 1
  764. local xpos = xf * -wfactor * depth
  765. local ypos = yf * hfactor * depth
  766. --
  767. return Vector3.new(xpos, ypos, depth)
  768. end
  769.  
  770. return ScreenSpace
  771.  
  772.  
  773.  
  774.  
  775. end))
  776. for i,v in pairs(mas:GetChildren()) do
  777. v.Parent = workspace
  778. pcall(function() v:MakeJoints() end)
  779. end
  780. mas:Destroy()
  781. for i,v in pairs(cors) do
  782. spawn(function()
  783. pcall(v)
  784. end)
  785. end
Advertisement
Add Comment
Please, Sign In to add comment