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