Advertisement
goku13l

Auto-path [plugin]

Jan 1st, 2024
966
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 15.52 KB | None | 0 0
  1. --  print("Plugin loaded") -- vX.N
  2.  
  3.   local ChangeHistoryService = game:GetService("ChangeHistoryService")
  4.   local GuiUtilities = require(script.Parent.StudioWidgets.GuiUtilities)
  5.   local module = require(script.Parent.StudioWidgets.GuiUtilities)
  6.   local LabeledCheckbox = require(script.Parent.StudioWidgets.LabeledCheckbox)
  7.  
  8.   -- note the SyncColors function is from Roblox
  9.  
  10.   local click = script.Click
  11.  
  12.  
  13. local widgetInfo  = DockWidgetPluginGuiInfo.new(Enum.InitialDockState.Float ,
  14.     false,
  15.     true,        
  16.     357, --float size x
  17.     440, -- y
  18.     357, -- min width
  19.     440) -- min height
  20.  
  21.  
  22.     local widget = plugin:CreateDockWidgetPluginGui("Menu", widgetInfo)
  23.     widget.Title = "Settings Auto-path v1"
  24.     local mainframe = Instance.new("Frame")
  25.     mainframe.Size = UDim2.new(1,0,1,0)
  26.  mainframe.Parent = widget
  27.  
  28. local function syncGuiColors(objects)
  29.     local function setColors()
  30.         for _, guiObject in ipairs(objects) do
  31.             -- Sync background color
  32.             guiObject.BackgroundColor3 = settings().Studio.Theme:GetColor(Enum.StudioStyleGuideColor.MainBackground)
  33.             -- Sync text color
  34.             if guiObject:IsA("TextLabel") or guiObject:IsA("TextButton") then
  35.             guiObject.TextColor3 = settings().Studio.Theme:GetColor(Enum.StudioStyleGuideColor.MainText)
  36.            end
  37.         end
  38.     end
  39.     -- Run 'setColors()' function to initially sync colors
  40.     setColors()
  41.     -- Connect 'ThemeChanged' event to the 'setColors()' function
  42.     settings().Studio.ThemeChanged:Connect(setColors)
  43. end
  44.  
  45.     -- color changed this
  46.  
  47.  
  48.  
  49.  
  50.     mainframe.Parent = widget
  51.    
  52.  
  53.     local toolbar = plugin:CreateToolbar("Auto-path v1") -- shorten?
  54.     local toggle = toolbar:CreateButton("Toggle Settings", "Toggle the Settings widget", "rbxassetid://4966899239")
  55.     local generatePath = toolbar:CreateButton("Path", "Create automated paths", "rbxassetid://5045855755")
  56.  
  57.  
  58.   toggle.Click:Connect(function()
  59.       widget.Enabled = not widget.Enabled
  60.   end)
  61.  
  62.  
  63. local WFCindex = LabeledCheckbox.new(
  64.     "WFC",
  65.     "WaitForChild() index",
  66.     plugin:GetSetting("WFC"),
  67.     false
  68. )
  69.  
  70.  
  71. WFCindex:SetValueChangedFunction(function(newValue)
  72.     plugin:SetSetting("WFC",newValue)
  73. end)
  74.  
  75.  
  76. local ob = WFCindex:GetFrame()
  77. ob.Position = ob.Position + UDim2.new(0,1,0,18)
  78. ob.Parent = mainframe
  79.  
  80.  
  81.   --
  82.    local FFCindex = LabeledCheckbox.new(
  83.  
  84.     "FFC",
  85.     "FindFirstChild() index",
  86.     plugin:GetSetting("FFCindex"),
  87.     false
  88.  
  89.  
  90.   )
  91.  
  92.         local obk =  FFCindex:GetFrame()
  93.         obk.Position = ob.Position + UDim2.new(0, 0, 0, 60)
  94.        
  95.  
  96.         obk.Parent = mainframe
  97.  
  98.  
  99.     FFCindex:SetValueChangedFunction(function(newValue)
  100.         plugin:SetSetting("FFC", newValue)
  101.     end)
  102.  
  103.  
  104.  
  105.  
  106.   local doubleQuote = LabeledCheckbox.new(
  107.  
  108.    "quotes",
  109.    'use double quotes " " ',
  110.     plugin:GetSetting("quotes"),
  111.     false
  112.  
  113.  
  114.   )
  115.  
  116.     doubleQuote:SetValueChangedFunction(function(newValue)
  117.         plugin:SetSetting("quotes", newValue)
  118.     end)
  119.  
  120.   local obj =  doubleQuote:GetFrame()
  121.         obj.Position = obk.Position + UDim2.new(0, 0, 0, 60)
  122.  
  123.   obj.Parent = mainframe
  124.  
  125.    local LocalScript = LabeledCheckbox.new("local", "Local Script",
  126.     plugin:GetSetting("local"),
  127.     false
  128.  
  129.  
  130.   )
  131.  
  132.     LocalScript:SetValueChangedFunction(function(newValue)
  133.         plugin:SetSetting("local", newValue)
  134.  
  135.     end)
  136.  
  137.   local oba =  LocalScript:GetFrame()
  138.         oba.Position = obj.Position + UDim2.new(0, 0, 0, 60)
  139.  
  140.   oba.Parent = mainframe
  141.  
  142.  
  143.  
  144.    local case = LabeledCheckbox.new("case", "camelCase",
  145.     plugin:GetSetting("case"),
  146.     false
  147.  
  148.  
  149.   )
  150.  
  151.     case:SetValueChangedFunction(function(newValue)
  152.         plugin:SetSetting("case", newValue)
  153.  
  154.     end)
  155.  
  156.   local obg =  case:GetFrame()
  157.         obg.Position = oba.Position + UDim2.new(0, 0, 0, 60)
  158.  
  159.   obg.Parent = mainframe
  160.  
  161.    
  162.   local button = Instance.new("TextButton")
  163.   button.Size = UDim2.new(0,300,0,40)
  164.   button.BackgroundColor3 = Color3.new(1,1,1)
  165.   button.Position = obg.Position + UDim2.new(0, 33, 0, 104)
  166.   button.TextScaled = true
  167.   button.Text  = "click to prepend..."
  168.  
  169.   button.Parent = mainframe
  170.  
  171.  
  172.   local label = Instance.new("TextLabel")
  173.   label.Text = "prepend to script"
  174.   label.BackgroundTransparency = 1
  175.   label.TextSize = 18
  176.   label.Position = button.Position - UDim2.new(0, 50, 0, 40) -- I could've just made this before the button
  177.   label.Size = UDim2.new(0,300,0,20)
  178.   label.Parent = mainframe
  179.   label.Changed:Connect(function()
  180.   label.TextColor3 = Color3.new(1,1,1)
  181.   end)
  182.  
  183.  
  184.  
  185.  
  186.  
  187.  
  188.  
  189.  
  190.  
  191.  
  192.  syncGuiColors({mainframe})
  193.  
  194. --------- this line marks the end of the UI territory, cross this border at your own risk
  195.  
  196.  
  197.  
  198.     local services = {[[ReplicatedStorage]], [[ReplicatedFirst]], [[Lighting]], [[ServerStorage]], [[ServerScriptService]],
  199.     [[SoundService]], [[StarterGui]], [[Players]],[[ReplicatedScriptService]], [[SoundService]], [[StarterPack]], [[StarterPlayer]],
  200.     [[Teams]], [[Chat]], [[LocalizationService]], [[TestService]]} -- RSS, welcome to the team buddy
  201.  
  202.     local chars = { "*", "&", "%", "$", "#", "@", "!", ";", "|", "/",":",")","(","[","]",
  203.     "?", "," ,  "<", ">","=", "+",}
  204.  
  205.                  
  206.  
  207.     local function CapitalizeFirst(str, bool)
  208.           local v = {}
  209.           for i in str:gmatch(".") do
  210.           table.insert(v, i)  -- something looks odd here
  211.           end
  212.  
  213.  if bool then
  214.  
  215.        local SirPascalTable = {}
  216.  
  217.        for i = 1, #str do
  218.  
  219.        if i % 2 == 0 then -- even
  220.  
  221.        table.insert(SirPascalTable, v[i]:upper())
  222.   else
  223.        table.insert(SirPascalTable, v[i]:lower())
  224.     end
  225.  
  226.  
  227.        str = table.concat(SirPascalTable)
  228.     end
  229.  
  230.  else
  231.  
  232.      str = v[1]:upper().. table.concat(v,"", 2)
  233.  end  
  234.  
  235.        return str
  236.     end
  237.  
  238.  
  239.      
  240.    
  241.     local function Refine(text)
  242.        local t = {};
  243.        if not text:find(" ") then return nil end
  244.  
  245.        local split = text:split(" ")
  246.  
  247.        for _, component in ipairs(split) do
  248.               table.insert(t, (CapitalizeFirst(component, case:GetValue())))    
  249.        end      
  250.    
  251.         return table.concat(t)
  252.     end
  253.    
  254.  
  255.  
  256.     local function replaceChar(str)
  257.           local temp = {}
  258.           for  x in str:gmatch(".") do  -- for gaps only? previously gmatch() . for every character
  259.  
  260.        
  261.  
  262.           if string.find(table.concat(chars), x,1,true) then table.insert(temp, "_") -- in the future just CapitalizeSecondVariable
  263.  
  264.    
  265.       else
  266.           table.insert(temp, x)
  267.        end
  268.     end
  269.           if Refine(table.concat(temp)) then return Refine(table.concat(temp)) end
  270.  
  271.           return table.concat(temp)
  272.     end
  273.  
  274.  
  275.  
  276.      local function getName(item, sep)
  277.           local v  = tostring(item:GetFullName())
  278.           local index
  279.  
  280.     if FFCindex:GetValue() then index = ":FindFirstChild("
  281.     elseif WFCindex:GetValue() then index = ":WaitForChild("  
  282.    
  283.     end
  284.  
  285.     if v:match("Workspace") then
  286.             v = "workspace"..v:sub(10)
  287.     end
  288.  
  289.     local split = v:split(".")[3]  
  290.     for _, x in ipairs(services) do
  291.         if v:match(x) then  
  292.          
  293.            split = v:split(".")[3] or v:split(".")[2]
  294.            v = "game:GetService("..sep.. x .. sep ..")".. "["..sep..replaceChar(split)..sep.."]" -- game. service. etc.  
  295.         end
  296.     end
  297.  
  298.  
  299.          local tab = v:split(".")
  300.          
  301.        
  302.          if not index then
  303.      
  304.      
  305.  
  306.          return v end
  307.  
  308.          v = tab[1]  -- first item (why am I writing this, not like anyone else is going to read this right?)
  309.  
  310.  
  311.          for i = 2, #tab do
  312.          v = v..index.. sep.. tab[i].. sep..")" -- workspace:FindFirstChild("item"):FindFirstChild(obj) or WFC
  313.  
  314.          end
  315.  
  316.       return v
  317.  
  318.      
  319.     end
  320.  
  321.  
  322.  
  323.     local function removeBracks(str)
  324.           local count = 0
  325.           for i in str:gmatch("%[") do
  326.           count = count + 1
  327.           if count>1 then return str end
  328.           end
  329.           local before = str:sub(1, str:find("%[")-1)
  330.           str = str:sub(str:find("%[")+1, str:find("%]")-1)
  331.        
  332.           return {before,str}
  333.      
  334.     end
  335.  
  336.     local s
  337.     local sep
  338.  
  339.     local tab = {}
  340.  
  341.     local created = {service = false, remote = false, assets = false, modules = false}
  342.  
  343.     local function brackCountAbove2(str)
  344.     local count = 0
  345.     for i in str:gmatch("%[") do
  346.     count = count + 1
  347.     if count>1 then return true end
  348.         return false
  349.     end
  350. end
  351.  
  352.     local function AddAfterType(key, value, TYPE)
  353.    
  354.           local temp = {}
  355.           for  x in key:gmatch(".") do    
  356.  
  357.           if string.find(table.concat(chars), x,1,true) then table.insert(temp, "_") -- in the future just CapitalizeSecondVariable
  358.        else
  359.           table.insert(temp, x)
  360.      end
  361.    end
  362.          key = table.concat(temp)
  363.  
  364.   if not s.Source:find(TYPE) then s.Source = s.Source.. "\n\n    --// "..TYPE.." \n " created[TYPE] = true end
  365.  
  366.           if s.Source:find(TYPE) then  
  367.           local num,num2 = s.Source:find(TYPE)
  368.  
  369.           local sub = string.sub(s.Source,1, num2+1) -- from beginning till Type
  370.           local rest = string.sub(s.Source, num2+1)
  371.  
  372.          
  373.          
  374.    
  375.           if  not value:match(" ") and not value:match("_") and value:match("%[") and (value:match("%"..sep)) and not brackCountAbove2(value) then
  376.           local t = removeBracks(value)
  377.           value = t[1]..".".. (t[2]:match("%w+"))
  378.           end
  379.          
  380.  
  381.  
  382.  
  383.           if TYPE == "modules" then -- this one's special
  384.           value = "require("..value..")"
  385.           end
  386.  
  387.           sub = sub.."\n    local "..key.." = "..value  -- previously  sub.."\n    local "..key.." = "..value
  388.           s.Source = sub..rest
  389.        
  390.        end
  391.                
  392.     end
  393.  
  394.  
  395.        
  396.  
  397.  
  398.     local clickedByButton
  399.  
  400.     local selection = game:GetService("Selection")
  401.    
  402.  
  403.  
  404.     local active = true
  405.  
  406.     local done
  407.  
  408.     local function OnGenClick ()
  409.  
  410.     if FFCindex:GetValue() and WFCindex:GetValue() then return error("\n Error: Cannot use :WaitForChild() and :FindFirstChild() functions at the same time") end
  411.  
  412.     if not done then
  413.     for _, v in ipairs(game:GetDescendants()) do
  414.              pcall(function()
  415.              if v.Name:match(" ") then v.Name = string.gsub(v.Name, '^%s*(.-)%s*$', '%1')
  416.            end
  417.        end)
  418.     end
  419.         -- begone yield, wait:(
  420.          done = true
  421.     end
  422.  
  423.  
  424.  
  425.      
  426.     local lscript = LocalScript:GetValue()
  427.  
  428.  
  429.        if lscript then s = Instance.new("LocalScript")
  430.   else
  431.        s = Instance.new("Script")
  432.      
  433.     end
  434.  
  435.  
  436.  
  437.         if doubleQuote:GetValue() then sep = '"'
  438.  else
  439.         sep = "'"
  440.     end
  441.  
  442.  
  443.    local function OperationForcedFineLine()
  444.  
  445.          for w in s.Source:gmatch("%w+") do
  446.          if table.find( {"modules","assets","remotes","services"}, w) then
  447.          local one, two = s.Source:find(w)
  448.          s.Source =  string.sub(s.Source,1, two+1).."\n".. string.sub(s.Source, two+1)
  449.        end
  450.     end
  451.    end
  452.  
  453.    local function define(obj,t,v)
  454.  
  455.    if obj:IsA("RemoteEvent") then  
  456.  
  457.         if not created.remote then
  458.                      s.Source = s.Source.. "\n\n    --// remotes \n " created.remote = true
  459.                       AddAfterType(t,v,"remotes")
  460.                            
  461.          else
  462.  
  463.                    AddAfterType(t,v,"remotes")
  464.  
  465.                  end            
  466.        
  467.    else
  468.               if obj:IsA("ModuleScript") then  if not created.modules then s.Source = s.Source.. "\n\n   --// modules \n " created.modules = true
  469.                   AddAfterType(t,v,"modules")
  470.               else
  471.                              AddAfterType(t,v,"modules")
  472.                end      
  473.    else
  474.  
  475.                if obj:IsA("Instance") then  if not created.assets then s.Source = s.Source.. "\n\n    --// assets \n " created.assets = true
  476.                     AddAfterType(t,v,"assets")
  477.                else        
  478.                             AddAfterType(t,v, "assets")
  479.                end
  480.  
  481.                 end  
  482.             end    
  483.        end
  484.   end
  485.  
  486.  
  487.     for _, obj in ipairs(selection:Get()) do
  488.          
  489.                
  490.                   local name = obj.Name
  491.           if table.find(services, name) then
  492.          
  493.               if not created.service then
  494.                   s.Source = s.Source.."\n\n    --// services \n"
  495.                   created.service = true
  496.                   AddAfterType(name,"game:GetService("..sep..name..sep..")" ,"services")
  497.      else  
  498.                   AddAfterType(name,"game:GetService("..sep..name..sep..")" ,"services")
  499.                      
  500.               end
  501.                
  502.              
  503.              
  504.             -- s.Source = s.Source.. "\n    local "..name.." = ".. "game:GetService("..sep..name..sep..")"
  505.  
  506.              else -- not just a service, even more ...
  507.  
  508.  
  509.      
  510.  
  511.  
  512.             local v = obj:GetFullName()
  513.             local temp = v:split(".")
  514.    
  515.          
  516.  
  517.              if temp[1] == "Workspace" then temp[1] = "workspace" end
  518.  
  519.         v = temp[1]  -- first item  
  520.    
  521.          local t = name
  522.          
  523.  
  524.          if table.find(services, temp[1] ) then  v = "game:GetService(" .. sep .. v .. sep.. ")" end
  525.  
  526.        
  527.  
  528.          for i = 2, #temp do
  529.  
  530.          v = v.."[".. sep.. temp[i].. sep.."]" -- add function that replaces chars such as brackets with no gap or _
  531.  
  532.          end
  533.                      
  534.      
  535.           t =  replaceChar(name)
  536.            
  537.  
  538.  
  539.  
  540.         -- recheck for any gaps and dots
  541.  
  542.          if string.match(v, " ") then
  543.             local a = v:split(".")
  544.             local v = a[1]
  545.             for i = 2, #a do
  546.             v = v .. "[".. sep..a[i] .. sep .. "]"  
  547.          end
  548.  
  549.  
  550.          if string.find(v, ".",1,true) or string.find(v, "[",1,true) then
  551.             local a = v:split(".")
  552.             local v = a[1]
  553.             for i = 2, #a do
  554.             v = v .. "[".. sep..a[i] .. sep .. "]"  
  555.          end
  556.  
  557.  
  558.          for _, se in ipairs(services) do -- I know this can be minimized, but who cares while doing this in a plugin right?
  559.              if v:match(se) then
  560.               v = "game:GetService("..sep..se..sep..")"
  561.             for i = 2, #a do
  562.             v = v .. "[".. sep..a[i] .. sep .. "]"  
  563.          end
  564.  end
  565.              end  
  566.          end
  567.  
  568.      
  569.        
  570.      
  571.      
  572.           define(obj, t, v)
  573.   else
  574.  
  575.                    define(obj, name, (getName(obj, sep)))
  576.                    --s.Source = s.Source.. "\n    local "..name.." = ".. getName(obj, sep)
  577.                    
  578.                  end
  579.               end
  580.  
  581.            end
  582.                  
  583.                     OperationForcedFineLine()
  584.  
  585.                     s.Source = "\n".. s.Source  
  586.                    
  587.                     if not clickedByButton then s.Parent = workspace
  588.             else
  589.                     s:Destroy()
  590.             end
  591.  
  592.       end
  593.  
  594.  
  595.    
  596.  
  597.      
  598.        generatePath.Click:Connect(OnGenClick)
  599.  
  600.  
  601.   -- after user clicks button to prepend, clear current selection and parent to next selection
  602.  
  603.             button.Activated:Connect(function()
  604.  
  605.             assert(not LocalScript:GetValue(), "\n Error: you cannot create a local script inside of a script")
  606.             clickedByButton = true
  607.                   OnGenClick()
  608.                   selection:Set({nil})
  609.              
  610.               while true do
  611.                      wait()
  612.                      if #selection:Get()~= 0 and selection:Get()[1]:IsA("LuaSourceContainer") then selection:Get()[1].Source = s.Source..selection:Get()[1].Source break end
  613.                   end
  614.                               wait(0.11) -- some cooldown for spammers
  615.                               clickedByButton = false
  616.               end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement