Advertisement
Void_scripter0

Rainbow cape

Feb 3rd, 2019
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.94 KB | None | 0 0
  1. if game:GetService("RunService"):IsClient() then error("Script must be server-side in order to work; use h/ and not hl/") end
  2. local Player,game,owner = owner,game
  3. local RealPlayer = Player
  4. do
  5. print("FE Compatibility code by Mokiros | Showcase by Bacon Hair!")
  6. local rp = RealPlayer
  7. script.Parent = rp.Character
  8.  
  9. --RemoteEvent for communicating
  10. local Event = Instance.new("RemoteEvent")
  11. Event.Name = "UserInput_Event"
  12.  
  13. --Fake event to make stuff like Mouse.KeyDown work
  14. local function fakeEvent()
  15. local t = {_fakeEvent=true,Functions={},Connect=function(self,f)table.insert(self.Functions,f) end}
  16. t.connect = t.Connect
  17. return t
  18. end
  19.  
  20. --Creating fake input objects with fake variables
  21. local m = {Target=nil,Hit=CFrame.new(),KeyUp=fakeEvent(),KeyDown=fakeEvent(),Button1Up=fakeEvent(),Button1Down=fakeEvent()}
  22. local UIS = {InputBegan=fakeEvent(),InputEnded=fakeEvent()}
  23. local CAS = {Actions={},BindAction=function(self,name,fun,touch,...)
  24. CAS.Actions[name] = fun and {Name=name,Function=fun,Keys={...}} or nil
  25. end}
  26. --Merged 2 functions into one by checking amount of arguments
  27. CAS.UnbindAction = CAS.BindAction
  28.  
  29. --This function will trigger the events that have been :Connect()'ed
  30. local function te(self,ev,...)
  31. local t = m[ev]
  32. if t and t._fakeEvent then
  33. for _,f in pairs(t.Functions) do
  34. f(...)
  35. end
  36. end
  37. end
  38. m.TrigEvent = te
  39. UIS.TrigEvent = te
  40.  
  41. Event.OnServerEvent:Connect(function(plr,io)
  42. if plr~=rp then return end
  43. m.Target = io.Target
  44. m.Hit = io.Hit
  45. if not io.isMouse then
  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 Mouse = Player:GetMouse()
  66. local UIS = game:GetService("UserInputService")
  67. local input = function(io,a)
  68. if a then return end
  69. --Since InputObject is a client-side instance, we create and pass table instead
  70. Event:FireServer({KeyCode=io.KeyCode,UserInputType=io.UserInputType,UserInputState=io.UserInputState,Hit=Mouse.Hit,Target=Mouse.Target})
  71. end
  72. UIS.InputBegan:Connect(input)
  73. UIS.InputEnded:Connect(input)
  74.  
  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.  
  85. ----Sandboxed game object that allows the usage of client-side methods and services
  86. --Real game object
  87. local _rg = game
  88.  
  89. --Metatable for fake service
  90. local fsmt = {
  91. __index = function(self,k)
  92. local s = rawget(self,"_RealService")
  93. if s then return s[k] end
  94. end,
  95. __newindex = function(self,k,v)
  96. local s = rawget(self,"_RealService")
  97. if s then s[k]=v end
  98. end,
  99. __call = function(self,...)
  100. local s = rawget(self,"_RealService")
  101. if s then return s(...) end
  102. end
  103. }
  104. local function FakeService(t,RealService)
  105. t._RealService = typeof(RealService)=="string" and _rg:GetService(RealService) or RealService
  106. return setmetatable(t,fsmt)
  107. end
  108.  
  109. --Fake game object
  110. local g = {
  111. GetService = function(self,s)
  112. return self[s]
  113. end,
  114. Players = FakeService({
  115. LocalPlayer = FakeService({GetMouse=function(self)return m end},Player)
  116. },"Players"),
  117. UserInputService = FakeService(UIS,"UserInputService"),
  118. ContextActionService = FakeService(CAS,"ContextActionService"),
  119. }
  120. rawset(g.Players,"localPlayer",g.Players.LocalPlayer)
  121. g.service = g.GetService
  122.  
  123. g.RunService = FakeService({
  124. RenderStepped = _rg:GetService("RunService").Heartbeat,
  125. BindToRenderStep = function(self,name,_,fun)
  126.  
  127. end,
  128. UnbindFromRenderStep = function(self,name)
  129. self._btrs[name]:Disconnect()
  130. end,
  131. },"RunService")
  132.  
  133. setmetatable(g,{
  134. __index=function(self,s)
  135. return _rg:GetService(s) or typeof(_rg[s])=="function"
  136. and function(_,...)return _rg[s](_rg,...)end or _rg[s]
  137. end,
  138. __newindex = fsmt.__newindex,
  139. __call = fsmt.__call
  140. })
  141. --Changing owner to fake player object to support owner:GetMouse()
  142. game,owner = g,g.Players.LocalPlayer
  143. end
  144. local verlet = {}
  145. verlet.step_time = 1 / 50
  146. verlet.gravity = Vector3.new(0, -10, 0)
  147.  
  148. local char = game.Players.LocalPlayer.Character
  149. local torso = char:WaitForChild("Torso")
  150. local parts = {}
  151. local render = game:GetService("RunService").RenderStepped
  152.  
  153. wait(2)
  154.  
  155. local point = {}
  156. local link = {}
  157. local rope = {}
  158.  
  159. local function ccw(A,B,C)
  160. return (C.y-A.y) * (B.x-A.x) > (B.y-A.y) * (C.x-A.x)
  161. end
  162.  
  163. local function intersect(A,B,C,D)
  164. return ccw(A,C,D) ~= ccw(B,C,D) and ccw(A,B,C) ~= ccw(A,B,D)
  165. end
  166.  
  167. local function vec2(v)
  168. return Vector2.new(v.x, v.z)
  169. end
  170.  
  171. function point:step()
  172. if not self.fixed then
  173. local derivative = (self.position - self.last_position) * 0.95
  174. self.last_position = self.position
  175. self.position = self.position + derivative + (self.velocity * verlet.step_time ^ 2)
  176. --[[local torsoP = torso.CFrame * CFrame.new(-1, 0, 0.5)
  177. local torsoE = torso.CFrame * CFrame.new(1, 0, 0.5)
  178. local pointE = self.position + torso.CFrame.lookVector * 100
  179. local doIntersect = intersect(vec2(torsoP.p), vec2(torsoE.p), vec2(self.position), vec2(pointE))
  180. if not doIntersect then
  181. self.postition = self.position - torso.CFrame.lookVector * 10
  182. end]]
  183. end
  184. end
  185.  
  186. function link:step()
  187. for i = 1, 1 do
  188. local distance = self.point1.position - self.point2.position
  189. local magnitude = distance.magnitude
  190. local differance = (self.length - magnitude) / magnitude
  191. local translation = ((self.point1.fixed or self.point2.fixed) and 1 or 0.6) * distance * differance
  192. if not self.point1.fixed then
  193. self.point1.position = self.point1.position + translation
  194. end
  195. if not self.point2.fixed then
  196. self.point2.position = self.point2.position - translation
  197. end
  198. end
  199. end
  200.  
  201. function verlet.new(class, a, b, c)
  202. if class == "Point" then
  203. local new = {}
  204. setmetatable(new, {__index = point})
  205. new.class = class
  206. new.position = a or Vector3.new()
  207. new.last_position = new.position
  208. new.velocity = verlet.gravity
  209. new.fixed = false
  210. return new
  211. elseif class == "Link" then
  212. local new = {}
  213. setmetatable(new, {__index = link})
  214. new.class = class
  215. new.point1 = a
  216. new.point2 = b
  217. new.length = c or (a.position - b.position).magnitude
  218. return new
  219. elseif class == "Rope" then
  220. local new = {}
  221. setmetatable(new, {__index = link})
  222. new.class = class
  223. new.start_point = a
  224. new.finish_point = b
  225. new.points = {}
  226. new.links = {}
  227. local inc = (b - a) / 10
  228. for i = 0, 10 do
  229. table.insert(new.points, verlet.new("Point", a + (i * inc)))
  230. end
  231. for i = 2, #new.points do
  232. table.insert(new.links, verlet.new("Link", new.points[i - 1], new.points[i]))
  233. end
  234. return new
  235. end
  236. end
  237.  
  238. local tris = {}
  239. local triParts = {}
  240.  
  241. local function GetDiscoColor(hue)
  242. local section = hue % 1 * 3
  243. local secondary = 0.5 * math.pi * (section % 1)
  244. if section < 1 then
  245. return Color3.new(1, 1 - math.cos(secondary), 1 - math.sin(secondary))
  246. elseif section < 2 then
  247. return Color3.new(1 - math.sin(secondary), 1, 1 - math.cos(secondary))
  248. else
  249. return Color3.new(1 - math.cos(secondary), 1 - math.sin(secondary), 1)
  250. end
  251. end
  252.  
  253. local function setupPart(part)
  254. part.Anchored = true
  255. part.FormFactor = 3
  256. part.CanCollide = false
  257. part.TopSurface = 10
  258. part.BottomSurface = 10
  259. part.LeftSurface = 10
  260. part.RightSurface = 10
  261. part.FrontSurface = 10
  262. part.BackSurface = 10
  263. part.Material = "Neon"
  264. local m = Instance.new("SpecialMesh", part)
  265. m.MeshType = "Wedge"
  266. m.Scale = Vector3.new(0.2, 1, 1)
  267. return part
  268. end
  269.  
  270. local function CFrameFromTopBack(at, top, back)
  271. local right = top:Cross(back)
  272. return CFrame.new(at.x, at.y, at.z, right.x, top.x, back.x, right.y, top.y, back.y, right.z, top.z, back.z)
  273. end
  274.  
  275. local function drawTri(parent, a, b, c)
  276. local this = {}
  277. local mPart1 = table.remove(triParts, 1) or setupPart(Instance.new("Part"))
  278. local mPart2 = table.remove(triParts, 1) or setupPart(Instance.new("Part"))
  279. function this:Set(a, b, c)
  280. local ab, bc, ca = b-a, c-b, a-c
  281. local abm, bcm, cam = ab.magnitude, bc.magnitude, ca.magnitude
  282. local edg1 = math.abs(0.5 + ca:Dot(ab)/(abm*abm))
  283. local edg2 = math.abs(0.5 + ab:Dot(bc)/(bcm*bcm))
  284. local edg3 = math.abs(0.5 + bc:Dot(ca)/(cam*cam))
  285. if edg1 < edg2 then
  286. if edg1 >= edg3 then
  287. a, b, c = c, a, b
  288. ab, bc, ca = ca, ab, bc
  289. abm = cam
  290. end
  291. else
  292. if edg2 < edg3 then
  293. a, b, c = b, c, a
  294. ab, bc, ca = bc, ca, ab
  295. abm = bcm
  296. else
  297. a, b, c = c, a, b
  298. ab, bc, ca = ca, ab, bc
  299. abm = cam
  300. end
  301. end
  302.  
  303. local len1 = -ca:Dot(ab)/abm
  304. local len2 = abm - len1
  305. local width = (ca + ab.unit*len1).magnitude
  306.  
  307. local maincf = CFrameFromTopBack(a, ab:Cross(bc).unit, -ab.unit)
  308.  
  309. if len1 > 0.2 then
  310. mPart1.Parent = parent
  311. mPart1.Size = Vector3.new(0.2, width, len1)
  312. mPart1.CFrame = maincf*CFrame.Angles(math.pi,0,math.pi/2)*CFrame.new(0,width/2,len1/2)
  313. else
  314. mPart1.Parent = nil
  315. end
  316.  
  317. if len2 > 0.2 then
  318. mPart2.Parent = parent
  319. mPart2.Size = Vector3.new(0.2, width, len2)
  320. mPart2.CFrame = maincf*CFrame.Angles(math.pi,math.pi,-math.pi/2)*CFrame.new(0,width/2,-len1 - len2/2)
  321. else
  322. mPart2.Parent = nil
  323. end
  324. end
  325. function this:SetProperty(prop, value)
  326. mPart1[prop] = value
  327. mPart2[prop] = value
  328. end
  329. this:Set(a, b, c)
  330. function this:Destroy()
  331. mPart1:Destroy()
  332. mPart2:Destroy()
  333. end
  334. this.p1 = mPart1
  335. this.p2 = mPart2
  336. this.p1.BrickColor = BrickColor.new(GetDiscoColor(math.noise(0.5, 0.5, this.p1.CFrame.Y * 0.5 + time())))
  337. this.p2.BrickColor = BrickColor.new(GetDiscoColor(math.noise(0.5, 0.5, this.p2.CFrame.Y * 0.5 + time())))
  338. return this
  339. end
  340.  
  341. function verlet.draw(object, id)
  342. if object.class == "Point" then
  343. local part = parts[id]
  344. part.BrickColor = BrickColor.new(1, 1, 1)
  345. part.Transparency = 0
  346. part.formFactor = 3
  347. part.Anchored = true
  348. part.CanCollide = false
  349. part.TopSurface = 0
  350. part.BottomSurface = 0
  351. part.Size = Vector3.new(0.35, 0.35, 0.35)
  352. part.Material = "Neon"
  353. part.CFrame = CFrame.new(object.position)
  354. part.Parent = torso
  355. return part
  356. elseif object.class == "Link" then
  357. local part = parts[id]
  358. local dist = (object.point1.position - object.point2.position).magnitude
  359. part.Size = Vector3.new(0.2, 0.2, dist)
  360. part.CFrame = CFrame.new(object.point1.position, object.point2.position) * CFrame.new(0, 0, dist * -0.5)
  361. part.Parent = torso
  362. return part
  363. end
  364. end
  365.  
  366. function verlet.clear()
  367. for _, v in pairs(workspace:GetChildren()) do
  368. if v.Name == "Part" then
  369. v:Destroy()
  370. end
  371. end
  372. end
  373.  
  374. local points = {}
  375. local links = {}
  376.  
  377. for x = 0, 2 do
  378. points[x] = {}
  379. for y = 0, 3 do
  380. points[x][y] = verlet.new("Point", torso.Position + Vector3.new(x * 0.8 - 2, 2 - y * 0.8, 5 + y * 0.4))
  381. points[x][y].fixed = y == 0
  382. end
  383. end
  384.  
  385. for x = 1, 2 do
  386. for y = 0, 3 do
  387. links[#links + 1] = verlet.new("Link", points[x][y], points[x - 1][y], 1 + y * 0.08)
  388. end
  389. end
  390.  
  391. for x = 0, 2 do
  392. for y = 1, 3 do
  393. links[#links + 1] = verlet.new("Link", points[x][y], points[x][y - 1], 1.2 + y * 0.03)
  394. end
  395. end
  396.  
  397. render:connect(function()
  398. for x = 0, 2 do
  399. for y = 0, 3 do
  400. if y == 0 then
  401. points[x][y].position = (torso.CFrame * CFrame.new(x * 1 - 1, 1, 0.5)).p
  402. else
  403. points[x][y]:step()
  404. end
  405. end
  406. end
  407. for i = 1, #links do
  408. links[i]:step()
  409. end
  410. for i = 1, #tris do
  411. triParts[#triParts + 1] = tris[i].p1
  412. triParts[#triParts + 1] = tris[i].p2
  413. end
  414. tris = {}
  415. for x = 1, 2 do
  416. for y = 1, 3 do
  417. tris[#tris + 1] = drawTri(torso, points[x - 1][y - 1].position, points[x - 1][y].position, points[x][y - 1].position)
  418. tris[#tris + 1] = drawTri(torso, points[x][y].position, points[x - 1][y].position, points[x][y - 1].position)
  419. end
  420. end
  421. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement