TigerManGamingYT

Insurgent QuickMenu API

May 13th, 2020
1,671
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 15.40 KB | None | 0 0
  1. -- Ahxyz#0144 // Project Insurgent QuickMenu API
  2.  
  3. --[[
  4.     This is just a quick API i put together to test functions with ease. The syntax is as follows:
  5.  
  6.     local module = loadstring(game:HttpGet("https://pastebin.com/raw/iU43kUrL",true))()
  7.  
  8.     > This will load in the code below as a module.
  9.  
  10.     Module:Init(string Name)
  11.  
  12.     > This will initialise the API for building.
  13.  
  14.     local mymenu = module:NewMenu{string Name=None}
  15.  
  16.     > Create a menu object
  17.  
  18.     mymenu:AddToggle(string Name,function Callback)
  19.  
  20.     > Adds a togglable switch to the menu object. the Callback function will be called when the switch toggled, and will return (bool        
  21.     ToggleStatus).
  22.  
  23.     mymenu:AddButton(string Name,function Callback)
  24.  
  25.     > Adds a clickable button to the menu object. The Callback function will be called when the button is pressed, and will not return
  26.     any values.
  27.  
  28.     mymenu:AddDivider()
  29.  
  30.     > Adds a line after the last object.
  31.  
  32.     mymenu:AddTextLabel(string Name)
  33.  
  34.     > Adds a text label with Name as Text.
  35.  
  36.     mymenu:AddTextBox(string Name,string Hint,function Callback)
  37.  
  38.     > Adds a text input box to the menu object. Hint is PlaceholderText. The callback function will be called when the       
  39.     TextBox.FocusLost event fires, and will return (string Text).
  40.  
  41.     mymenu:Build()
  42.  
  43.     > Builds the menu and runs it's neccessary scripts.
  44.  
  45.     module:Finalise()
  46.  
  47.     > Shows the GUI on the user's screen.
  48.  
  49.  
  50.     Other Functions:
  51.  
  52.     menuobject = mymenu:Find(string ObjectName)
  53.  
  54.     > This will find the first object with the provided name in the menu and return it's data table.
  55.  
  56. --]]
  57.  
  58.  
  59. local MAIN_Module = {}
  60.  
  61. local MAIN_Enum = {
  62.    
  63.     ["TogglePos"] = {
  64.         ["On"] = UDim2.new(0.5,0,0,0),
  65.         ["Off"] = UDim2.new(0,0,0,0)
  66.     }
  67.    
  68. }
  69.  
  70. -- Internal Functions
  71.  
  72. local MAIN_New = {}
  73.  
  74. function MAIN_New:Menu(Parent,Pos,Name)
  75.     local Menu = Instance.new("Frame")
  76.     local Topbar = Instance.new("Frame")
  77.     local Background = Instance.new("ImageLabel")
  78.     local Title = Instance.new("TextLabel")
  79.     local Minimise = Instance.new("TextButton")
  80.     Menu.Name = Name
  81.     Menu.Parent = Parent
  82.     Menu.BackgroundColor3 = Color3.fromRGB(30, 30, 30)
  83.     Menu.BorderSizePixel = 0
  84.     Menu.ClipsDescendants = true
  85.     Menu.Position = Pos
  86.     Menu.Size = UDim2.new(0, 150, 0, 60)
  87.     Topbar.Name = "Topbar"
  88.     Topbar.Parent = Menu
  89.     Topbar.BackgroundColor3 = Color3.fromRGB(55, 55, 55)
  90.     Topbar.BorderSizePixel = 0
  91.     Topbar.ClipsDescendants = true
  92.     Topbar.Position = UDim2.new(0, 0, -0.00333333015, 0)
  93.     Topbar.Size = UDim2.new(0, 150, 0, 25)
  94.     Background.Name = "Background"
  95.     Background.Parent = Topbar
  96.     Background.BackgroundColor3 = Color3.fromRGB(255, 255, 255)
  97.     Background.BackgroundTransparency = 1.000
  98.     Background.BorderSizePixel = 0
  99.     Background.Position = UDim2.new(0, 0, -0.959999979, 0)
  100.     Background.Size = UDim2.new(0, 150, 0, 84)
  101.     Title.Name = "Title"
  102.     Title.Parent = Topbar
  103.     Title.BackgroundColor3 = Color3.fromRGB(255, 255, 255)
  104.     Title.BackgroundTransparency = 1.000
  105.     Title.BorderSizePixel = 0
  106.     Title.Position = UDim2.new(0.266666681, 0, 0, 0)
  107.     Title.Size = UDim2.new(0, 69, 0, 24)
  108.     Title.Font = Enum.Font.SourceSansBold
  109.     Title.Text = Name
  110.     Title.TextColor3 = Color3.fromRGB(230, 230, 230)
  111.     Title.TextSize = 14.000
  112.     Minimise.Name = "Minimise"
  113.     Minimise.Parent = Topbar
  114.     Minimise.BackgroundColor3 = Color3.fromRGB(255, 255, 255)
  115.     Minimise.BackgroundTransparency = 1.000
  116.     Minimise.BorderSizePixel = 0
  117.     Minimise.Position = UDim2.new(0.866666675, 0, 0.00800048839, 0)
  118.     Minimise.Size = UDim2.new(0, 20, 0, 23)
  119.     Minimise.Font = Enum.Font.SourceSans
  120.     Minimise.Text = "-"
  121.     Minimise.TextColor3 = Color3.fromRGB(255, 255, 255)
  122.     Minimise.TextSize = 14.000
  123.     Minimise.AutoButtonColor = false
  124.     return {
  125.         ["Name"] = Name,
  126.         ['Self'] = Menu,
  127.         ['Topbar'] = Topbar,
  128.         ['Background'] = Background,
  129.         ['Title'] = Title,
  130.         ['Minimise'] = Minimise
  131.     }
  132. end
  133.  
  134. function MAIN_New:Toggle(Parent,Pos,Text)
  135.     local Switch = Instance.new("Frame")
  136.     local Toggle = Instance.new("TextButton")
  137.     local SwitchLabel = Instance.new("TextLabel")
  138.     Switch.Name = Text
  139.     Switch.Parent = Parent
  140.     Switch.BackgroundColor3 = Color3.fromRGB(70, 70, 70)
  141.     Switch.BorderColor3 = Color3.fromRGB(100, 100, 100)
  142.     Switch.Position = Pos
  143.     Switch.Size = UDim2.new(0, 30, 0, 10)
  144.     Toggle.Name = "Toggle"
  145.     Toggle.Parent = Switch
  146.     Toggle.BackgroundColor3 = Color3.fromRGB(240, 240, 240)
  147.     Toggle.BorderSizePixel = 0
  148.     Toggle.Position = UDim2.new(0.5, 0, -3.81469732e-07, 0)
  149.     Toggle.Size = UDim2.new(0, 15, 0, 10)
  150.     Toggle.Font = Enum.Font.SourceSans
  151.     Toggle.Text = ""
  152.     Toggle.TextColor3 = Color3.fromRGB(0, 0, 0)
  153.     Toggle.TextSize = 14.000
  154.     Toggle.AutoButtonColor = false
  155.     SwitchLabel.Name = "SwitchLabel"
  156.     SwitchLabel.Parent = Switch
  157.     SwitchLabel.BackgroundColor3 = Color3.fromRGB(255, 255, 255)
  158.     SwitchLabel.BackgroundTransparency = 1.000
  159.     SwitchLabel.BorderSizePixel = 0
  160.     SwitchLabel.Position = UDim2.new(-3.26666665, 0, 0, 0)
  161.     SwitchLabel.Size = UDim2.new(0, 98, 0, 10)
  162.     SwitchLabel.Font = Enum.Font.SourceSans
  163.     SwitchLabel.Text = Text
  164.     SwitchLabel.TextColor3 = Color3.fromRGB(210, 210, 210)
  165.     SwitchLabel.TextSize = 14.000
  166.     SwitchLabel.TextXAlignment = Enum.TextXAlignment.Left
  167.     return {
  168.         ["Name"] = Text,
  169.         ["Label"] = SwitchLabel,
  170.         ["Self"] = Switch,
  171.         ["Button"] = Toggle
  172.     }
  173. end
  174.  
  175. function MAIN_New:Button(Parent,Pos,Text)
  176.     local Button = Instance.new("Frame")
  177.     local Press = Instance.new("TextButton")
  178.     local ButtonLabel = Instance.new("TextLabel")
  179.     Button.Name = Text
  180.     Button.Parent = Parent
  181.     Button.BackgroundColor3 = Color3.fromRGB(70, 70, 70)
  182.     Button.BorderColor3 = Color3.fromRGB(100, 100, 100)
  183.     Button.Position = Pos
  184.     Button.Size = UDim2.new(0, 30, 0, 10)
  185.     Press.Name = "Press"
  186.     Press.Parent = Button
  187.     Press.BackgroundColor3 = Color3.fromRGB(240, 240, 240)
  188.     Press.BorderSizePixel = 0
  189.     Press.Size = UDim2.new(0, 30, 0, 10)
  190.     Press.Font = Enum.Font.SourceSans
  191.     Press.Text = ""
  192.     Press.TextColor3 = Color3.fromRGB(0, 0, 0)
  193.     Press.TextSize = 14.000
  194.     Press.AutoButtonColor = false
  195.     ButtonLabel.Name = "ButtonLabel"
  196.     ButtonLabel.Parent = Button
  197.     ButtonLabel.BackgroundColor3 = Color3.fromRGB(255, 255, 255)
  198.     ButtonLabel.BackgroundTransparency = 1.000
  199.     ButtonLabel.BorderSizePixel = 0
  200.     ButtonLabel.Position = UDim2.new(-3.26666665, 0, 0, 0)
  201.     ButtonLabel.Size = UDim2.new(0, 98, 0, 10)
  202.     ButtonLabel.Font = Enum.Font.SourceSans
  203.     ButtonLabel.Text = Text
  204.     ButtonLabel.TextColor3 = Color3.fromRGB(210, 210, 210)
  205.     ButtonLabel.TextSize = 14.000
  206.     ButtonLabel.TextXAlignment = Enum.TextXAlignment.Left
  207.     return {
  208.         ["Name"] = Text,
  209.         ["Label"] = ButtonLabel,
  210.         ["Self"] = Button,
  211.         ["Button"] = Press
  212.         }
  213. end
  214.  
  215. function MAIN_New:Divider(Parent,Pos)
  216.     local Divider = Instance.new("Frame")
  217.     Divider.Name = "Divider"
  218.     Divider.Parent = Parent
  219.     Divider.BackgroundColor3 = Color3.fromRGB(230, 230, 230)
  220.     Divider.BorderSizePixel = 0
  221.     Divider.Position = Pos
  222.     Divider.Size = UDim2.new(0, 128, 0, 1)
  223.     return {
  224.         ["Name"] = "Divider",
  225.         ["Self"] = Divider
  226.     }
  227. end
  228.  
  229. function MAIN_New:TextLabel(Parent,Pos,Text)
  230.     local TextLabel = Instance.new("TextLabel")
  231.     TextLabel.Name = Text:sub(1,7).."..."
  232.     TextLabel.Parent = Parent
  233.     TextLabel.BackgroundColor3 = Color3.fromRGB(255, 255, 255)
  234.     TextLabel.BackgroundTransparency = 1.000
  235.     TextLabel.BorderSizePixel = 0
  236.     TextLabel.Position = Pos
  237.     TextLabel.Size = UDim2.new(0, 128, 0, 15)
  238.     TextLabel.Font = Enum.Font.SourceSans
  239.     TextLabel.Text = Text
  240.     TextLabel.TextColor3 = Color3.fromRGB(245, 245, 245)
  241.     TextLabel.TextSize = 14.000
  242.     return {
  243.         ["Name"] = Text,
  244.         ["Self"] = TextLabel
  245.     }
  246. end
  247.  
  248. function MAIN_New:TextBox(Parent,Pos,Text,Hint)
  249.     local TextBox = Instance.new("TextBox")
  250.     TextBox.Parent = Parent
  251.     TextBox.BackgroundColor3 = Color3.fromRGB(255, 255, 255)
  252.     TextBox.BackgroundTransparency = 1.000
  253.     TextBox.BorderSizePixel = 0
  254.     TextBox.Position = Pos
  255.     TextBox.Size = UDim2.new(0, 128, 0, 15)
  256.     TextBox.Font = Enum.Font.SourceSans
  257.     TextBox.PlaceholderColor3 = Color3.fromRGB(140, 140, 140)
  258.     TextBox.PlaceholderText = Hint
  259.     TextBox.Text = Text
  260.     TextBox.TextColor3 = Color3.fromRGB(220, 220, 220)
  261.     TextBox.TextSize = 14.000
  262.     return {
  263.         ["Name"] = Text,
  264.         ["Self"] = TextBox
  265.     }
  266. end
  267.  
  268. -- Variables
  269.  
  270. local Base
  271. local Menus = 0
  272.  
  273. -- Module Functions
  274.  
  275. function MAIN_Module:Init(Name)
  276.     Base = Instance.new("ScreenGui")
  277.     Base.Name = Name
  278.     Base.Enabled = false
  279. end
  280.  
  281. function MAIN_Module:NewMenu(Argument)
  282.    
  283.     -- Internal Variables
  284.     local MenuLength = 60
  285.     local ObjectCount = 0
  286.     local DividerCount = 0
  287.     local This = { ["Name"] = Argument.Name, ["UI"] = nil, ["Objects"] = {} }
  288.    
  289.     -- Create the menu assets
  290.    
  291.     This.UI = MAIN_New:Menu(Base,UDim2.new(0.02+(Menus/12),0,0.02,0),This.Name)
  292.     Menus = Menus + 1
  293.    
  294.     -- Draggability
  295.    
  296.     local DragProperties = {
  297.         ["Dragging"] = false,
  298.         ["Input"] = nil,
  299.         ["DragStart"] = nil,
  300.         ["StartPos"] = nil,
  301.         ["Delta"] = nil
  302.        
  303.     }
  304.     local function update(input)
  305.         DragProperties.Delta = input.Position - DragProperties.DragStart
  306.         This.UI.Self.Position = UDim2.new(DragProperties.StartPos.X.Scale, DragProperties.StartPos.X.Offset + DragProperties.Delta.X, DragProperties.StartPos.Y.Scale, DragProperties.StartPos.Y.Offset + DragProperties.Delta.Y)
  307.     end
  308.     This.UI.Topbar.InputBegan:Connect(function(input)
  309.         if input.UserInputType == Enum.UserInputType.MouseButton1 then
  310.             DragProperties.Dragging = true
  311.             DragProperties.DragStart = input.Position
  312.             DragProperties.StartPos = This.UI.Self.Position
  313.            
  314.             input.Changed:Connect(function()
  315.                 if input.UserInputState == Enum.UserInputState.End then
  316.                     DragProperties.Dragging = false
  317.                 end
  318.             end)
  319.         end
  320.     end)
  321.     This.UI.Topbar.InputChanged:Connect(function(input)
  322.         if input.UserInputType == Enum.UserInputType.MouseMovement or input.UserInputType == Enum.UserInputType.Touch then
  323.             DragProperties.Input = input
  324.         end
  325.     end)
  326.     game:GetService("UserInputService").InputChanged:Connect(function(input)
  327.         if input == DragProperties.Input and DragProperties.Dragging then
  328.             update(input)
  329.         end
  330.     end)
  331.    
  332.     --  Menu General Functions
  333.    
  334.     function This:Find(Name)
  335.         for i,v in pairs(This.Objects) do
  336.             if v.Name == Name then
  337.                 return v
  338.             end
  339.         end
  340.         return nil
  341.     end
  342.    
  343.     -- Menu Build Functions
  344.    
  345.     function This:AddToggle(Name,Callback)
  346.         MenuLength = MenuLength + 18
  347.        
  348.         local Toggle = {
  349.             ["Name"] = Name,
  350.             ["UI"] = nil,
  351.             ["Toggled"] = false
  352.         }
  353.         Toggle["Opfn"] = function()
  354.             Toggle.UI = MAIN_New:Toggle(This.UI.Self,UDim2.new(0.725,0,0,0.4+(18 * (ObjectCount+1))),Name)
  355.             Toggle.UI.Button.Position = MAIN_Enum.TogglePos.Off
  356.            
  357.             coroutine.resume(coroutine.create(function()
  358.                 local Last = false
  359.                 while wait() do
  360.                     if Toggle.Toggled ~= Last then
  361.                         if Toggle.Toggled == true then
  362.                             Toggle.UI.Button:TweenPosition(MAIN_Enum.TogglePos.On,Enum.EasingDirection.In,Enum.EasingStyle.Sine,0.2)
  363.                         elseif Toggle.Toggled == false then
  364.                             Toggle.UI.Button:TweenPosition(MAIN_Enum.TogglePos.Off,Enum.EasingDirection.Out,Enum.EasingStyle.Sine,0.2)
  365.                         end
  366.                         Last = Toggle.Toggled
  367.                     end
  368.                 end
  369.             end))
  370.            
  371.             Toggle.UI.Button.MouseButton1Click:Connect(function()
  372.                 Toggle.Toggled = not Toggle.Toggled
  373.                 local Ran,Error = pcall(function() Callback(Toggle.Toggled) end)
  374.                 if not Ran then
  375.                     warn('QuickMenu: Ignoring callback failure: '..Error)
  376.                 end
  377.                
  378.                 local Clr = 240
  379.                 for _ = 1,5 do
  380.                     Clr = Clr - 20
  381.                     Toggle.UI.Button.BackgroundColor3 = Color3.fromRGB(Clr,Clr,Clr)
  382.                     wait()
  383.                 end
  384.                 for _ = 1,10 do
  385.                     Clr = Clr + 10
  386.                     Toggle.UI.Button.BackgroundColor3 = Color3.fromRGB(Clr,Clr,Clr)
  387.                     wait()
  388.                 end
  389.             end)
  390.         end
  391.         table.insert(This.Objects,Toggle)
  392.     end
  393.    
  394.     function This:AddButton(Name,Callback)
  395.         MenuLength = MenuLength + 18
  396.        
  397.         local Button = {
  398.             ["Name"] = Name,
  399.             ["UI"] = nil
  400.         }
  401.         Button["Opfn"] = function()
  402.             Button.UI = MAIN_New:Button(This.UI.Self,UDim2.new(0.725,0,0,0.4+(18 * (ObjectCount+1))),Name)
  403.            
  404.             Button.UI.Button.MouseButton1Click:Connect(function()
  405.                 local Ran,Error = pcall(function() Callback() end)
  406.                 if not Ran then
  407.                     warn('QuickMenu: Ignoring callback failure: '..Error)
  408.                 end
  409.                
  410.                 local Clr = 240
  411.                 for _ = 1,5 do
  412.                     Clr = Clr - 20
  413.                     Button.UI.Button.BackgroundColor3 = Color3.fromRGB(Clr,Clr,Clr)
  414.                     wait()
  415.                 end
  416.                 for _ = 1,10 do
  417.                     Clr = Clr + 10
  418.                     Button.UI.Button.BackgroundColor3 = Color3.fromRGB(Clr,Clr,Clr)
  419.                     wait()
  420.                 end
  421.             end)
  422.         end
  423.         table.insert(This.Objects,Button)
  424.     end
  425.        
  426.     function This:AddDivider()
  427.         MenuLength = MenuLength + 18
  428.         DividerCount = DividerCount + 1
  429.        
  430.         local Divider = {
  431.             ["Name"] = "Divider"..tostring(DividerCount),
  432.             ["UI"] = nil
  433.         }
  434.         Divider["Opfn"] = function()
  435.             Divider.UI = MAIN_New:Divider(This.UI.Self,UDim2.new(0.065,0,0,6.4+(18 * (ObjectCount+1))))
  436.         end
  437.         table.insert(This.Objects,Divider)
  438.     end
  439.    
  440.     function This:AddTextLabel(Name)
  441.         MenuLength = MenuLength + 18
  442.        
  443.         local TextLabel = {
  444.             ["Name"] = Name,
  445.             ["Text"] = Name,
  446.             ["UI"] = nil
  447.         }
  448.         TextLabel["Opfn"] = function()
  449.             TextLabel.UI = MAIN_New:TextLabel(This.UI.Self,UDim2.new(0.065,0,0,-4+(18*(ObjectCount+1))),Name)
  450.            
  451.             coroutine.resume(coroutine.create(function()
  452.                 local Last = ""
  453.                 while wait() do
  454.                     if Last ~= TextLabel.Text then
  455.                         TextLabel.UI.Self.Text = TextLabel.Text
  456.                         Last = TextLabel.Text
  457.                     end
  458.                 end
  459.             end))
  460.         end
  461.         table.insert(This.Objects,TextLabel)
  462.     end
  463.    
  464.     function This:AddTextBox(Name,Hint,Callback)
  465.         MenuLength = MenuLength + 18
  466.        
  467.         local TextBox = {
  468.             ["Name"] = Name,
  469.             ["Text"] = "",
  470.             ["Hint"] = Hint,
  471.             ["UI"] = nil
  472.         }
  473.         TextBox["Opfn"] = function()
  474.             TextBox.UI = MAIN_New:TextBox(This.UI.Self,UDim2.new(0.065,0,0,-4+(18*(ObjectCount+1))),Name,Hint)
  475.            
  476.             coroutine.resume(coroutine.create(function()
  477.                 local LastText = TextBox.Text
  478.                 local LastHint = TextBox.Hint
  479.                 while wait() do
  480.                     if LastText ~= TextBox.Text then
  481.                         TextBox.UI.Self.Text = TextBox.Text
  482.                         LastText = TextBox.Text
  483.                     end
  484.                     if LastHint ~= TextBox.Hint then
  485.                         TextBox.UI.Self.PlaceholderText = TextBox.Hint
  486.                         LastHint = TextBox.Hint
  487.                     end
  488.                 end
  489.             end))
  490.            
  491.             TextBox.UI.Self.FocusLost:Connect(function()
  492.                 local Ran,Error = pcall(function() Callback(TextBox.UI.Self.Text) end)
  493.                 if not Ran then
  494.                     warn('QuickMenu: Ignoring callback failure: '..Error)
  495.                 end
  496.                
  497.                
  498.             end)
  499.         end
  500.         table.insert(This.Objects,TextBox)
  501.     end
  502.    
  503.     function This:Build()
  504.         This.UI.Self.Size = UDim2.new(0,This.UI.Self.Size.X.Offset,0,MenuLength)
  505.         for i,v in pairs(This.Objects) do
  506.             ObjectCount = ObjectCount + 1
  507.             v.Opfn()
  508.         end
  509.        
  510.         local MenuOpen = true
  511.         local MenuCycling = false
  512.         This.UI.Minimise.MouseButton1Click:Connect(function()
  513.             if MenuCycling == false then
  514.                 if MenuOpen then
  515.                     MenuCycling = true
  516.                     This.UI.Self:TweenSize(UDim2.new(0,150,0,25),Enum.EasingDirection.Out,Enum.EasingStyle.Sine,1)
  517.                     This.UI.Minimise.Text = "+"
  518.                     wait(1)
  519.                     MenuOpen = false
  520.                     MenuCycling = false
  521.                 else
  522.                     local MenuCycling = true
  523.                     This.UI.Self:TweenSize(UDim2.new(0,150,0,MenuLength),Enum.EasingDirection.Out,Enum.EasingStyle.Sine,1)
  524.                     This.UI.Minimise.Text = "-"
  525.                     wait(1)
  526.                     MenuOpen = true
  527.                     MenuCycling = false
  528.                 end
  529.             end
  530.         end)
  531.     end
  532.    
  533.     return This
  534. end
  535.  
  536. function MAIN_Module:Finalise()
  537.     Base.Parent = game.CoreGui
  538.     Base.Enabled = true
  539.     game:GetService("UserInputService").InputBegan:Connect(function()
  540.         if game:GetService("UserInputService"):IsKeyDown(Enum.KeyCode.RightControl) then
  541.             Base.Enabled = not Base.Enabled
  542.         end
  543.     end)
  544. end
  545.  
  546. return MAIN_Module
Add Comment
Please, Sign In to add comment