ForeverDev

Untitled

Sep 26th, 2014
259
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 10.93 KB | None | 0 0
  1. --[[
  2.     Studio+ by ForeverDev.  Project started September 23rd, 2014.
  3.    
  4.     What is Studio+ ?
  5.         Studio+ is a module script designed to allow more scripting in fewer lines.  It
  6.         has a very simplistic syntax.  One feature of Studio+ is the use of table manipulation.
  7.         Studio+ allows you to manipulate tables in many different ways.  Consider the following code
  8.        
  9.             local array = {1, 3, 5, 7, 9, 11}
  10.             sp(array).drop(1, 5, 7)
  11.             print(table.concat(array, ", ")) --> 3, 9, 11
  12.            
  13.            
  14.         Studio+ also allows you to easily edit objects.  For example, the following code changes a
  15.         frame's border, background, and text color to red.
  16.        
  17.             sp(frame).change("BackgroundColor3", "TextColor3", "BorderColor3", Color3.new(1, 0, 0))
  18.            
  19.         Isn't that a lot easier to read and better looking than the following?
  20.        
  21.             frame.BackgroundColor3 = Color3.new(1, 0, 0)
  22.             frame.TextColor3 = Color3.new(1, 0, 0)
  23.             frame.BorderColor3 = Color3.new(1, 0, 0)
  24.            
  25.     How do I use Studio+ ?
  26.         It's very easy to enable Studio+ in your script.  First, make sure this module script
  27.         is located inside of ServerScriptService.  To allow any script to use Studio+, place
  28.         the following line of code at the top of any script:
  29.            
  30.             local sp = require(game.ServerScriptService.StudioPlus)
  31.            
  32.         If you want to edit the properties of an object, you first have to 'point' to it.  To
  33.         do this, you would use the following code in your script:
  34.        
  35.             sp(PATH_TO_OBJECT)
  36.            
  37.         For example, if you wanted to 'point' to the BasePlate, you would do the following:
  38.        
  39.             sp(Workspace.BasePlate)
  40.            
  41.         Then, you can edit the BasePlate.  You can use as many SP (Studio+) functions as you
  42.         want in a row, as long as you don't interrupt it with other Lua code.
  43.        
  44.             sp(Workspace.BasePlate)
  45.                 .val("hi")
  46.                 .change("Transparency", 1)
  47.                
  48.         Here is an example of how NOT to use SP.
  49.        
  50.             sp(Workspace.BasePlate)
  51.                 .val("hi")
  52.             print("hello!")                         <-- this print line will cause an error
  53.                 .change("Transparency", 1) 
  54.                
  55.                
  56.         As stated earlier, SP can perform many different functions on tables.  To
  57.         manipulate a table with SP, you 'point' to a table the same way you point to an
  58.         object.  For example:
  59.        
  60.             local array = {1, 3, 5, 7}
  61.            
  62.             local median = sp(array).median()
  63.             local sum = sp(array).add()
  64.            
  65.             print(median) --> 4
  66.             print(sum) --> 16
  67.            
  68.         Finally, SP can handle events.  The following code would execute when a player joins the game:
  69.        
  70.             sp(game.Players).newPlayer(function(player) print(player.Name) end)
  71.            
  72.         All SP functions are listed below.
  73.            
  74. -------------------------------------------------------------------------------------------------------------------------
  75.                
  76.     Current SP functions :
  77.    
  78.     TABLE FUNCTIONS:
  79.         --> .add()
  80.                 returns the sum of all numbers inside of the table
  81.         --> .average()
  82.                 returns the average of all numbers inside of the table
  83.         --> .concat(String split)
  84.                 returns the table concatenated with each element separated by split
  85.         --> .drop(...)
  86.                 removes all given values from the table
  87.         --> .getRandom()
  88.                 returns a random value from the table
  89.         --> .insert(...)
  90.                 inserts all given values into the table
  91.         --> .median()
  92.                 retuns the median of all numbers inside of the table
  93.         --> .multiply()
  94.                 returns the product of all numbers inside of the table
  95.         --> .order()
  96.                 sorts all numbers inside of the table by value
  97.         --> .shuffle()
  98.                 moves table[1] to table[#table], and moves each other index up one
  99.                 ex) sp({1, 2, 3, 4, 5}).shuffle() == {2, 3, 4, 5, 1}
  100.                
  101.     STRING FUNCTIONS:
  102.         --> .cut(...)
  103.                 removes any passed pattern found in the string
  104.         --> .find(String pattern)
  105.                 returns first index of found pattern, last index of found pattern, and any captures
  106.         --> .gmatch(String pattern, Function patternFound[ARGS: MATCH])
  107.                 returns an iteration function, calls patternFound if the pattern is found in the string.  ex:
  108.                 sp("hello").gmatch("%a", function(match)
  109.                     print(match)
  110.                 end)
  111.         --> .iterate(String pattern, String/Function replace)
  112.                 replaces any found patterns with replace
  113.         --> .match(String pattern)
  114.                 returns a substring of the found pattern
  115.         --> .sub(Integer start, Integer end)
  116.                 returns string.substring(string, start, end)
  117.                
  118.     OBJECT FUNCTIONS:
  119.         --> .change(String property1, ..., value)
  120.                 changes all the given properties to the last argument
  121.         --> .child(String childName)
  122.                 returns true if a child named childName is located inside of object.  
  123.                 does not return an instance like :FindFirstChild()
  124.         --> .destroy(Function f[ARGS: NONE])
  125.                 destroys the object, executes f if provided (basically an object.onDestroy event)
  126.         --> .move(Vector3/CFrame location)
  127.                 moves the object (also works with models) to the given Vector3 location.
  128.         --> .val(String value)
  129.                 creates a string value inside of object with a value of value
  130.         --> .val()
  131.                 returns the value inside of an object, or nil
  132.                
  133.     OBJECT EVENTS:
  134.         --> .changed(Function f[ARGS: String property])
  135.                 executes f when a property of object is changed
  136.         --> .clicked(Function f[ARGS: NONE])
  137.                 executes f when object is clicked
  138.         --> .childAdded(Function f[ARGS: Instance child])
  139.                 executes f when a child is added to object.  'child' is the new child
  140.         --> .childRemoved(Function f[ARGS: Instance child])
  141.                 executes f when a child under object is removed.  'child' is the instance that was removed
  142.         --> .mouseEnter(Function f[ARGS: NONE])
  143.                 executes f when the player hovers their mouse over a GUI
  144.         --> .mouseLeave(Function f[ARGS: NONE])
  145.                 executes f when the players takes their mouse off of a GUI
  146.         --> .playerAdded(Function f[ARGS: Instance player])
  147.                 executes f when a player is added.  only works if object is game.Players.  'player' is the new player
  148.         --> .playerLeaving(Function f[ARGS: Instance player])
  149.                 executes f when a player leaves.  only works if object is game.Players.  'player' is the player that left
  150.         --> .renderStep(Function f[ARGS: NONE])
  151.                 executes sixty times per second, only works in a local script
  152. ]]
  153.  
  154. local patterns = {
  155.     number = "%-?[%d+%.]+",
  156.     space = "%s+",
  157.     word = "%a+",
  158. }
  159.  
  160. return function(object)
  161.     local studio;
  162.     studio = {
  163.         --begin table functions
  164.         add = function()
  165.             if type(object) == "table" then
  166.                 local sum = 0
  167.                 for _, number in ipairs(object) do
  168.                     sum = sum + number
  169.                 end
  170.                 return sum
  171.             end
  172.         end,
  173.         multiply = function()
  174.             if type(object) == "table" then
  175.                 local product = 1
  176.                 for _, number in ipairs(object) do
  177.                     product = product * number
  178.                 end
  179.                 return product
  180.             end
  181.         end,
  182.         average = function()
  183.             if type(object) == "table" then
  184.                 local average = 0
  185.                 for _, number in ipairs(object) do
  186.                     average = average + number
  187.                 end
  188.                 return average / #object
  189.             end
  190.         end,
  191.         shuffle = function()
  192.             if type(object) == "table" then
  193.                 local shift = {}
  194.                 for index, value in ipairs(object) do
  195.                     if index == 1 then
  196.                         shift[#object] = value
  197.                     else
  198.                         shift[index - 1] = value
  199.                     end
  200.                 end
  201.                 object = shift
  202.                 return object
  203.             end
  204.         end,
  205.         median = function()
  206.             if type(object) == "table" then
  207.                 local replicated = object
  208.                 table.sort(replicated)
  209.                 repeat
  210.                     table.remove(replicated, 1)
  211.                     table.remove(replicated, #replicated)
  212.                 until #replicated <= 2
  213.                 return #replicated == 2 and (replicated[1] + replicated[2]) / 2 or replicated[1]
  214.             end
  215.         end,
  216.         drop = function(...)
  217.             if type(object) == "table" then
  218.                 for index, value in ipairs(object) do
  219.                     for _, search in ipairs({...}) do
  220.                         if search == value then
  221.                             table.remove(object, index)
  222.                         end
  223.                     end
  224.                 end
  225.                 return object
  226.             end
  227.         end,
  228.         insert = function(...)
  229.             if type(object) == "table" then
  230.                 for _, element in ipairs({...}) do
  231.                     table.insert(object, element)
  232.                 end
  233.             end
  234.         end,
  235.         getRandom = function()
  236.             if type(object) == "table" then
  237.                 return object[math.random(#object)]
  238.             end
  239.         end,
  240.         concat = function(between)
  241.             if type(object) == "table" then
  242.                 return table.concat(object, between)
  243.             end
  244.         end,
  245.         order = function()
  246.             if type(object) == "table" then
  247.                 table.sort(object)
  248.             end
  249.             return object
  250.         end,
  251.        
  252.         --begin string functions
  253.         sub = function(begin, ending)
  254.             return tostring(object):sub(begin, ending)
  255.         end,
  256.         find = function(pattern)
  257.             return tostring(object):find(patterns[pattern] or pattern)
  258.         end,
  259.         match = function(pattern)
  260.             return tostring(object):match(patterns[pattern] or pattern)
  261.         end,
  262.         gmatch = function(pattern, func)
  263.             for match in tostring(object):gmatch(patterns[pattern] or pattern) do
  264.                 func(match)
  265.             end
  266.         end,
  267.         iterate = function(pattern, func)
  268.             object = tostring(object):gsub(patterns[pattern] or pattern, func)
  269.             return object
  270.         end,
  271.         cut = function(...)
  272.             for _, pattern in ipairs({...}) do
  273.                 object:gsub(patterns[pattern] or pattern, "")
  274.             end
  275.         end,
  276.        
  277.         --begin object functions
  278.         val = function(value)
  279.             if not value then
  280.                 return object:FindFirstChild("Storage") and object.Storage.Value or nil
  281.             elseif not object:FindFirstChild("Storage") then
  282.                 Instance.new("StringValue", object).Name = "Storage"
  283.             end
  284.             object.Storage.Value = tostring(value)
  285.             return studio
  286.         end,
  287.         change = function(...)
  288.             local args = {...}
  289.             for index, property in ipairs(args) do
  290.                 if index == #args then
  291.                     break
  292.                 end
  293.                 object[property] = args[#args]
  294.             end
  295.             return studio
  296.         end,
  297.         move = function(position)
  298.             if object:IsA("BasePart") then
  299.                 object.Position = position
  300.             elseif object:IsA("Model") then
  301.                 object:MoveTo(position)
  302.             end
  303.             return studio
  304.         end,
  305.         destroy = function(event)
  306.             event(object)
  307.             object:Destroy()
  308.             return studio
  309.         end,
  310.         child = function(name)
  311.             return object:FindFirstChild(name)
  312.         end,
  313.        
  314.         --begin object functions
  315.         clicked = function(func)
  316.             if object:IsA("TextButton") or object:IsA("ImageButton") then
  317.                 object.MouseButton1Click:connect(func)
  318.             elseif object:IsA("ClickDetector") then
  319.                 object.MouseClick:connect(func)
  320.             end
  321.             return studio
  322.         end,
  323.         mouseEnter = function(func)
  324.             object.MouseEnter:connect(func)
  325.             return studio
  326.         end,
  327.         mouseLeave = function(func)
  328.             object.MouseLeave:connect(func)
  329.             return studio
  330.         end,
  331.         childAdded = function(func)
  332.             object.ChildAdded:connect(func)
  333.             return studio
  334.         end,
  335.         childRemoved = function(func)
  336.             object.ChildRemoved:connect(func)
  337.             return studio
  338.         end,
  339.         changed = function(func)
  340.             object.Changed:connect(func)
  341.             return studio
  342.         end,
  343.         playerAdded = function(func)
  344.             if object:IsA("Players") then
  345.                 object.PlayerAdded:connect(func)
  346.             end
  347.             return studio
  348.         end,
  349.         playerLeaving = function(func)
  350.             if object:IsA("Players") then
  351.                 object.PlayerRemoving:connect(func)
  352.             end
  353.             return studio
  354.         end,
  355.         renderStep = function(func)
  356.             game:GetService("RunService").RenderStepped:connect(func)
  357.             return studio
  358.         end
  359.     }
  360.     return studio
  361. end
Advertisement
Add Comment
Please, Sign In to add comment