Advertisement
_Jigoku_

Waypoints Library

Jan 19th, 2020
201
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 7.83 KB | None | 0 0
  1. local instances = {}
  2. instances.markers = {}
  3. local tweenService = game:GetService("TweenService")
  4. local module = {}
  5.  
  6. module.initiate = function()
  7.     local ui = Instance.new("ScreenGui")
  8.     ui.ResetOnSpawn = false
  9.     ui.ZIndexBehavior = Enum.ZIndexBehavior.Global
  10.     ui.Name = "WaypointsUI"
  11.     ui.Parent = game.Players.LocalPlayer.PlayerGui
  12.    
  13.     local Frame = Instance.new("Frame")
  14.    
  15.     Frame.Name = "Holder"
  16.     Frame.Parent = ui
  17.     Frame.AnchorPoint = Vector2.new(0.5, 0.5)
  18.     Frame.BackgroundColor3 = Color3.fromRGB(255, 255, 255)
  19.     Frame.BackgroundTransparency = 1.000
  20.     Frame.Position = UDim2.new(0.5, 0, 0.5, 0)
  21.     Frame.Size = UDim2.new(1, -25, 1, -25)
  22.    
  23.     instances.mother = ui
  24.     instances.holder = Frame
  25.     instances.absSize = Frame.AbsoluteSize
  26.    
  27.     local Sample = Instance.new("ImageLabel")
  28.     local UIAspectRatioConstraint = Instance.new("UIAspectRatioConstraint")
  29.     local Icon = Instance.new("ImageLabel")
  30.     local RotateLabel = Instance.new("Frame")
  31.     local Arrow = Instance.new("ImageLabel")
  32.     local Label = Instance.new("TextLabel")
  33.    
  34.     Label.Name = "Label"
  35.     Label.Text = "x"
  36.     Label.Size = UDim2.new(1,0,1,0)
  37.     Label.BackgroundTransparency = 1
  38.     Label.TextColor3 = Color3.fromRGB(0,0,0)
  39.     Label.TextTransparency = 0.6
  40.     Label.Font = Enum.Font.SourceSansSemibold
  41.     Label.TextScaled = true
  42.     Label.Parent = Sample
  43.    
  44.     Sample.Name = "Sample"
  45.     Sample.BackgroundColor3 = Color3.fromRGB(255, 255, 255)
  46.     Sample.BackgroundTransparency = 1.000
  47.     Sample.Position = UDim2.new(0.5, 0, 0.5, 0)
  48.     Sample.Size = UDim2.new(0.04, 0, 0.04, 0)
  49.     Sample.Image = "rbxassetid://2681945588"
  50.    
  51.     UIAspectRatioConstraint.Parent = Sample
  52.    
  53.     Icon.Name = "Icon"
  54.     Icon.Parent = Sample
  55.     Icon.AnchorPoint = Vector2.new(0.5, 0.5)
  56.     Icon.BackgroundColor3 = Color3.fromRGB(255, 255, 255)
  57.     Icon.BackgroundTransparency = 1.000
  58.     Icon.Position = UDim2.new(0.5, 0, 0.5, 0)
  59.     Icon.Size = UDim2.new(1, -6, 1, -6)
  60.     Icon.ZIndex = 2
  61.     Icon.Image = "rbxassetid://924320031"
  62.     Icon.Visible = false
  63.    
  64.     RotateLabel.Name = "RotateLabel"
  65.     RotateLabel.Parent = Sample
  66.     RotateLabel.BackgroundColor3 = Color3.fromRGB(255, 255, 255)
  67.     RotateLabel.BackgroundTransparency = 1.000
  68.     RotateLabel.Size = UDim2.new(1, 0, 1, 0)
  69.    
  70.     Arrow.Name = "Arrow"
  71.     Arrow.Parent = RotateLabel
  72.     Arrow.AnchorPoint = Vector2.new(0.5, 1)
  73.     Arrow.BackgroundColor3 = Color3.fromRGB(255, 255, 255)
  74.     Arrow.BackgroundTransparency = 1.000
  75.     Arrow.Position = UDim2.new(0.5, 0, 0, 0)
  76.     Arrow.Size = UDim2.new(0.5, 0, 0.400000006, 0)
  77.     Arrow.Image = "rbxassetid://2800468809"
  78.    
  79.     instances.template = Sample
  80. end
  81.  
  82.  
  83. local function start(marker,text)
  84.     local part = Instance.new("Part")
  85.     part.Anchored = true
  86.     part.Size = Vector3.new(1,1,1)
  87.     part.Transparency = 1
  88.     part.CanCollide = false
  89.     part.CFrame = game.Players.LocalPlayer.Character.HumanoidRootPart.CFrame
  90.     part.Parent = workspace
  91.    
  92.     local BillboardGui = Instance.new("BillboardGui")
  93.     local Frame = Instance.new("Frame")
  94.     local Label = Instance.new("TextLabel")
  95.    
  96.     BillboardGui.Parent = part
  97.     BillboardGui.ZIndexBehavior = Enum.ZIndexBehavior.Sibling
  98.     BillboardGui.Active = true
  99.     BillboardGui.AlwaysOnTop = true
  100.     BillboardGui.LightInfluence = 1.000
  101.     BillboardGui.MaxDistance = 50.000
  102.     BillboardGui.ExtentsOffsetWorldSpace = Vector3.new(0,1.5,0)
  103.     BillboardGui.Size = UDim2.new(8, 0, 1.25, 0)
  104.    
  105.     Frame.Parent = BillboardGui
  106.     Frame.BackgroundColor3 = Color3.fromRGB(255, 255, 255)
  107.     Frame.BackgroundTransparency = 1.000
  108.     Frame.BorderSizePixel = 0
  109.     Frame.Size = UDim2.new(1, 0, 1, 0)
  110.    
  111.     Label.Name = "Label"
  112.     Label.Parent = Frame
  113.     Label.BackgroundColor3 = Color3.fromRGB(255, 255, 255)
  114.     Label.BackgroundTransparency = 1.000
  115.     Label.BorderSizePixel = 0
  116.     Label.Position = UDim2.new(0, 0, 0.100000001, 0)
  117.     Label.Size = UDim2.new(1, 0, 1, 0)
  118.     Label.Font = Enum.Font.SourceSansSemibold
  119.     Label.Text = text
  120.     Label.TextColor3 = Color3.fromRGB(255, 255, 255)
  121.     Label.TextScaled = true
  122.     Label.TextSize = 14.000
  123.     Label.TextStrokeTransparency = 0.500
  124.     Label.TextWrapped = true
  125.    
  126.    
  127.     local bottom,top = Instance.new("Part"), Instance.new("Part")
  128.     local att0,att1 = Instance.new("Attachment"), Instance.new("Attachment")
  129.    
  130.     att0.Parent = bottom
  131.     att1.Parent = top
  132.    
  133.     bottom.Size = Vector3.new(2,2,2)
  134.     top.Size = Vector3.new(2,2,2)
  135.    
  136.     bottom.CFrame = game.Players.LocalPlayer.Character.HumanoidRootPart.CFrame - Vector3.new(0,5000,0)
  137.     top.CFrame = game.Players.LocalPlayer.Character.HumanoidRootPart.CFrame + Vector3.new(0,5000,0)
  138.    
  139.     top.Anchored = true
  140.     top.Transparency = 1
  141.     top.CanCollide = false
  142.     top.Name = "top"
  143.    
  144.     bottom.Anchored = true
  145.     bottom.Transparency = 1
  146.     bottom.CanCollide = false
  147.     bottom.Orientation = Vector3.new(90, 180, 0)
  148.     bottom.Name = "bottom"
  149.    
  150.     local beam = Instance.new("Beam")
  151.     beam.Parent = top
  152.     beam.Attachment0 = att0
  153.     beam.Attachment1 = att1
  154.     beam.FaceCamera = true
  155.     beam.Texture = "rbxassetid://4611423139"
  156.     beam.Color = ColorSequence.new(marker.ImageColor3)
  157.    
  158.     bottom.Parent = workspace
  159.     top.Parent = workspace
  160.    
  161.    
  162.     table.insert(instances.markers,{marker,part,true,marker.ImageColor3})
  163. end
  164.  
  165. module.create = function(text,color)
  166.     local new = instances.template:Clone()
  167.     new.Parent = instances.mother
  168.    
  169.     new.ImageColor3 = color
  170.     new.RotateLabel.Arrow.ImageColor3 = color
  171.    
  172.     if ((text) and typeof(text) == "string") and string.len(text) > 0 then
  173.         new.Label.Text = string.sub(text,1,1)
  174.     end
  175.    
  176.     new.Parent = instances.holder
  177.    
  178.     start(new,text)
  179. end
  180.  
  181. coroutine.wrap(function()
  182.     if not _G.WRan then
  183.         _G.WRan = true
  184.         repeat wait() until instances.mother ~= nil
  185.        
  186.         function ClampMarkerToBorder(X,Y,Absolute)
  187.             local Screen = instances.absSize
  188.             X = Screen.X - X
  189.             Y = Screen.Y - Y
  190.            
  191.             local DistanceToXBorder = math.min(X,Screen.X-X)
  192.             local DistanceToYBorder = math.min(Y,Screen.Y-Y)
  193.            
  194.             if DistanceToYBorder < DistanceToXBorder then
  195.                 if Y < (Screen.Y-Y) then
  196.                     return math.clamp(X,0,Screen.X-Absolute.X),0
  197.                 else
  198.                     return math.clamp(X,0,Screen.X-Absolute.X),Screen.Y - Absolute.Y
  199.                 end
  200.             else
  201.                 if X < (Screen.X-X) then
  202.                     return 0,math.clamp(Y,0,Screen.Y-Absolute.Y)
  203.                 else
  204.                     return Screen.X - Absolute.X,math.clamp(Y,0,Screen.Y-Absolute.Y)
  205.                 end
  206.             end
  207.         end
  208.        
  209.        
  210.         game:GetService("RunService").Heartbeat:Connect(function()
  211.             for i,Stat in pairs(instances.markers) do
  212.                 local Marker = Stat[1]
  213.                 local Location = Stat[2]
  214.                 Marker.Visible = Stat[3]
  215.                
  216.                 if Stat[3] then
  217.                     local MarkerPosition , MarkerVisible = game.Workspace.CurrentCamera:WorldToScreenPoint(Location.Position)
  218.                     local MarkerRotation = game.Workspace.CurrentCamera.CFrame:Inverse()*Location.CFrame
  219.                     local MarkerAbsolute = Marker.AbsoluteSize
  220.                    
  221.                     local MarkerPositionX = MarkerPosition.X - MarkerAbsolute.X/2
  222.                     local MarkerPositionY = MarkerPosition.Y - MarkerAbsolute.Y/2
  223.                    
  224.                     MarkerPositionX = MarkerPositionX-(MarkerAbsolute.X/2)
  225.                    
  226.                     if MarkerPosition.Z < 0  then
  227.                         MarkerPositionX,MarkerPositionY = ClampMarkerToBorder(MarkerPositionX,MarkerPositionY,MarkerAbsolute)
  228.                     else
  229.                         local Screen = instances.absSize
  230.                         if MarkerPositionX < 0 then
  231.                             MarkerPositionX = 0
  232.                         elseif MarkerPositionX > (Screen.X - MarkerAbsolute.X) then
  233.                             MarkerPositionX = Screen.X - MarkerAbsolute.X
  234.                         end
  235.                         if MarkerPositionY < 0 then
  236.                             MarkerPositionY = 0
  237.                         elseif MarkerPositionY > (Screen.Y - MarkerAbsolute.Y) then
  238.                             MarkerPositionY = Screen.Y - MarkerAbsolute.Y
  239.                         end
  240.                     end
  241.                        
  242.                     Marker.RotateLabel.Visible = not MarkerVisible
  243.                     Marker.RotateLabel.Rotation = 90 + math.deg(math.atan2(MarkerRotation.Z,MarkerRotation.X))
  244.                     Marker.Position = UDim2.new(0,MarkerPositionX,0,MarkerPositionY)
  245.                    
  246.                     tweenService:Create(Marker,TweenInfo.new(.5),{ImageColor3 = Stat[4]}):Play()
  247.                     tweenService:Create(Marker.RotateLabel.Arrow,TweenInfo.new(.5),{ImageColor3 = Stat[4]}):Play()
  248.                 end
  249.             end
  250.         end)
  251.     end
  252. end)()
  253.  
  254. _G.waypointsLibSource = module
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement