Advertisement
vallentganteng

rainbow cape

Apr 20th, 2019
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.75 KB | None | 0 0
  1. --https://github.com/Mokiros/roblox-FE-compatibility
  2. if game:GetService("RunService"):IsClient() then error("Script must be server-side in order to work; use h/ and not hl/") end
  3. local Player,game,owner = owner,game
  4. local RealPlayer = Player
  5. do print("FE Compatibility code V2 by Mokiros")local RealPlayer=RealPlayer;script.Parent=RealPlayer.Character;local a=function(b)b[1].f[b[2]]=nil end;local c={__index={disconnect=a,Disconnect=a}}local d={__index={Connect=function(b,e)local f=tostring(math.random(0,10000))while b.f[f]do f=tostring(math.random(0,10000))end;b.f[f]=e;return setmetatable({b,f},c)end}}d.__index.connect=d.__index.Connect;local function g()return setmetatable({f={}},d)end;local h={Hit=CFrame.new(),KeyUp=g(),KeyDown=g(),Button1Up=g(),Button1Down=g(),Button2Up=g(),Button2Down=g()}h.keyUp=h.KeyUp;h.keyDown=h.KeyDown;local i={InputBegan=g(),InputEnded=g()}local CAS={Actions={},BindAction=function(self,j,k,l,...)CAS.Actions[j]=k and{Name=j,Function=k,Keys={...}}or nil end}CAS.UnbindAction=CAS.BindAction;local function m(self,n,...)for o,e in pairs(self[n].f)do e(...)end end;h.T=m;i.T=m;local p=Instance.new("RemoteEvent")p.Name="UserInput_Event"p.OnServerEvent:Connect(function(q,r)if q~=RealPlayer then return end;h.Target=r.e;h.Hit=r.d;if not r.f then local s=r.c==Enum.UserInputState.Begin;if r.b==Enum.UserInputType.MouseButton1 then return h:T(s and"Button1Down"or"Button1Up")end;if r.b==Enum.UserInputType.MouseButton2 then return h:T(s and"Button2Down"or"Button2Up")end;for o,t in pairs(CAS.Actions)do for o,u in pairs(t.Keys)do if u==r.a then t.Function(t.Name,r.c,r)end end end;h:T(s and"KeyDown"or"KeyUp",r.a.Name:lower())i:T(s and"InputBegan"or"InputEnded",r,false)end end)p.Parent=NLS([==[local a=script:WaitForChild("UserInput_Event")local b=owner:GetMouse()local c=game:GetService("UserInputService")local d=function(e,f)if f then return end;a:FireServer({a=e.KeyCode,b=e.UserInputType,c=e.UserInputState,d=b.Hit,e=b.Target})end;c.InputBegan:Connect(d)c.InputEnded:Connect(d)local g,h;local i=game:GetService("RunService").Heartbeat;while true do if g~=b.Hit or h~=b.Target then g,h=b.Hit,b.Target;a:FireServer({f=1,Target=h,d=g})end;for j=1,2 do i:Wait()end end]==],script)local v=game;local w={__index=function(self,u)local x=rawget(self,"_RealService")if x then return typeof(x[u])=="function"and function(o,...)return x[u](x,...)end or x[u]end end,__newindex=function(self,u,y)local x=rawget(self,"_RealService")if x then x[u]=y end end}local function z(t,A)t._RealService=typeof(A)=="string"and v:GetService(A)or A;return setmetatable(t,w)end;local B={GetService=function(self,x)return rawget(self,x)or v:GetService(x)end,Players=z({LocalPlayer=z({GetMouse=function(self)return h end},Player)},"Players"),UserInputService=z(i,"UserInputService"),ContextActionService=z(CAS,"ContextActionService"),RunService=z({_btrs={},RenderStepped=v:GetService("RunService").Heartbeat,BindToRenderStep=function(self,j,o,k)self._btrs[j]=self.Heartbeat:Connect(k)end,UnbindFromRenderStep=function(self,j)self._btrs[j]:Disconnect()end},"RunService")}rawset(B.Players,"localPlayer",B.Players.LocalPlayer)B.service=B.GetService;z(B,game)game,owner=B,B.Players.LocalPlayer end
  6.  
  7. local verlet = {}
  8. verlet.step_time = 1 / 50
  9. verlet.gravity = Vector3.new(0, -10, 0)
  10.  
  11. local char = game.Players.LocalPlayer.Character
  12. local torso = char:WaitForChild("Torso")
  13. local parts = {}
  14. local render = game:GetService("RunService").RenderStepped
  15.  
  16. wait(2)
  17.  
  18. local point = {}
  19. local link = {}
  20. local rope = {}
  21.  
  22. local function ccw(A,B,C)
  23. return (C.y-A.y) * (B.x-A.x) > (B.y-A.y) * (C.x-A.x)
  24. end
  25.  
  26. local function intersect(A,B,C,D)
  27. return ccw(A,C,D) ~= ccw(B,C,D) and ccw(A,B,C) ~= ccw(A,B,D)
  28. end
  29.  
  30. local function vec2(v)
  31. return Vector2.new(v.x, v.z)
  32. end
  33.  
  34. function point:step()
  35. if not self.fixed then
  36. local derivative = (self.position - self.last_position) * 0.95
  37. self.last_position = self.position
  38. self.position = self.position + derivative + (self.velocity * verlet.step_time ^ 2)
  39. --[[local torsoP = torso.CFrame * CFrame.new(-1, 0, 0.5)
  40. local torsoE = torso.CFrame * CFrame.new(1, 0, 0.5)
  41. local pointE = self.position + torso.CFrame.lookVector * 100
  42. local doIntersect = intersect(vec2(torsoP.p), vec2(torsoE.p), vec2(self.position), vec2(pointE))
  43. if not doIntersect then
  44. self.postition = self.position - torso.CFrame.lookVector * 10
  45. end]]
  46. end
  47. end
  48.  
  49. function link:step()
  50. for i = 1, 1 do
  51. local distance = self.point1.position - self.point2.position
  52. local magnitude = distance.magnitude
  53. local differance = (self.length - magnitude) / magnitude
  54. local translation = ((self.point1.fixed or self.point2.fixed) and 1 or 0.6) * distance * differance
  55. if not self.point1.fixed then
  56. self.point1.position = self.point1.position + translation
  57. end
  58. if not self.point2.fixed then
  59. self.point2.position = self.point2.position - translation
  60. end
  61. end
  62. end
  63.  
  64. function verlet.new(class, a, b, c)
  65. if class == "Point" then
  66. local new = {}
  67. setmetatable(new, {__index = point})
  68. new.class = class
  69. new.position = a or Vector3.new()
  70. new.last_position = new.position
  71. new.velocity = verlet.gravity
  72. new.fixed = false
  73. return new
  74. elseif class == "Link" then
  75. local new = {}
  76. setmetatable(new, {__index = link})
  77. new.class = class
  78. new.point1 = a
  79. new.point2 = b
  80. new.length = c or (a.position - b.position).magnitude
  81. return new
  82. elseif class == "Rope" then
  83. local new = {}
  84. setmetatable(new, {__index = link})
  85. new.class = class
  86. new.start_point = a
  87. new.finish_point = b
  88. new.points = {}
  89. new.links = {}
  90. local inc = (b - a) / 10
  91. for i = 0, 10 do
  92. table.insert(new.points, verlet.new("Point", a + (i * inc)))
  93. end
  94. for i = 2, #new.points do
  95. table.insert(new.links, verlet.new("Link", new.points[i - 1], new.points[i]))
  96. end
  97. return new
  98. end
  99. end
  100.  
  101. local tris = {}
  102. local triParts = {}
  103.  
  104. local function GetDiscoColor(hue)
  105. local section = hue % 1 * 3
  106. local secondary = 0.5 * math.pi * (section % 1)
  107. if section < 1 then
  108. return Color3.new(1, 1 - math.cos(secondary), 1 - math.sin(secondary))
  109. elseif section < 2 then
  110. return Color3.new(1 - math.sin(secondary), 1, 1 - math.cos(secondary))
  111. else
  112. return Color3.new(1 - math.cos(secondary), 1 - math.sin(secondary), 1)
  113. end
  114. end
  115.  
  116. local function setupPart(part)
  117. part.Anchored = true
  118. part.FormFactor = 3
  119. part.CanCollide = false
  120. part.TopSurface = 10
  121. part.BottomSurface = 10
  122. part.LeftSurface = 10
  123. part.RightSurface = 10
  124. part.FrontSurface = 10
  125. part.BackSurface = 10
  126. part.Material = "Neon"
  127. local m = Instance.new("SpecialMesh", part)
  128. m.MeshType = "Wedge"
  129. m.Scale = Vector3.new(0.2, 1, 1)
  130. return part
  131. end
  132.  
  133. local function CFrameFromTopBack(at, top, back)
  134. local right = top:Cross(back)
  135. 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)
  136. end
  137.  
  138. local function drawTri(parent, a, b, c)
  139. local this = {}
  140. local mPart1 = table.remove(triParts, 1) or setupPart(Instance.new("Part"))
  141. local mPart2 = table.remove(triParts, 1) or setupPart(Instance.new("Part"))
  142. function this:Set(a, b, c)
  143. local ab, bc, ca = b-a, c-b, a-c
  144. local abm, bcm, cam = ab.magnitude, bc.magnitude, ca.magnitude
  145. local edg1 = math.abs(0.5 + ca:Dot(ab)/(abm*abm))
  146. local edg2 = math.abs(0.5 + ab:Dot(bc)/(bcm*bcm))
  147. local edg3 = math.abs(0.5 + bc:Dot(ca)/(cam*cam))
  148. if edg1 < edg2 then
  149. if edg1 >= edg3 then
  150. a, b, c = c, a, b
  151. ab, bc, ca = ca, ab, bc
  152. abm = cam
  153. end
  154. else
  155. if edg2 < edg3 then
  156. a, b, c = b, c, a
  157. ab, bc, ca = bc, ca, ab
  158. abm = bcm
  159. else
  160. a, b, c = c, a, b
  161. ab, bc, ca = ca, ab, bc
  162. abm = cam
  163. end
  164. end
  165.  
  166. local len1 = -ca:Dot(ab)/abm
  167. local len2 = abm - len1
  168. local width = (ca + ab.unit*len1).magnitude
  169.  
  170. local maincf = CFrameFromTopBack(a, ab:Cross(bc).unit, -ab.unit)
  171.  
  172. if len1 > 0.2 then
  173. mPart1.Parent = parent
  174. mPart1.Size = Vector3.new(0.2, width, len1)
  175. mPart1.CFrame = maincf*CFrame.Angles(math.pi,0,math.pi/2)*CFrame.new(0,width/2,len1/2)
  176. else
  177. mPart1.Parent = nil
  178. end
  179.  
  180. if len2 > 0.2 then
  181. mPart2.Parent = parent
  182. mPart2.Size = Vector3.new(0.2, width, len2)
  183. mPart2.CFrame = maincf*CFrame.Angles(math.pi,math.pi,-math.pi/2)*CFrame.new(0,width/2,-len1 - len2/2)
  184. else
  185. mPart2.Parent = nil
  186. end
  187. end
  188. function this:SetProperty(prop, value)
  189. mPart1[prop] = value
  190. mPart2[prop] = value
  191. end
  192. this:Set(a, b, c)
  193. function this:Destroy()
  194. mPart1:Destroy()
  195. mPart2:Destroy()
  196. end
  197. this.p1 = mPart1
  198. this.p2 = mPart2
  199. this.p1.BrickColor = BrickColor.new(GetDiscoColor(math.noise(0.5, 0.5, this.p1.CFrame.Y * 0.5 + time())))
  200. this.p2.BrickColor = BrickColor.new(GetDiscoColor(math.noise(0.5, 0.5, this.p2.CFrame.Y * 0.5 + time())))
  201. return this
  202. end
  203.  
  204. function verlet.draw(object, id)
  205. if object.class == "Point" then
  206. local part = parts[id]
  207. part.BrickColor = BrickColor.new(1, 1, 1)
  208. part.Transparency = 0
  209. part.formFactor = 3
  210. part.Anchored = true
  211. part.CanCollide = false
  212. part.TopSurface = 0
  213. part.BottomSurface = 0
  214. part.Size = Vector3.new(0.35, 0.35, 0.35)
  215. part.Material = "Neon"
  216. part.CFrame = CFrame.new(object.position)
  217. part.Parent = torso
  218. return part
  219. elseif object.class == "Link" then
  220. local part = parts[id]
  221. local dist = (object.point1.position - object.point2.position).magnitude
  222. part.Size = Vector3.new(0.2, 0.2, dist)
  223. part.CFrame = CFrame.new(object.point1.position, object.point2.position) * CFrame.new(0, 0, dist * -0.5)
  224. part.Parent = torso
  225. return part
  226. end
  227. end
  228.  
  229. function verlet.clear()
  230. for _, v in pairs(workspace:GetChildren()) do
  231. if v.Name == "Part" then
  232. v:Destroy()
  233. end
  234. end
  235. end
  236.  
  237. local points = {}
  238. local links = {}
  239.  
  240. for x = 0, 2 do
  241. points[x] = {}
  242. for y = 0, 3 do
  243. points[x][y] = verlet.new("Point", torso.Position + Vector3.new(x * 0.8 - 2, 2 - y * 0.8, 5 + y * 0.4))
  244. points[x][y].fixed = y == 0
  245. end
  246. end
  247.  
  248. for x = 1, 2 do
  249. for y = 0, 3 do
  250. links[#links + 1] = verlet.new("Link", points[x][y], points[x - 1][y], 1 + y * 0.08)
  251. end
  252. end
  253.  
  254. for x = 0, 2 do
  255. for y = 1, 3 do
  256. links[#links + 1] = verlet.new("Link", points[x][y], points[x][y - 1], 1.2 + y * 0.03)
  257. end
  258. end
  259.  
  260. render:connect(function()
  261. for x = 0, 2 do
  262. for y = 0, 3 do
  263. if y == 0 then
  264. points[x][y].position = (torso.CFrame * CFrame.new(x * 1 - 1, 1, 0.5)).p
  265. else
  266. points[x][y]:step()
  267. end
  268. end
  269. end
  270. for i = 1, #links do
  271. links[i]:step()
  272. end
  273. for i = 1, #tris do
  274. triParts[#triParts + 1] = tris[i].p1
  275. triParts[#triParts + 1] = tris[i].p2
  276. end
  277. tris = {}
  278. for x = 1, 2 do
  279. for y = 1, 3 do
  280. tris[#tris + 1] = drawTri(torso, points[x - 1][y - 1].position, points[x - 1][y].position, points[x][y - 1].position)
  281. tris[#tris + 1] = drawTri(torso, points[x][y].position, points[x - 1][y].position, points[x][y - 1].position)
  282. end
  283. end
  284. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement