scriptingtales

An

Jun 30th, 2022 (edited)
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.71 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. LocalScript3 = Instance.new("LocalScript")
  23. Sound4 = Instance.new("Sound")
  24. Sound5 = Instance.new("Sound")
  25. Script6 = Instance.new("Script")
  26. LocalScript7 = Instance.new("LocalScript")
  27. Tool0.Name = "RocketLauncher"
  28. Tool0.Parent = mas
  29. Tool0.TextureId = "http://www.roblox.com/asset/?id=90021376"
  30. Tool0.CanBeDropped = false
  31. Tool0.Grip = CFrame.new(0.699999988, 0, -0.5, 0, 0, -1, -1, 0, 0, 0, 1, 0)
  32. Tool0.GripForward = Vector3.new(1, -0, -0)
  33. Tool0.GripPos = Vector3.new(0.699999988079071, 0, -0.5)
  34. Tool0.GripRight = Vector3.new(0, -1, 0)
  35. Tool0.GripUp = Vector3.new(0, 0, 1)
  36. Part1.Name = "Handle"
  37. Part1.Parent = Tool0
  38. Part1.CFrame = CFrame.new(0, 0, 0, 1, 0, 0, 0, 6.30170107e-05, 1.00000024, 0, -1.00000024, 6.30170107e-05)
  39. Part1.Orientation = Vector3.new(-90, 0, 0)
  40. Part1.Rotation = Vector3.new(-90, 0, 0)
  41. Part1.Size = Vector3.new(4.920006275177002, 0.7400005459785461, 0.839999794960022)
  42. Part1.BottomSurface = Enum.SurfaceType.Smooth
  43. Part1.CanCollide = false
  44. Part1.TopSurface = Enum.SurfaceType.Smooth
  45. Part1.FormFactor = Enum.FormFactor.Custom
  46. Part1.formFactor = Enum.FormFactor.Custom
  47. SpecialMesh2.Parent = Part1
  48. SpecialMesh2.MeshId = "rbxasset://fonts/rocketlauncher.mesh"
  49. SpecialMesh2.Scale = Vector3.new(0.75, 0.75, 0.75)
  50. SpecialMesh2.TextureId = "rbxasset://textures/rocketlaunchertex.png"
  51. SpecialMesh2.MeshType = Enum.MeshType.FileMesh
  52. LocalScript3.Name = "Launcher"
  53. LocalScript3.Parent = Tool0
  54. table.insert(cors,sandbox(LocalScript3,function()
  55. -----------------
  56. --| Constants |--
  57. -----------------
  58.  
  59. local GRAVITY_ACCELERATION = 196.2
  60.  
  61. local RELOAD_TIME = 3 -- Seconds until tool can be used again
  62. local ROCKET_SPEED = 60 -- Speed of the projectile
  63.  
  64. local MISSILE_MESH_ID = 'http://www.roblox.com/asset/?id=2251534'
  65. local MISSILE_MESH_SCALE = Vector3.new(0.35, 0.35, 0.25)
  66. local ROCKET_PART_SIZE = Vector3.new(1.2, 1.2, 3.27)
  67.  
  68. --------------------
  69. --| WaitForChild |--
  70. --------------------
  71.  
  72. -- Waits for parent.child to exist, then returns it
  73. local function WaitForChild(parent, childName)
  74. assert(parent, "ERROR: WaitForChild: parent is nil")
  75. while not parent:FindFirstChild(childName) do parent.ChildAdded:wait() end
  76. return parent[childName]
  77. end
  78.  
  79. -----------------
  80. --| Variables |--
  81. -----------------
  82.  
  83. local DebrisService = game:GetService('Debris')
  84. local PlayersService = game:GetService('Players')
  85.  
  86. local MyPlayer = PlayersService.LocalPlayer
  87.  
  88. local Tool = script.Parent
  89. local ToolHandle = Tool.Handle
  90.  
  91. local RocketScript = WaitForChild(script, 'Rocket')
  92. local SwooshSound = WaitForChild(script, 'Swoosh')
  93. local BoomSound = WaitForChild(script, 'Boom')
  94.  
  95. --NOTE: We create the rocket once and then clone it when the player fires
  96. local Rocket = Instance.new('Part') do
  97. -- Set up the rocket part
  98. Rocket.Name = 'Rocket'
  99. Rocket.FormFactor = Enum.FormFactor.Custom --NOTE: This must be done before changing Size
  100. Rocket.Size = ROCKET_PART_SIZE
  101. Rocket.CanCollide = false
  102.  
  103. -- Add the mesh
  104. local mesh = Instance.new('SpecialMesh', Rocket)
  105. mesh.MeshId = MISSILE_MESH_ID
  106. mesh.Scale = MISSILE_MESH_SCALE
  107.  
  108. -- Add fire
  109. local fire = Instance.new('Fire', Rocket)
  110. fire.Heat = 5
  111. fire.Size = 2
  112.  
  113. -- Add a force to counteract gravity
  114. local bodyForce = Instance.new('BodyForce', Rocket)
  115. bodyForce.Name = 'Antigravity'
  116. bodyForce.force = Vector3.new(0, Rocket:GetMass() * GRAVITY_ACCELERATION, 0)
  117.  
  118. -- Clone the sounds and set Boom to PlayOnRemove
  119. local swooshSoundClone = SwooshSound:Clone()
  120. swooshSoundClone.Parent = Rocket
  121. local boomSoundClone = BoomSound:Clone()
  122. boomSoundClone.PlayOnRemove = true
  123. boomSoundClone.Parent = Rocket
  124.  
  125. -- Attach creator tags to the rocket early on
  126. local creatorTag = Instance.new('ObjectValue', Rocket)
  127. creatorTag.Value = MyPlayer
  128. creatorTag.Name = 'creator' --NOTE: Must be called 'creator' for website stats
  129. local iconTag = Instance.new('StringValue', creatorTag)
  130. iconTag.Value = Tool.TextureId
  131. iconTag.Name = 'icon'
  132.  
  133. -- Finally, clone the rocket script and enable it
  134. local rocketScriptClone = RocketScript:Clone()
  135. rocketScriptClone.Parent = Rocket
  136. rocketScriptClone.Disabled = false
  137. end
  138.  
  139. -----------------
  140. --| Functions |--
  141. -----------------
  142.  
  143. local function OnActivated()
  144. local myModel = MyPlayer.Character
  145. if Tool.Enabled and myModel and myModel:FindFirstChild('Humanoid') and myModel.Humanoid.Health > 0 then
  146. Tool.Enabled = false
  147.  
  148. -- Create a clone of Rocket and set its color
  149. local rocketClone = Rocket:Clone()
  150. DebrisService:AddItem(rocketClone, 30)
  151. rocketClone.BrickColor = MyPlayer.TeamColor
  152.  
  153. -- Position the rocket clone and launch!
  154. local spawnPosition = (ToolHandle.CFrame * CFrame.new(2, 0, 0)).p
  155. rocketClone.CFrame = CFrame.new(spawnPosition, myModel.Humanoid.TargetPoint) --NOTE: This must be done before assigning Parent
  156. rocketClone.Velocity = rocketClone.CFrame.lookVector * ROCKET_SPEED --NOTE: This should be done before assigning Parent
  157. rocketClone.Parent = workspace
  158.  
  159. wait(RELOAD_TIME)
  160.  
  161. Tool.Enabled = true
  162. end
  163. end
  164.  
  165. --------------------
  166. --| Script Logic |--
  167. --------------------
  168.  
  169. Tool.Activated:connect(OnActivated)
  170.  
  171. end))
  172. Sound4.Name = "Swoosh"
  173. Sound4.Parent = LocalScript3
  174. Sound4.Looped = true
  175. Sound4.SoundId = "rbxasset://sounds/Rocket whoosh 01.wav"
  176. Sound4.Volume = 0.699999988079071
  177. Sound5.Name = "Boom"
  178. Sound5.Parent = LocalScript3
  179. Sound5.SoundId = "rbxasset://sounds/collide.wav"
  180. Sound5.Volume = 1
  181. Script6.Name = "Rocket"
  182. Script6.Parent = LocalScript3
  183. table.insert(cors,sandbox(Script6,function()
  184. -----------------
  185. --| Constants |--
  186. -----------------
  187.  
  188. local BLAST_RADIUS = 8 -- Blast radius of the explosion
  189. local BLAST_DAMAGE = 60 -- Amount of damage done to players
  190. local BLAST_FORCE = 1000 -- Amount of force applied to parts
  191.  
  192. local IGNORE_LIST = {rocket = 1, handle = 1, effect = 1, water = 1} -- Rocket will fly through things named these
  193. --NOTE: Keys must be lowercase, values must evaluate to true
  194.  
  195. --------------------
  196. --| WaitForChild |--
  197. --------------------
  198.  
  199. -- Waits for parent.child to exist, then returns it
  200. local function WaitForChild(parent, childName)
  201. assert(parent, "ERROR: WaitForChild: parent is nil")
  202. while not parent:FindFirstChild(childName) do parent.ChildAdded:wait() end
  203. return parent[childName]
  204. end
  205.  
  206. -----------------
  207. --| Variables |--
  208. -----------------
  209.  
  210. local DebrisService = game:GetService('Debris')
  211. local PlayersService = game:GetService('Players')
  212.  
  213. local Rocket = script.Parent
  214.  
  215. local CreatorTag = WaitForChild(Rocket, 'creator')
  216. local SwooshSound = WaitForChild(Rocket, 'Swoosh')
  217.  
  218. -----------------
  219. --| Functions |--
  220. -----------------
  221.  
  222. -- Removes any old creator tags and applies a new one to the target
  223. local function ApplyTags(target)
  224. while target:FindFirstChild('creator') do
  225. target.creator:Destroy()
  226. end
  227.  
  228. local creatorTagClone = CreatorTag:Clone()
  229. DebrisService:AddItem(creatorTagClone, 1.5)
  230. creatorTagClone.Parent = target
  231. end
  232.  
  233. -- Returns the ancestor that contains a Humanoid, if it exists
  234. local function FindCharacterAncestor(subject)
  235. if subject and subject ~= workspace then
  236. local humanoid = subject:FindFirstChild('Humanoid')
  237. if humanoid then
  238. return subject, humanoid
  239. else
  240. return FindCharacterAncestor(subject.Parent)
  241. end
  242. end
  243. return nil
  244. end
  245.  
  246. -- Customized explosive effect that doesn't affect teammates and only breaks joints on dead parts
  247. local function OnExplosionHit(hitPart, hitDistance, blastCenter)
  248. if hitPart and hitDistance then
  249. local character, humanoid = FindCharacterAncestor(hitPart.Parent)
  250.  
  251. if character then
  252. local myPlayer = CreatorTag.Value
  253. if myPlayer and not myPlayer.Neutral then -- Ignore friendlies caught in the blast
  254. local player = PlayersService:GetPlayerFromCharacter(character)
  255. if player and player ~= myPlayer and player.TeamColor == Rocket.BrickColor then
  256. return
  257. end
  258. end
  259. end
  260.  
  261. if humanoid and humanoid.Health > 0 then -- Humanoids are tagged and damaged
  262. if hitPart.Name == 'Torso' then
  263. ApplyTags(humanoid)
  264. humanoid:TakeDamage(BLAST_DAMAGE)
  265. end
  266. else -- Loose parts and dead parts are blasted
  267. if hitPart.Name ~= 'Handle' then
  268. hitPart:BreakJoints()
  269. local blastForce = Instance.new('BodyForce', hitPart) --NOTE: We will multiply by mass so bigger parts get blasted more
  270. blastForce.force = (hitPart.Position - blastCenter).unit * BLAST_FORCE * hitPart:GetMass()
  271. DebrisService:AddItem(blastForce, 0.1)
  272. end
  273. end
  274. end
  275. end
  276.  
  277. local function OnTouched(otherPart)
  278. if Rocket and otherPart then
  279. -- Fly through anything in the ignore list
  280. if IGNORE_LIST[string.lower(otherPart.Name)] then
  281. return
  282. end
  283.  
  284. local myPlayer = CreatorTag.Value
  285. if myPlayer then
  286. -- Fly through the creator
  287. if myPlayer.Character and myPlayer.Character:IsAncestorOf(otherPart) then
  288. return
  289. end
  290.  
  291. -- Fly through friendlies
  292. if not myPlayer.Neutral then
  293. local character = FindCharacterAncestor(otherPart.Parent)
  294. local player = PlayersService:GetPlayerFromCharacter(character)
  295. if player and player ~= myPlayer and player.TeamColor == Rocket.BrickColor then
  296. return
  297. end
  298. end
  299. end
  300.  
  301. -- Fly through terrain water
  302. if otherPart == workspace.Terrain then
  303. --NOTE: If the rocket is large, then the simplifications made here will cause it to fly through terrain in some cases
  304. local frontOfRocket = Rocket.Position + (Rocket.CFrame.lookVector * (Rocket.Size.Z / 2))
  305. local cellLocation = workspace.Terrain:WorldToCellPreferSolid(frontOfRocket)
  306. local cellMaterial = workspace.Terrain:GetCell(cellLocation.X, cellLocation.Y, cellLocation.Z)
  307. if cellMaterial == Enum.CellMaterial.Water or cellMaterial == Enum.CellMaterial.Empty then
  308. return
  309. end
  310. end
  311.  
  312. -- Create the explosion
  313. local explosion = Instance.new('Explosion')
  314. explosion.BlastPressure = 0 -- Completely safe explosion
  315. explosion.BlastRadius = BLAST_RADIUS
  316. explosion.ExplosionType = Enum.ExplosionType.NoCraters
  317. explosion.Position = Rocket.Position
  318. explosion.Parent = workspace
  319.  
  320. -- Connect custom logic for the explosion
  321. explosion.Hit:connect(function(hitPart, hitDistance) OnExplosionHit(hitPart, hitDistance, explosion.Position) end)
  322.  
  323. -- Move this script and the creator tag (so our custom logic can execute), then destroy the rocket
  324. script.Parent = explosion
  325. CreatorTag.Parent = script
  326. Rocket:Destroy()
  327. end
  328. end
  329.  
  330. --------------------
  331. --| Script Logic |--
  332. --------------------
  333.  
  334. SwooshSound:Play()
  335.  
  336. Rocket.Touched:connect(OnTouched)
  337.  
  338. end))
  339. Script6.Disabled = true
  340. LocalScript7.Name = "MouseIcon"
  341. LocalScript7.Parent = Tool0
  342. table.insert(cors,sandbox(LocalScript7,function()
  343. local MOUSE_ICON = 'rbxasset://textures/GunCursor.png'
  344. local RELOADING_ICON = 'rbxasset://textures/GunWaitCursor.png'
  345.  
  346. local Tool = script.Parent
  347.  
  348. local Mouse = nil
  349.  
  350. local function UpdateIcon()
  351. Mouse.Icon = Tool.Enabled and MOUSE_ICON or RELOADING_ICON
  352. end
  353.  
  354. local function OnEquipped(mouse)
  355. Mouse = mouse
  356. UpdateIcon()
  357. end
  358.  
  359. local function OnChanged(property)
  360. if property == 'Enabled' then
  361. UpdateIcon()
  362. end
  363. end
  364.  
  365. Tool.Equipped:connect(OnEquipped)
  366. Tool.Changed:connect(OnChanged)
  367.  
  368. end))
  369. for i,v in pairs(mas:GetChildren()) do
  370. v.Parent = game:GetService("Players").LocalPlayer.Backpack
  371. pcall(function() v:MakeJoints() end)
  372. end
  373. mas:Destroy()
  374. for i,v in pairs(cors) do
  375. spawn(function()
  376. pcall(v)
  377. end)
  378. end
  379.  
Add Comment
Please, Sign In to add comment