Advertisement
Guest User

Untitled

a guest
Mar 19th, 2019
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 16.18 KB | None | 0 0
  1. local _G,_VERSION,assert,collectgarbage,dofile,error,getfenv,getmetatable,ipairs,load,loadfile,loadstring,next,pairs,pcall,print,rawequal,rawget,rawset,select,setfenv,setmetatable,tonumber,tostring,type,unpack,xpcall,coroutine,math,string,table,game,Game,workspace,Workspace,delay,Delay,LoadLibrary,printidentity,Spawn,tick,time,version,Version,Wait,wait,PluginManager,crash__,LoadRobloxLibrary,settings,Stats,stats,UserSettings,Enum,Color3,BrickColor,Vector2,Vector3,Vector3int16,CFrame,UDim,UDim2,Ray,Axes,Faces,Instance,Region3,Region3int16=_G,_VERSION,assert,collectgarbage,dofile,error,getfenv,getmetatable,ipairs,load,loadfile,loadstring,next,pairs,pcall,print,rawequal,rawget,rawset,select,setfenv,setmetatable,tonumber,tostring,type,unpack,xpcall,coroutine,math,string,table,game,Game,workspace,Workspace,delay,Delay,LoadLibrary,printidentity,Spawn,tick,time,version,Version,Wait,wait,PluginManager,crash__,LoadRobloxLibrary,settings,Stats,stats,UserSettings,Enum,Color3,BrickColor,Vector2,Vector3,Vector3int16,CFrame,UDim,UDim2,Ray,Axes,Faces,Instance,Region3,Region3int16
  2. math.randomseed(tick())
  3.  
  4. local Players = Game:GetService('Players')
  5. local StarterPack = Game:GetService('StarterPack')
  6. local StarterGui = Game:GetService('StarterGui')
  7. local Lighting = Game:GetService('Lighting')
  8. local Debris = Game:GetService('Debris')
  9. local Teams = Game:GetService('Teams')
  10. local BadgeService = Game:GetService('BadgeService')
  11. local InsertService = Game:GetService('InsertService')
  12. local Terrain = Workspace.Terrain
  13. local VerifyArg
  14.  
  15. local function IsA(value, data_type)
  16. data_type = VerifyArg(data_type, 'string', "data_type")
  17. if type(value) == data_type then return true end -- Lua types
  18. if pcall(function() assert(Game.IsA(value, data_type)) end) then return true end -- Instance types
  19. if pcall(function() assert(Enum[data_type]) end) then -- Enum types
  20. for _, enum in next, Enum[data_type]:GetEnumItems() do
  21. if value == enum then
  22. return true
  23. end
  24. end
  25. elseif pcall(Enum.Material.GetEnumItems, value) then
  26. for _, enum in next, value:GetEnumItems() do
  27. if value == enum then
  28. return true
  29. end
  30. end
  31. end
  32. if data_type == 'Color3' and pcall(function() Instance.new('Color3Value').Value = value end) then return true -- Color3
  33. elseif data_type == 'BrickColor' and pcall(function() Instance.new('BrickColorValue').Value = value end) then return true -- BrickColor
  34. elseif data_type == 'Vector2' and pcall(function() return Vector2.new() + value end) then return true -- Vector2
  35. elseif data_type == 'Vector3' and pcall(function() Instance.new('Vector3Value').Value = value end) then return true -- Vector3
  36. elseif (data_type == 'CFrame' or data_type == 'CoordinateFrame') and pcall(function() Instance.new('CFrameValue').Value = value end) then return true -- CFrame
  37. elseif data_type == 'UDim' and pcall(function() return UDim.new() + value end) then return true -- UDim
  38. elseif data_type == 'UDim2' and pcall(function() Instance.new('Frame').Position = value end) then return true -- UDim2
  39. elseif data_type == 'Ray' and pcall(function() Ray.new(Vector3.new(), Vector3.new()).Distance(value, Vector3.new()) end) then return true -- Ray
  40. elseif data_type == 'Axes' and pcall(function() Instance.new('ArcHandles').Axes = value end) then return true -- Axes
  41. elseif data_type == 'Faces' and pcall(function() Instance.new('Handles').Faces = value end) then return true -- Faces
  42. elseif data_type == 'Enum' and pcall(Enum.Material.GetEnumItems, value) then return true -- Enum
  43. elseif data_type == 'RBXScriptSignal' then
  44. local _, connection = pcall(function() return Game.AllowedGearTypeChanged.connect(value) end)
  45. if _ and connection then
  46. connection:disconnect()
  47. return true
  48. end
  49. end
  50. return false
  51. end
  52.  
  53. local function CppIsA(value, data_type)
  54. data_type = VerifyArg(data_type, 'string', "data_type")
  55. if data_type == 'int' then
  56. if pcall(function() Instance.new('IntValue').Value = value end) then
  57. return true
  58. end
  59. elseif data_type == 'double' then
  60. if pcall(function() Instance.new('NumberValue').Value = value end) then
  61. return true
  62. end
  63. elseif data_type == 'bool' then
  64. if pcall(function() Instance.new('BoolValue').Value = value end) then
  65. return true
  66. end
  67. elseif data_type == 'string' then
  68. if pcall(function() Instance.new('StringValue').Value = value end) then
  69. return true
  70. end
  71. elseif data_type == 'float' then
  72. if pcall(function() Instance.new('ClickDetector').MaxActivationDistance = value end) then
  73. return true
  74. end
  75. end
  76. return false
  77. end
  78.  
  79. local function GetType(value)
  80. if IsA(value, 'Instance') then return value.ClassName
  81. elseif IsA(value, 'Enum') then return 'Enum'
  82. elseif IsA(value, 'Color3') then return 'Color3'
  83. elseif IsA(value, 'BrickColor') then return 'BrickColor'
  84. elseif IsA(value, 'Vector2') then return 'Vector2'
  85. elseif IsA(value, 'Vector3') then return 'Vector3'
  86. elseif IsA(value, 'CFrame') then return 'CFrame'
  87. elseif IsA(value, 'UDim') then return 'UDim'
  88. elseif IsA(value, 'UDim2') then return 'UDim2'
  89. elseif IsA(value, 'Ray') then return 'Ray'
  90. elseif IsA(value, 'Axes') then return 'Axes'
  91. elseif IsA(value, 'Faces') then return 'Faces'
  92. elseif IsA(value, 'RBXScriptSignal') then return 'RBXScriptSignal'
  93. else return type(value)
  94. end
  95. end
  96.  
  97. function VerifyArg(value, data_type, arg_name, optional)
  98. if type(data_type) ~= 'string' then error("bad 'data_type' argument (string expected, got " .. GetType(data_type) .. ")", 2) end
  99. if type(arg_name) ~= 'string' then error("bad 'arg_name' argument (string expected, got " .. GetType(arg_name) .. ")") end
  100.  
  101. if optional and value == nil then
  102. return value
  103. elseif type(value) == data_type then
  104. return value
  105. elseif IsA(value, data_type) or CppIsA(value, data_type) then
  106. return value
  107. elseif data_type == 'number' and tonumber(value) then
  108. return tonumber(value)
  109. elseif data_type == 'string' and type(value) == 'number' then
  110. return tostring(value)
  111. else
  112. error("bad '" .. arg_name .. "'" .. (optional and " optional" or "") .. " argument (" .. data_type .. " expected, got " .. GetType(value) .. ")", 3)
  113. end
  114. end
  115.  
  116. local function Modify(instance, t)
  117. instance = VerifyArg(instance, 'Instance', "instance")
  118. t = VerifyArg(t, 'table', "t")
  119. for key, value in next, t do
  120. if type(key) == 'number' then
  121. value.Parent = instance
  122. else
  123. instance[key] = value
  124. end
  125. end
  126. return instance
  127. end
  128.  
  129. local function WaitForChild(Parent, Name)
  130. Parent = VerifyArg(Parent, 'Instance', "Parent")
  131. Name = VerifyArg(Name, 'string', "Name")
  132. local Item = Parent:FindFirstChild(Name)
  133. if not Item then
  134. repeat wait(0) print("Waiting for "..Name) Item = Parent:FindFirstChild(Name) until Item
  135. end
  136. return Item;
  137. end
  138.  
  139. local function CallOnChildren(instance, func)
  140. instance = VerifyArg(instance, 'Instance', "instance")
  141. func = VerifyArg(func, 'function', "func")
  142. func(instance)
  143. for _, child in next, instance:GetChildren() do
  144. CallOnChildren(child, func)
  145. end
  146. end
  147.  
  148. local function GetNearestParent(instance, class_name)
  149. instance = VerifyArg(instance, 'Instance', "instance")
  150. class_name = VerifyArg(class_name, 'string', "class_name")
  151. local ancestor = instance
  152. repeat
  153. ancestor = ancestor.Parent
  154. if ancestor == nil then
  155. return nil
  156. end
  157. until ancestor:IsA(class_name)
  158. return ancestor
  159. end
  160.  
  161. local function GetCharacter(descendant)
  162. descendant = VerifyArg(descendant, 'Instance', "descendant")
  163. local character = descendant
  164. repeat
  165. if character.Parent then
  166. character = character.Parent
  167. else
  168. return nil
  169. end
  170. until Players:GetPlayerFromCharacter(character)
  171. return character, Players:GetPlayerFromCharacter(character)
  172. end
  173.  
  174.  
  175. -- Variables --
  176.  
  177. local ParentNamesNoDetect = {Water = true; Bodykit = true; Projectiles = true; Water = true; ["!Water"] = true; Wake = true;}
  178. local ChildrenParentNoDetect = {"Humanoid"}
  179. local NamesNoDetect = {Wake = true;}
  180. local WaterLevel = 3000
  181. local ShipGui = WaitForChild(script, "ShipGui")
  182.  
  183. local function RoundNumber(Number, Divider)
  184. Divider = Divider or 1
  185. return (math.floor((Number/Divider)+5)*Divider)
  186. end
  187.  
  188. local function ClampNumber(Number, High, Low)
  189. if Number > High then
  190. return High;
  191. elseif Number < Low then
  192. return Low;
  193. end
  194. return Number;
  195. end
  196.  
  197. local function MPStoKPS(MPS) -- Meters per a econd to Kilometers per a second
  198. return MPS * 3.6
  199. end
  200.  
  201.  
  202. local function SetupBoat(Boat, VehicleSeat, Configuration)
  203. --local Boat = script.Parent
  204. --local VehicleSeat = WaitForChild(Boat, "VehicleSeat")
  205. --local Base = WaitForChild(Boat, "Base")
  206. local ShipHealth = WaitForChild(VehicleSeat, "ShipHealth")
  207. local EngineSound = WaitForChild(VehicleSeat, "EngineSound")
  208. local BodyGyro = WaitForChild(VehicleSeat, "BodyGyro")
  209. local BodyVelocity = WaitForChild(VehicleSeat, "BodyVelocity")
  210. local BodyPosition = WaitForChild(VehicleSeat, "BodyPosition")
  211. local BodyAngularVelocity = WaitForChild(VehicleSeat, "BodyAngularVelocity")
  212. local Wake = Modify(Instance.new("Model", Boat), {Name="Wake"})
  213.  
  214. ShipHealth.Changed:connect(function ()
  215. if ShipHealth.Value <= 1 then
  216. script.Parent.Disabled = true
  217. script.Parent.TurnSpeed = 0
  218. script.Parent.MaxSpeed = 0
  219. for i = BodyPosition.position.Y,-200,-0.1 do
  220. BodyPosition.position = Vector3.new(0, i, 0)
  221. wait()
  222. end
  223. script.Parent.Parent:Destroy()
  224. end
  225. end)
  226.  
  227. local function GetCharacter(descendant)
  228. local character = descendant
  229. repeat
  230. if character.Parent then
  231. character = character.Parent
  232. else
  233. return nil
  234. end
  235. until Players:GetPlayerFromCharacter(character)
  236. return character, Players:GetPlayerFromCharacter(character)
  237. end
  238.  
  239. local Config = Configuration
  240. Config.NeutralColor = BrickColor.new("Dark stone grey");
  241.  
  242.  
  243. local function Weld(Object, BaseObject)
  244. for _, Item in pairs(Object:GetChildren()) do
  245. if Item:IsA("BasePart") and Item ~= BaseObject and Item.Parent.Name ~= "Cannon" then
  246. local Weld = Modify(Instance.new("Weld", BaseObject), {
  247. Part0 = Item;
  248. Part1 = BaseObject;
  249. C0 = Item.CFrame:inverse()*CFrame.new(Item.Position);
  250. C1 = BaseObject.CFrame:inverse()*CFrame.new(Item.Position);
  251. })
  252. Item.Anchored = false
  253. --print("Welded "..Item:GetFullName())
  254. end
  255. Weld(Item, BaseObject)
  256. end
  257. end
  258.  
  259.  
  260. local function SetupTouch(Part)
  261. for _, Item in pairs(Part:GetChildren()) do
  262. if Item:IsA("BasePart") then
  263. local Name = string.lower(Item.Name)
  264. if Name == "hitdetect" or Name == "hitdetectrecolor" then
  265. Item.Touched:connect(function(NewPart)
  266. print("Touch")
  267. if NewPart and NewPart.Parent and NewPart:IsA("BasePart") and NewPart.CanCollide then
  268. if not (ParentNamesNoDetect[NewPart.Parent.Name] or NamesNoDetect[NewPart.Name]) then
  269. VehicleSeat.MaxSpeed = 0
  270. print("Stop")
  271. else
  272. local Valid = true
  273. for _, ChildName in pairs(ChildrenParentNoDetect) do
  274. if NewPart.Parent:FindFirstChild(ChildName) then
  275. Valid = false
  276. end
  277. end
  278. if Valid then
  279. print("Stop")
  280. VehicleSeat.MaxSpeed = 0
  281. end
  282. end
  283. end
  284. end)
  285. end
  286. end
  287. SetupTouch(Item)
  288. end
  289. end
  290.  
  291. SetupTouch(Boat)
  292. Weld(Boat, VehicleSeat)
  293.  
  294. VehicleSeat.ChildAdded:connect(function(Child)
  295. Spawn(function()
  296. if Child:IsA("Weld") then
  297. local Torso = Child.Part1
  298. if Torso and Torso:IsA("BasePart") then
  299. local Character, Player = GetCharacter(Torso)
  300. if Character and Player then
  301. for _, Item in pairs(Character:GetChildren()) do
  302. if Item:IsA("Model") and Item ~= Boat then
  303. Item:Destroy(); -- Remove all other boats.
  304. end
  305. end
  306.  
  307. Boat.Parent = Character
  308. VehicleSeat.Anchored = false
  309.  
  310. repeat wait(0) until Player:FindFirstChild("PlayerGui")
  311. local Gui = ShipGui:Clone()
  312. local MainFrame = WaitForChild(Gui, "MainFrame")
  313. local ShipName = WaitForChild(MainFrame, "ShipName")
  314. local ShipSpeed = WaitForChild(MainFrame, "ShipSpeed")
  315. local HealthRed = WaitForChild(MainFrame, "HealthRed")
  316. local HealthGreen = WaitForChild(HealthRed, "HealthGreen")
  317.  
  318. ShipName.Text = Config.ShipName
  319. ShipSpeed.Text = "Shipspeed: 0.000 m/ps";
  320.  
  321. Spawn(function()
  322. while Gui and Gui.Parent do
  323. wait(0.07)
  324. ShipSpeed.Text = "Shipspeed: "..RoundNumber(MPStoKPS(VehicleSeat.Velocity.magnitude/20), 0.001).." kph"
  325. HealthGreen.Size = UDim2.new(ShipHealth.Value/ShipHealth.MaxValue, 0, 1, 0)
  326. end
  327. print("Connection disconnected")
  328. end)
  329.  
  330. Gui.Parent = Player.PlayerGui
  331.  
  332. Child.AncestryChanged:connect(function(Child, Parent)
  333. if not Parent then
  334. if Gui then
  335. Gui:Destroy()
  336. end
  337.  
  338. VehicleSeat.TurnSpeed = 0
  339. VehicleSeat.MaxSpeed = 0
  340. end
  341. end)
  342. end
  343. end
  344. end
  345. end)
  346. end)
  347.  
  348. local RotationX, RotationY, RotationZ = VehicleSeat.CFrame:toEulerAnglesXYZ()
  349.  
  350. BodyGyro.cframe = CFrame.Angles(0, RotationY, 0)
  351. Boat:MakeJoints()
  352.  
  353. while true do
  354. local VehicleSeatThrottle = VehicleSeat.Throttle
  355. local VehicleSeatMaxSpeed = VehicleSeat.MaxSpeed
  356. local VehicleSeatSteer = VehicleSeat.Steer
  357. if VehicleSeat.Disabled == false then
  358.  
  359. if VehicleSeatThrottle == 1 then
  360. if VehicleSeatMaxSpeed < Config.TopSpeed + 0.5 then
  361. VehicleSeat.MaxSpeed = VehicleSeatMaxSpeed + VehicleSeat.Torque
  362. end
  363. elseif VehicleSeatThrottle == -1 then
  364. if VehicleSeatMaxSpeed > -Config.TopSpeedReverse - 0.5 then
  365. VehicleSeat.MaxSpeed = VehicleSeatMaxSpeed - VehicleSeat.Torque
  366. end
  367. end
  368.  
  369. if VehicleSeatSteer == 1 then
  370. if VehicleSeat.TurnSpeed > -Config.MaxTurn then
  371. VehicleSeat.TurnSpeed = VehicleSeat.TurnSpeed - Config.TurnSpeedAddition
  372. end
  373. elseif VehicleSeatSteer == -1 then
  374. if VehicleSeat.TurnSpeed < Config.MaxTurn then
  375. VehicleSeat.TurnSpeed = VehicleSeat.TurnSpeed + Config.TurnSpeedAddition
  376. end
  377. elseif VehicleSeatSteer == 0 then
  378. if VehicleSeat.TurnSpeed < 0 then
  379. VehicleSeat.TurnSpeed = VehicleSeat.TurnSpeed + Config.TurnSpeedAddition
  380. elseif VehicleSeat.TurnSpeed > 0 then
  381. VehicleSeat.TurnSpeed = VehicleSeat.TurnSpeed - Config.TurnSpeedAddition
  382. end
  383. if VehicleSeat.TurnSpeed <= Config.TurnStop and VehicleSeat.TurnSpeed >= -Config.TurnStop then
  384. VehicleSeat.TurnSpeed = 0
  385. end
  386. end
  387. end
  388.  
  389. local Pitch = math.abs(VehicleSeat.MaxSpeed) / 10 + 2.5
  390.  
  391. if VehicleSeatMaxSpeed > 0 then
  392. if Config.PlayEngineSound then
  393. EngineSound.Pitch = Pitch
  394. EngineSound:Play()
  395. end
  396.  
  397. elseif VehicleSeatMaxSpeed < 0 then
  398. if Config.PlayEngineSound then
  399. EngineSound.Pitch = Pitch
  400. EngineSound:Play()
  401. end
  402.  
  403. else
  404. EngineSound:Stop()
  405.  
  406. end
  407. --BodyGyro.cframe = CFrame.Angles(0, (AngleY) + VehicleSeat.TurnSpeed, 0) * CFrame.new(Direction.p+Vector3.new(0,0,-1))
  408. --BodyGyro.cframe = VehicleSeat.CFrame * CFrame.Angles(0, VehicleSeat.TurnSpeed, 0) --BodyGyro.cframe * CFrame.Angles(0, VehicleSeat.TurnSpeed, 0) -- VehicleSeat.CFrame * CFrame.Angles(0, VehicleSeat.TurnSpeed, 0)
  409. --BodyGyro.cframe = (VehicleSeat.CFrame.lookVector * CFrame.new(1, 0, 0)) * CFrame.Angles(0, VehicleSeat.TurnSpeed, 0)
  410. --print("Ship to be angled at "..((AngleY) + VehicleSeat.TurnSpeed)*(180/math.pi).." with AngleY (Actual) at "..(AngleY*(180/math.pi)).." with an increase of "..VehicleSeat.TurnSpeed*(180/math.pi))
  411.  
  412. BodyAngularVelocity.angularvelocity = Vector3.new(0, VehicleSeat.TurnSpeed, 0)
  413. --local Direction = VehicleSeat.CFrame
  414. --local AngleX, AngleY, AngleZ = Direction:toEulerAnglesXYZ()
  415. local Guide = VehicleSeat.CFrame * CFrame.new(-1, 0, 0)
  416.  
  417. BodyGyro.cframe = CFrame.new(VehicleSeat.Position, Vector3.new(Guide.X, VehicleSeat.CFrame.Y + (-Config.TiltFactor * (VehicleSeat.TurnSpeed/Config.MaxTurn)), Guide.Z))
  418. BodyVelocity.velocity = VehicleSeat.CFrame.lookVector * VehicleSeat.MaxSpeed
  419.  
  420. wait(0.1)
  421. end
  422. end
  423.  
  424. -- Variables --
  425.  
  426. local Boat = script.Parent.Parent
  427. local VehicleSeat = script.Parent
  428.  
  429. local Config = {
  430. TopSpeed = 55; -- How fast it can go. (In studs)
  431. TopSpeedReverse = 30; -- How fast is can go in reverse (In studs)
  432. MaxTurn =0.7; -- 1 = complete turn in 1 second 0.5 means complete turn (360) in 2 seconds.
  433. TurnSpeedAddition = 0.05;
  434. TurnStop = 0.05;
  435. TiltFactor = -0.02; -- Amount it tilts.
  436. ShipName = script.Parent.Parent.Name;
  437. }
  438.  
  439. SetupBoat(Boat, VehicleSeat, Config)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement