ForeverDev

STUDIO+

Sep 25th, 2014
337
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 8.81 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.         --> .drop(...)
  84.                 removes all given values from the table
  85.         --> .median()
  86.                 retuns the median of all numbers inside of the table
  87.         --> .multiply()
  88.                 returns the product of all numbers inside of the table
  89.         --> .order()
  90.                 sorts all numbers inside of the table by value
  91.         --> .shuffle()
  92.                 moves table[1] to table[#table], and moves each other index up one
  93.                 ex) sp({1, 2, 3, 4, 5}).shuffle() == {2, 3, 4, 5, 1}
  94.                
  95.     OBJECT FUNCTIONS:
  96.         --> .change(String property1, ..., value)
  97.                 changes all the given properties to the last argument
  98.         --> .child(String childName)
  99.                 returns true if a child named childName is located inside of object.  
  100.                 does not return an instance like :FindFirstChild()
  101.         --> .destroy(Function f[ARGS: NONE])
  102.                 destroys the object, executes f if provided (basically an object.onDestroy event)
  103.         --> .move(Vector3/CFrame location)
  104.                 moves the object (also works with models) to the given Vector3 location.
  105.         --> .val(String value)
  106.                 creates a string value inside of object with a value of value
  107.         --> .val()
  108.                 returns the value inside of an object, or nil
  109.                
  110.     OBJECT EVENTS:
  111.         --> .changed(Function f[ARGS: String property])
  112.                 executes f when a property of object is changed
  113.         --> .clicked(Function f[ARGS: NONE])
  114.                 executes f when object is clicked
  115.         --> .childAdded(Function f[ARGS: Instance child])
  116.                 executes f when a child is added to object.  'child' is the new child
  117.         --> .childRemoved(Function f[ARGS: Instance child])
  118.                 executes f when a child under object is removed.  'child' is the instance that was removed
  119.         --> .mouseEnter(Function f[ARGS: NONE])
  120.                 executes f when the player hovers their mouse over a GUI
  121.         --> .mouseLeave(Function f[ARGS: NONE])
  122.                 executes f when the players takes their mouse off of a GUI
  123.         --> .playerAdded(Function f[ARGS: Instance player])
  124.                 executes f when a player is added.  only works if object is game.Players.  'player' is the new player
  125.         --> .playerLeaving(Function f[ARGS: Instance player])
  126.                 executes f when a player leaves.  only works if object is game.Players.  'player' is the player that left
  127.         --> .renderStep(Function f[ARGS: NONE])
  128.                 executes sixty times per second, only works in a local script
  129. ]]
  130.  
  131. return function(object)
  132.     local studio;
  133.     studio = {
  134.         --begin table functions
  135.         add = function()
  136.             if type(object) == "table" then
  137.                 local sum = 0
  138.                 for _, number in ipairs(object) do
  139.                     sum = sum + number
  140.                 end
  141.                 return sum
  142.             end
  143.         end,
  144.         multiply = function()
  145.             if type(object) == "table" then
  146.                 local product = 1
  147.                 for _, number in ipairs(object) do
  148.                     product = product * number
  149.                 end
  150.                 return product
  151.             end
  152.         end,
  153.         average = function()
  154.             if type(object) == "table" then
  155.                 local average = 0
  156.                 for _, number in ipairs(object) do
  157.                     average = average + number
  158.                 end
  159.                 return average / #object
  160.             end
  161.         end,
  162.         shuffle = function()
  163.             if type(object) == "table" then
  164.                 local shift = {}
  165.                 for index, value in ipairs(object) do
  166.                     if index == 1 then
  167.                         shift[#object] = value
  168.                     else
  169.                         shift[index - 1] = value
  170.                     end
  171.                 end
  172.                 object = shift
  173.                 return object
  174.             end
  175.         end,
  176.         median = function()
  177.             if type(object) == "table" then
  178.                 local replicated = object
  179.                 table.sort(replicated)
  180.                 repeat
  181.                     table.remove(replicated, 1)
  182.                     table.remove(replicated, #replicated)
  183.                 until #replicated <= 2
  184.                 return #replicated == 2 and (replicated[1] + replicated[2]) / 2 or replicated[1]
  185.             end
  186.         end,
  187.         drop = function(...)
  188.             if type(object) == "table" then
  189.                 for index, value in ipairs(object) do
  190.                     for _, search in ipairs({...}) do
  191.                         if search == value then
  192.                             table.remove(object, index)
  193.                         end
  194.                     end
  195.                 end
  196.                 return object
  197.             end
  198.         end,
  199.         order = function()
  200.             if type(object) == "table" then
  201.                 table.sort(object)
  202.             end
  203.             return object
  204.         end,
  205.        
  206.         --begin object functions
  207.         val = function(value)
  208.             if not value then
  209.                 return object:FindFirstChild("Storage") and object.Storage.Value or nil
  210.             elseif not object:FindFirstChild("Storage") then
  211.                 Instance.new("StringValue", object).Name = "Storage"
  212.             end
  213.             object.Storage.Value = tostring(value)
  214.             return studio
  215.         end,
  216.         change = function(...)
  217.             local args = {...}
  218.             for index, property in ipairs(args) do
  219.                 if index == #args then
  220.                     break
  221.                 end
  222.                 object[property] = args[#args]
  223.             end
  224.             return studio
  225.         end,
  226.         move = function(position)
  227.             if object:IsA("BasePart") then
  228.                 object.Position = position
  229.             elseif object:IsA("Model") then
  230.                 object:MoveTo(position)
  231.             end
  232.             return studio
  233.         end,
  234.         destroy = function(event)
  235.             event(object)
  236.             object:Destroy()
  237.             return studio
  238.         end,
  239.         child = function(name)
  240.             return object:FindFirstChild(name)
  241.         end,
  242.        
  243.         --begin object functions
  244.         clicked = function(func)
  245.             if object:IsA("TextButton") or object:IsA("ImageButton") then
  246.                 object.MouseButton1Click:connect(func)
  247.             elseif object:IsA("ClickDetector") then
  248.                 object.MouseClick:connect(func)
  249.             end
  250.             return studio
  251.         end,
  252.         mouseEnter = function(func)
  253.             object.MouseEnter:connect(func)
  254.             return studio
  255.         end,
  256.         mouseLeave = function(func)
  257.             object.MouseLeave:connect(func)
  258.             return studio
  259.         end,
  260.         childAdded = function(func)
  261.             object.ChildAdded:connect(func)
  262.             return studio
  263.         end,
  264.         childRemoved = function(func)
  265.             object.ChildRemoved:connect(func)
  266.             return studio
  267.         end,
  268.         changed = function(func)
  269.             object.Changed:connect(func)
  270.             return studio
  271.         end,
  272.         playerAdded = function(func)
  273.             if object:IsA("Players") then
  274.                 object.PlayerAdded:connect(func)
  275.             end
  276.             return studio
  277.         end,
  278.         playerLeaving = function(func)
  279.             if object:IsA("Players") then
  280.                 object.PlayerRemoving:connect(func)
  281.             end
  282.             return studio
  283.         end,
  284.         renderStep = function(func)
  285.             game:GetService("RunService").RenderStepped:connect(func)
  286.             return studio
  287.         end
  288.     }
  289.     return studio
  290. end
Advertisement
Add Comment
Please, Sign In to add comment