Advertisement
Descaii

asd library

Nov 1st, 2019
198
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 18.79 KB | None | 0 0
  1. --
  2.  
  3.  
  4.  
  5.  
  6.  
  7. -- Http link: https://www.dropbox.com/s/zsexg0bjbd0b2gt/Function%20Library.lua?dl=1
  8.  
  9. --[[ Function Storage ]]--
  10.  
  11.  
  12. -- random generators
  13. function random2d(x,y,seed)
  14.     local seedMulti = Random.new(seed or 1):NextInteger(1,1000000)
  15.     local xRand = Random.new(x*seedMulti):NextInteger(1,1000000)
  16.     local yRand = Random.new(-y*seedMulti):NextInteger(1,1000000)
  17.     return Random.new(xRand+yRand):NextNumber()
  18. end
  19.  
  20. -- Recursive Children --
  21. local GetRecursiveChildren=function(P)local t,n,G=table.foreach,{}G=function(c,p)table.insert(n,p)t(p:GetChildren(),G)end t(P:GetChildren(),G)return n end
  22.  
  23. -- table clone --
  24. function cloneTable(t,recursive)
  25.     local e = {}
  26.     for i,v in pairs(t ) do
  27.         local i,v = i,v
  28.         if type(i ) == "table" and recursive then
  29.             i=cloneTable(i,recursive)
  30.         end
  31.         if type(v ) == "table" and recursive then
  32.             v=cloneTable(v,recursive)
  33.         end
  34.         e[i]=v
  35.     end
  36.     setmetatable(e,type(getmetatable(t ))=="table" and getmetatable(t ) or getmetatable(e ))
  37.     return e
  38. end
  39.  
  40. -- Reflect --
  41.  
  42. function reflect(input, normal)
  43.     return -2 * input:Dot(normal) * normal + input;
  44. end
  45.  
  46. --Normal Grabber
  47. local Normals = {} -- Add .lookVector to NormalAngle function to get unit direction of surface in global space
  48. Normals[1]={Side="Right",SurfaceDistance=function(Part)return(Part.Size.X/2)end,NormalAngle=function(Part)return CFrame.new(Part.Position,
  49. (Part.CFrame*CFrame.new(1,0,0)).p)end,Normal=Vector3.new(1,0,0),Angle=CFrame.Angles(0,0,math.rad(-90)),is={X=true,Y=false,Z=false}}
  50. Normals[2]={Side="Top",SurfaceDistance=function(Part)return Part.Size.Y/2 end,NormalAngle=function(Part)return CFrame.new(Part.Position,
  51. (Part.CFrame*CFrame.new(0,1,0)).p)end,Normal=Vector3.new(0,1,0),Angle=CFrame.Angles(math.rad(0*0),0,0),is={X=false,Y=true,Z=false}}
  52. Normals[3]={Side="Back",SurfaceDistance=function(Part)return Part.Size.Z/2 end,NormalAngle=function(Part)return CFrame.new(Part.Position,
  53. (Part.CFrame*CFrame.new(0,0,1)).p)end,Normal=Vector3.new(0,0,1),Angle=CFrame.Angles(math.rad(90),0,0),is={X=false,Y=false,Z=true}}
  54. Normals[4]={Side="Left",SurfaceDistance=function(Part)return Part.Size.X/2 end,NormalAngle=function(Part)return CFrame.new(Part.Position,
  55. (Part.CFrame*CFrame.new(-1,0,0)).p)end,Normal=Vector3.new(-1,0,0),Angle=CFrame.Angles(0,0,math.rad(90)),is={X=true,Y=false,Z=false}}
  56. Normals[5]={Side="Bottom",SurfaceDistance=function(Part)return Part.Size.Y/2 end,NormalAngle=function(Part)return CFrame.new(Part.Position,
  57. (Part.CFrame*CFrame.new(0,-1,0)).p)end,Normal=Vector3.new(0,-1,0),Angle=CFrame.Angles(math.rad(180),0,0),is={X=false,Y=true,Z=false}}
  58. Normals[6]={Side="Front",SurfaceDistance=function(Part)return Part.Size.Z/2 end,NormalAngle=function(Part)return CFrame.new(Part.Position,
  59. (Part.CFrame*CFrame.new(0,0,-1)).p)end,Normal=Vector3.new(0,0,-1),Angle=CFrame.Angles(math.rad(-90),0,0),is={X=false,Y=false,Z=true}}
  60.  
  61.  
  62.  -- miners haven
  63. function getRequiredUpgrades(sval,max,percraise,cap)
  64.     local amount = 0
  65.     local sval = sval
  66.     local tab = {}
  67.     if max then
  68.         repeat
  69.             sval=sval+(sval*percraise)
  70.             amount = amount +1
  71.             table.insert(tab,{sval,amount})
  72.         until sval>=max
  73.     elseif cap then
  74.         for i = 1,cap do
  75.             sval=sval+(sval*percraise)
  76.             amount = amount +1
  77.             table.insert(tab,{sval,amount})
  78.         end
  79.     end
  80.     return amount,sval,tab
  81. end
  82. print(getRequiredUpgrades(81000,500000000,0.45))
  83. -- osu lold--v
  84. function GetImprovement(a,b)
  85.     return (b-a)/(100-b)
  86. end
  87. -- osu --^
  88. --[[ Lerps ]]--
  89.  
  90. -- lerp --
  91. function lerp(a,b,c)
  92.     return a+(b-a)*c
  93. end
  94.  
  95. local Player = game.Players.LocalPlayer
  96. local T = Instance.new("Trail",Player.Character.Head)
  97. T.Texture = "rbxassetid://181044754"
  98. A0,A1 = Instance.new("Attachment",Player.Character.Head),Instance.new("Attachment",Player.Character.Head)]
  99. T.Attachment0,T.Attachment1 = A0,A1
  100. A1.Position = Vector3.new(0,-.5,0)
  101.  
  102.  
  103. function truerandom(a,b)
  104.     return a+(b-a)*math.random()
  105. end
  106.  
  107. -- 2x2 lerp (bilinear)
  108. function biterpolate(x,y,tl,tr,bl,br)
  109.     local top = tl+(tr-tl)*x
  110.     local bottom = bl+(br-bl)*x
  111.     return top+(bottom-top)*y
  112. end
  113.  
  114. local m = {}
  115. -- Color lerp --
  116. function colerp(a,b,c)
  117.     return Color3.new(a.r+(b.r-a.r)*c,a.g+(b.g-a.g)*c,a.b+(b.b-a.b)*c)
  118. end
  119.  
  120. -- Gui lerp --
  121. function glerp(a,b,c)
  122.     local axs,axo,ays,ayo,bxs,bxo,bys,byo=a.X.Scale,a.X.Offset,a.Y.Scale,a.Y.Offset,b.X.Scale,b.X.Offset,b.Y.Scale,b.Y.Offset
  123.     local xs,xo,ys,yo = axs+(bxs-axs)*c,axo+(bxo-axo)*c,ays+(bys-ays)*c,ayo+(byo-ayo)*c
  124.     xo,yo = (axo-bxo)<0 and math.ceil(xo) or math.floor(xo),(ayo-byo)<0 and math.ceil(yo) or math.floor(yo)
  125.     return UDim2.new(xs,xo,ys,yo)
  126. end
  127.  
  128. -- Vector lerp --
  129. function vlerp(a,b,c)
  130.     local x=pcall(function()return a.Z end)
  131.     local d=x and Vector3.new or Vector2.new
  132.     return d(a.X+(b.X-a.X)*c,a.Y+(b.Y-a.Y)*c,x and a.Z-(b.Z-a.Z)*c)
  133. end
  134.  
  135. -- CFrame lerp --
  136. ```lua
  137. function clerp(a,b,m)
  138.     local c,d={a:components()},{b:components()}
  139.     table.foreach(c,function(a,b)c[a]=c[a]+(d[a]-c[a])*m end)
  140.     return CFrame.new(unpack(c))
  141. end
  142. ```
  143.  
  144. function squeeze(h,e,c)
  145.     --[[ this function is used to make mountains rarer and plains more common, it
  146.         squeezes height values towards 0.5, which is water level for this terrain generator
  147.     --]]
  148.     if h>=c then
  149.         return c+((((h-c)/c)^e)/2)
  150.     else
  151.         return c-((((c-h)/c)^e)/2)
  152.     end
  153. end
  154. print(squeeze(0.5,3,0.6))
  155.  
  156. function squeeze(h,e,c)
  157.     if h>=c then
  158.         return c+((h-c)/(1-c))^e*(1-c)
  159.     else
  160.         return c-((c-h)/(c))^e*(c)
  161.     end
  162. end
  163. print(squeeze(.6,3,.7))
  164.  
  165. function test(tab,iter)
  166.     if iter then
  167.         if iter<=3 then
  168.             iter = iter + 1
  169.             return iter,"asd"
  170.         end
  171.     else
  172.         return 0,"asd"
  173.     end
  174. end  
  175. for i,v in test,{asd=1,asd2=2,asd3=3} do
  176.     print(i,v)
  177. end
  178.  
  179. ```lua
  180. function clerp(a,b,m) -- longer, but 5 times more efficient
  181.     local x,y,z,R00,R01,R02,R10,R11,R12,R20,R21,R22 = a:components()
  182.     local x_2,y_2,z_2,R00_2,R01_2,R02_2,R10_2,R11_2,R12_2,R20_2,R21_2,R22_2 = b:components()
  183.     return CFrame.new(x+(x_2-x)*m,y+(y_2-y)*m,z+(z_2-z)*m,R00+(R00_2-R00)*m,R01+(R01_2-R01)*m,
  184.         R02+(R02_2-R02)*m,R10+(R10_2-R10)*m,R11+(R11_2-R11)*m,R12+(R12_2-R12)*m,
  185.         R20+(R20_2-R20)*m,R21+(R21_2-R21)*m,R22+(R22_2-R22)*m)
  186. end
  187. ```
  188.  
  189. local cf = CFrame.new()
  190. local cf2 = CFrame.new(10,10,10)
  191. local s = tick()
  192. for i = 1,10000 do
  193.     local x = cf:lerp(cf2,0.5)
  194. end
  195. print(tick()-s)
  196.  
  197. -- Sine lerp --
  198. --[[function slerp(a,b,c) -- lol
  199.     return a+(b-a)*(1-((math.sin((math.pi*((math.abs(b-a)*c)/math.abs(b-a)))+(math.pi/2))+1)/2))
  200. end]]
  201.  
  202. function slerp(a,b,c)
  203.     return a+(b-a)*((math.sin(math.pi*(c-.5))+1)/2)
  204. end
  205.  
  206. function hslerp(a,b,c)
  207.     return -(a+(b-a)*(1-(math.sin((math.pi/2)*((math.abs(b-a)*c)/math.abs(b-a)))+1)))
  208. end
  209.  
  210. -- exponential lerp (?)
  211. function xlerp(a,b,c)
  212.     return a+(b-a)*(c*c)
  213. end
  214.  
  215. --[[ |Lerps end| ]]--
  216.  
  217. -- Get All BrickColors --
  218. function GetAllBrickColors()
  219.     local T={}
  220.     for r=1,255,10 do for g=1,255,10 do for b=1,255,10 do
  221.         local C=BrickColor.new(r/255,g/255,b/255)
  222.         if not T[C.Name] then
  223.             T[C.Name]=C.Name
  224.         end
  225.     end end end
  226.     return T
  227. end
  228.  
  229. -- sleep --
  230. function sleep(T) -- Doesn't work in certain circumstances (doesnt appear to work at all anymore)
  231.     local n = tick()
  232.     repeat coroutine.yield() until tick()-n>(T or 0)
  233.     return tick()-n
  234. end
  235.  
  236. -- Within Area --
  237. function WithinBounds(x,y,X,Y,Size)
  238.     local a,b,c,d = x<=X+Size,x>=X-Size,y<=Y+Size,y>=Y-Size
  239.     if a and b and c and d then
  240.         return true
  241.     else
  242.         return false
  243.     end
  244. end
  245.  
  246. -- Key Down system --
  247.  
  248. local Mouse = game.Players.LocalPlayer:GetMouse()
  249. local Key = {Down={},AllDown={},Byte={},Mouse = {}}
  250. Mouse.KeyDown:connect(function(k)
  251.     Key.Down[k]=true
  252.     Key.AllDown[string.lower(k)]=true
  253.     Key.Byte[string.byte(k)]=true
  254.     Key.AllDown[string.upper(k)]=true end)
  255. Mouse.KeyUp:connect(function(k)
  256.     Key.Down[k]=nil
  257.     Key.AllDown[string.lower(k)]=nil
  258.     Key.Byte[string.byte(k)]=nil
  259.     Key.AllDown[string.upper(k)]=nil end)
  260. Mouse.Button1Down:connect(function() Key.Mouse[1]=true end)
  261. Mouse.Button1Up:connect(function() Key.Mouse[1]=nil end)
  262. Mouse.Button2Down:connect(function() Key.Mouse[2]=true end)
  263. Mouse.Button2Up:connect(function() Key.Mouse[2]=nil end)
  264.  
  265. -- Get Corners of Gui & GetDistance & GetAngle --
  266.  
  267. function GetDistance(P1,P2)
  268.     return math.sqrt((P1.x-P2.x)^2 + (P1.y-P2.y)^2)
  269. end
  270.  
  271. function GetLength(x,y)
  272.     return ((x^2)+(y^2))^0.5
  273. end
  274.  
  275. function GetDistance(P1,P2) -- Untested
  276.     local a,b = pcall(function()return P1.X.Offset end),pcall(function()return P2.X.Offset end)
  277.     return math.sqrt((a and(P1.X.Offset-P2.X.Offset)^2 or(P1.X-P2.X)^2)+(b and(P1.Y.Offset-P2.Y.Offset)^2 or(P1.Y-P2.Y)^2))
  278. end
  279.  
  280. ```lua
  281. function GetCorners(Gui,R) -- R is EXTRA rotation
  282.     local GetDistance = function()return math.sqrt((P1.x-P2.x)^2+(P1.y-P2.y)^2)end
  283.     local Center = Gui.AbsolutePosition+Vector2.new(Gui.AbsoluteSize.X/2,Gui.AbsoluteSize.Y/2)
  284.     local Rot = Gui.Rotation+(R or 0)
  285.     local TLD = GetDistance(Gui.AbsolutePosition,Center)
  286.     local TopLeft = Center+Vector2.new(math.cos(math.rad(Rot-135)),math.sin(math.rad(Rot-135)))*TLD
  287.     local TopRight = Center+Vector2.new(math.cos(math.rad(Rot-45)),math.sin(math.rad(Rot-45)))*TLD
  288.     local BottomLeft = Center+Vector2.new(math.cos(math.rad(Rot+135)),math.sin(math.rad(Rot+135)))*TLD
  289.     local BottomRight = Center+Vector2.new(math.cos(math.rad(Rot+45)),math.sin(math.rad(Rot+45)))*TLD
  290.     return UDim2.new(0,TopLeft.x,0,TopLeft.y),UDim2.new(0,TopRight.x,0,TopRight.y),UDim2.new(0,BottomLeft.x,0,BottomLeft.y),UDim2.new(0,BottomRight.x,0,BottomRight.y)
  291. end
  292. ```
  293.  
  294. function GetUnitDirection(Rot)
  295.     return math.cos(math.rad(Rot)),math.sin(math.rad(Rot))
  296. end
  297.  
  298. function GetDistanceTest(P,P2,PO) -- Uses Point and GetUnitDirection, less efficient than GetDistance without need of angles
  299.     local RotO = -Vector2.new(GetUnitDirection(PO or Point(P,P2)))
  300.     local Off = P2-P
  301.     local x = Off/RotO
  302.     return x.X
  303. end
  304.  
  305. local function isWithin(a,b,x,y)
  306.     local min,max,ceil,floor = math.min,math.max,math.ceil,math.floor
  307.     local ra = {x=floor(min(a.x,b.x)),y=floor(min(a.y,b.y))}
  308.     local rb = {x=ceil(max(a.x,b.x)),y=ceil(max(a.y,b.y))}
  309.     if x>=ra.x and x<=rb.x and y>=ra.y and y<=rb.y then
  310.         return true
  311.     end
  312. end
  313.  
  314. local function GetIntersection(a,b,c,d)
  315.     local slope1 = (b.y-a.y)/(b.x-a.x)
  316.     local ycept1 = a.y-(slope1*a.x)
  317.  
  318.     local slope2 = (d.y-c.y)/(d.x-c.x)
  319.     local ycept2 = c.y-(slope2*c.x)
  320.  
  321.     local slope3 = (slope2-slope1)
  322.     local ycept3 = (ycept2-ycept1)
  323.  
  324.     local x = -(ycept3/slope3)
  325.     local y = (slope1*x)+ycept1
  326.  
  327.     if isWithin(a,b,x,y) and isWithin(c,d,x,y) then
  328.         return V2(x,y)
  329.     end
  330. end
  331.  
  332. function WithinBounds(P1,P2,TDI) -- TDI = Total radius, obj1.radius+obj2.radius
  333.     local a = pcall(function()return P1.X.Offset end)
  334.     local b = pcall(function()return P2.X.Offset end)
  335.     return (((a and(P1.X.Offset-P2.X.Offset) or(P1.X-P2.X))^2)+((b and(P1.Y.Offset-P2.Y.Offset) or(P1.Y-P2.Y))^2))<(TDI/2)^2
  336. end
  337.  
  338. function Point(V1,V2)
  339.     local X,Y=V1.X-V2.X,V1.Y-V2.Y
  340.     local AS=math.atan2(Y,X)
  341.     return 360*(AS/(math.pi*2))
  342. end
  343.  
  344. function GetAngle(V1,V2)
  345.     local Adjacent,Opposite = V2.X-V1.X,V2.Y-V1.Y
  346.     local Hypotenuse = ((Adjacent^2)+(Opposite^2))^0.5
  347.     local Sine,Cosine = Opposite/Hypotenuse,Adjacent/Hypotenuse
  348.     local OppositeAngle = math.asin(Sine)
  349.     local AdjacentAngle = math.acos(Cosine)
  350.     local RealAngle = (OppositeAngle<0 and math.pi+(math.pi-AdjacentAngle) or AdjacentAngle)
  351.     return 360*(RealAngle/(math.pi*2))
  352. end
  353.  
  354. function Point(UD1,UD2)
  355.     local a,b=pcall(function()return UD1.X.Offset end),pcall(function()return UD2.X.Offset end)
  356.     local X,Y=(a and UD1.X.Offset or UD1.X)-(b and UD2.X.Offset or UD2.X),(a and UD1.Y.Offset or UD1.Y)-(b and UD2.Y.Offset or UD2.Y)
  357.     local AS=math.atan2(Y,X)
  358.     return 360*(AS/(math.pi*2))
  359. end
  360.  
  361. local function fibonacci_sphere(samples,randomize)
  362.     local samples = samples or 1
  363.     local rnd = 1
  364.     if randomize then
  365.         rnd = math.random() * samples
  366.     end
  367.    
  368.     local points = {}
  369.     local offset = 2/samples
  370.     local increment = math.pi * (3 - math.sqrt(5));
  371.     local cos,sin,insert = math.cos,math.sin,table.insert
  372.    
  373.     for i = 1,samples do--range(samples):
  374.         local y = ((i * offset) - 1) + (offset / 2);
  375.         local r = (1 - y^2)^0.5
  376.        
  377.         local phi = ((i + rnd) % samples) * increment
  378.        
  379.         local x = cos(phi) * r
  380.         local z = sin(phi) * r
  381.        
  382.         insert(points,{x,y,z})
  383.     end
  384.    
  385.     return points
  386. end
  387.  
  388. -- New Server --
  389. function NewServer() -- Only works in SBs supporting NewLocalScript
  390.     if not NewLocalScript then return end
  391.     Instance.new("Hint",Workspace).Text = "Creating a new server..."
  392.     wait(1)
  393.     print("Start...")
  394.     while wait() do
  395.         for i,v in pairs(game.Players:GetPlayers()) do
  396.             print("Teleported "..tostring(v))
  397.             if NewLocalScript then
  398.                 local Par = v:FindFirstChild("Backpack") or v.Character or v:FindFirstChild("PlayerGui")
  399.                 NewLocalScript(Par,[[
  400.                     a,b = ypcall(function()
  401.                         game.Players.LocalPlayer:Kick()
  402.                         wait(5)
  403.                         game:GetService("TeleportService"):Teleport(game.PlaceId)
  404.                     end)
  405.                     if not a then
  406.                         print(b)
  407.                     end
  408.                 ]])
  409.             end
  410.         end
  411.     end
  412. end
  413.  
  414.  
  415. -- Time and Date
  416. ```lua
  417. local date = {}
  418. function date:GetTime(e,full)
  419.     return
  420.     (not full and math.floor((e or tick())/31556900) or tick()/31556900)+1970, -- years
  421.     not full and math.floor(((e or tick())%31556900)/86400) or ((e or tick())%31556900)/86400, -- days
  422.     not full and math.floor((((e or tick())%86400)/3600)) or (((e or tick())%86400)/3600), -- hours
  423.     not full and math.floor((((e or tick())%86400)%3600)/60) or (((e or tick())%86400)%3600)/60, -- minutes
  424.     not full and math.floor((((e or tick())%86400)%3600)%60) or (((e or tick())%86400)%3600)%60 -- seconds
  425. end
  426. function date:TimeToSeconds(seconds,minutes,hours,days,years)
  427.     local years,days,hours,minutes,seconds = years or 0, days or 0, hours or 0, minutes or 0, seconds or 0
  428.     return (years*31556900)+(days*86400)+(hours*3600)+(minutes*60)+seconds
  429. end
  430. print(date:GetTime(tick()))
  431. ```
  432.  
  433. ```lua
  434. local Time = {} -- improved
  435. function Time:GetDate(e)
  436.     local e,floor = e or tick(),math.floor
  437.  
  438.     local years = floor(e/31556900)+1970
  439.     local days = floor((e%31556900)/86400)
  440.     local hours = floor((e%86400)/3600)
  441.     local minutes = floor((e%3600)/60)
  442.     local seconds = floor(e%60)
  443.     local milliseconds = floor((e%1)/0.001)
  444.    
  445.     return years,days,hours,minutes,seconds,milliseconds
  446. end
  447. function Time:TimeToSeconds(seconds,minutes,hours,days,years)
  448.     local years,days,hours,minutes,seconds = years or 0, days or 0, hours or 0, minutes or 0, seconds or 0
  449.     return (years*31556900)+(days*86400)+(hours*3600)+(minutes*60)+seconds
  450. end
  451. print(Time:GetDate(os.time()))
  452. ```
  453.  
  454.  
  455. while wait() do
  456.     Instance.new("Humanoid",Workspace):Destroy(wait())
  457. end
  458.  
  459.  
  460. local GetRecursiveChildren=function(P)local t,n,G=table.foreach,{}G=function(c,p)table.insert(n,p)t(p:GetChildren(),G)end t(P:GetChildren(),G)return n end
  461. for i,v in pairs(GetRecursiveChildren(Workspace)) do
  462.     if v.ClassName=="PointLight" then
  463.         v.Shadows = true
  464.         v.Range=20
  465.         v.ShadowCutoff = 1
  466.     end
  467. end
  468.  
  469. local function(self)
  470. end
  471.  
  472.  
  473.  
  474. local c0 = {
  475. RightArm = CF(1.5,0.5,0),
  476. LeftArm = CF(-1.5,0.5,0),
  477. RightLeg = CF(0.5,-1,0),
  478. LeftLeg = CF(-0.5,-1,0),
  479. RootJoint = CF(0,0,0),
  480. Neck = CF(0,1,0)
  481. }
  482. local c1 = {
  483. RightArm = CF(0,0.5,0),
  484. LeftArm = CF(0,0.5,0),
  485. RightLeg = CF(0,1,0),
  486. LeftLeg = CF(0,1,0),
  487. RootJoint = CF(0,0,0),
  488. Neck = CF(0,-0.5,0)
  489. }
  490.  
  491.  
  492.  
  493.  
  494. -- fancy lighting --
  495. local p = Instance.new("Part",Workspace.CurrentCamera)
  496. p.Anchored = true
  497. p.Material = "Neon"
  498. p.FormFactor = "Custom"
  499. p.Size = Vector3.new(100,100,0)
  500. p.Transparency = 0.9
  501. p.CanCollide = false
  502. Workspace.CurrentCamera.FieldOfView = 50
  503. local Sun = Instance.new("SunRaysEffect",Workspace.CurrentCamera)
  504. Sun.Intensity = 0.15
  505. Sun.Spread = 0.8
  506. local Color = Instance.new("ColorCorrectionEffect",Workspace.CurrentCamera)
  507. Color.TintColor=Color3.new(255/255,247/255,215/255)
  508. local Blur = Instance.new("BlurEffect",Workspace.CurrentCamera)
  509. Blur.Size = 0.6
  510. game:GetService("RunService").RenderStepped:connect(function()
  511.     p.CFrame = Workspace.CurrentCamera.CoordinateFrame*CFrame.new(0,0,-5)
  512. end)
  513.  
  514. function GetParents(obj)
  515.     local txt = obj.Name
  516.     local tbl = {}
  517.     local lastobj = obj
  518.     repeat
  519.         asd = lastobj.Parent
  520.         txt = asd.Name.."."..txt
  521.         lastobj = asd
  522.         table.insert(tbl,lastobj)
  523.     until lastobj == game
  524.     return txt,tbl
  525. end
  526.  
  527. ```lua
  528. function Point(UD1,UD2)
  529.     local X,Y=UD1.X-UD2.X,UD1.Y-UD2.Y
  530.     local AS=math.atan2(Y,X)
  531.     return 360*(AS/(math.pi*2))
  532. end
  533. function GetUnitDirection(Rot)
  534.     return math.cos(math.rad(Rot)),math.sin(math.rad(Rot))
  535. end
  536. local x = Point(Vector2.new(0,0),Vector2.new(-5,-5))
  537. local a,b = GetUnitDirection(x)
  538. print((a*9000000),(b*9000000))
  539. ```
  540. function pair(x,y)
  541.     return (x^2+3*x+2*x*y+y+y^2)/2
  542. end
  543.  
  544. function GetDistance(P1,P2)
  545.     return math.sqrt((P1.x-P2.x)^2 + (P1.y-P2.y)^2)
  546. end
  547. print(GetDistance(Vector2.new(0,0),Vector2.new(4500000,4500000)))
  548.  
  549.  
  550. function GetIntersection(a,b,c,d)
  551.     -- get abc of a,b
  552.     local a1 = b.y-a.y
  553.     local b1 = a.x-b.x
  554.     local c1 = a1*a.x + b1*a.y
  555.  
  556.     -- get abc of c,d
  557.     local a2 = d.y-c.y
  558.     local b2 = c.x-d.x
  559.     local c2 = a2*c.x + b2*c.y
  560.  
  561.     local determinant = a1*b2 - a2*b1
  562.  
  563.     if determinant ~= 0 then
  564.         local x = (b2*c1 - b1*c2)/determinant
  565.         local y = (a1*c2 - a2*c1)/determinant
  566.         if isWithin(a,b,x,y) and isWithin(c,d,x,y) then
  567.             return {x=x,y=y}
  568.         end
  569.     end
  570. end
  571.  
  572. intersect_sphere = function(Ray_Pos,Ray_Dir,Sphere_Pos,Sphere_Size)
  573.     local Offset = Ray_Pos-Sphere_Pos -- L
  574.     local distance_To_Plane = -Offset:Dot(Ray_Dir)
  575.    
  576.     if distance_To_Plane<0 then return end
  577.    
  578.     local ray_Plane_Position = Ray_Pos+(Ray_Dir*distance_To_Plane)
  579.     local sphere_Plane_Distance = (ray_Plane_Position-Sphere_Pos).magnitude
  580.    
  581.     if sphere_Plane_Distance>Sphere_Size then return end
  582.    
  583.     local distance_To_Plane_Position = ((Sphere_Size^2)-(sphere_Plane_Distance^2))^.5
  584.     local distance_To_Intersect = distance_To_Plane-distance_To_Plane_Position
  585.    
  586.     return distance_To_Intersect,distance_To_Plane,distance_To_Plane_Position,sphere_Plane_Distance
  587. end
  588.  
  589. function matrix_multiply(a,b)
  590.     local result,arows,acols,brows,bcols = {},#a,#a[1],#b,#b[1]
  591.     for i = 1,arows do
  592.         local row,resultRow = a[i],{}
  593.         for i2 = 1,bcols do
  594.             local r = 0
  595.             for i3 = 1,acols do
  596.                 r = r + (row[i3]*b[i3][i2])
  597.             end
  598.             resultRow[i2]=r
  599.         end
  600.         result[i]=resultRow
  601.     end
  602.     return result
  603. end
  604.  
  605.  
  606. -- for farmtown
  607. function getValue(sproutTime,plantCount,travelTime)
  608.     local sproutTime=sproutTime+(travelTime or 0)
  609.     local moneyPerHarvest = 3.2*plantCount
  610.     local moneyPerSecond = moneyPerHarvest/sproutTime
  611.     local moneyPerMinute = moneyPerSecond*60
  612.     local moneyPerHour = (moneyPerMinute*60)-3000
  613.     print(moneyPerHour,(moneyPerMinute*60))
  614.     return moneyPerHour*4,moneyPerMinute,moneyPerSecond,moneyPerHarvest
  615. end
  616.  
  617. print(getValue(115,104))
  618.  
  619. function plotValue(wc,spc,fc,suc)
  620.     return ((wc*6)+(spc*7)+(fc*9)+(suc*10))/32
  621. end
  622. print(plotValue(1486,856,804,670))
  623.  
  624. local t = {
  625.     {35923,39207,22176,20808,17293}
  626.     {8302,7697,6820,6216,29035};
  627.     {8921,8144,7051,6320,30438};
  628.     {5137,4767,4220,3835,17959};
  629.     {4827,4483,3974,3614,16899};
  630.     {4022,3745,3328,3031,14127};
  631. }
  632. for i,v in pairs(t) do
  633.     for a,b in pairs(v) do
  634.         v[a]=b/6
  635.     end
  636.     print(unpack(v))
  637. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement