ForeverDev

Untitled

Sep 24th, 2014
262
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 7.52 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.         --> .destroy(Function f[ARGS: NONE])
  99.                 destroys the object, executes f if provided (basically an object.onDestroy event)
  100.         --> .move(Vector3/CFrame location)
  101.                 moves the object (also works with models) to the given Vector3 location.
  102.         --> .val(String value)
  103.                 creates a string value inside of object with a value of value
  104.         --> .val()
  105.                 returns the value inside of an object, or nil
  106.                
  107.     OBJECT EVENTS:
  108.         --> .clicked(Function f[ARGS: NONE])
  109.                 executes f when object is clicked
  110.         --> .newChild(Function f[ARGS: Instance child])
  111.                 executes f when a child is added to object.  'child' is the new child
  112.         --> .newPlayer(Function f[ARGS: Instance player])
  113.                 executes f when a player is added.  only works if object is game.Players.  'player' is the new player
  114.         --> .playerLeaving(Function f[ARGS: Instance player])
  115.                 executes f when a player leaves.  only works if object is game.Players.  'player' is the player that left
  116. ]]
  117.  
  118. return function(object)
  119.     local studio;
  120.     studio = {
  121.         --begin table functions
  122.         add = function()
  123.             if type(object) == "table" then
  124.                 local sum = 0
  125.                 for _, number in ipairs(object) do
  126.                     sum = sum + number
  127.                 end
  128.                 return sum
  129.             end
  130.         end,
  131.         multiply = function()
  132.             if type(object) == "table" then
  133.                 local product = 1
  134.                 for _, number in ipairs(object) do
  135.                     product = product * number
  136.                 end
  137.                 return product
  138.             end
  139.         end,
  140.         average = function()
  141.             if type(object) == "table" then
  142.                 local average = 0
  143.                 for _, number in ipairs(object) do
  144.                     average = average + number
  145.                 end
  146.                 return average / #object
  147.             end
  148.         end,
  149.         shuffle = function()
  150.             if type(object) == "table" then
  151.                 local shift = {}
  152.                 for index, value in ipairs(object) do
  153.                     if index == 1 then
  154.                         shift[#object] = value
  155.                     else
  156.                         shift[index - 1] = value
  157.                     end
  158.                 end
  159.                 object = shift
  160.                 return object
  161.             end
  162.         end,
  163.         median = function()
  164.             if type(object) == "table" then
  165.                 local replicated = object
  166.                 table.sort(replicated)
  167.                 repeat
  168.                     table.remove(replicated, 1)
  169.                     table.remove(replicated, #replicated)
  170.                 until #replicated <= 2
  171.                 if #replicated == 2 then
  172.                     return (replicated[1] + replicated[2]) / 2
  173.                 else
  174.                     return replicated[1]
  175.                 end
  176.             end
  177.         end,
  178.         drop = function(...)
  179.             if type(object) == "table" then
  180.                 for index, value in ipairs(object) do
  181.                     for _, search in ipairs({...}) do
  182.                         if search == value then
  183.                             table.remove(object, index)
  184.                         end
  185.                     end
  186.                 end
  187.                 return object
  188.             end
  189.         end,
  190.         order = function()
  191.             if type(object) == "table" then
  192.                 local sorted = {unpack(object)}
  193.                 table.sort(sorted)
  194.                 return sorted
  195.             end
  196.         end,
  197.        
  198.         --begin object functions
  199.         val = function(value)
  200.             if not value then
  201.                 return object:FindFirstChild("Storage") and object.Storage.Value or nil
  202.             elseif not object:FindFirstChild("Storage") then
  203.                 Instance.new("StringValue", object).Name = "Storage"
  204.             end
  205.             object.Storage.Value = tostring(value)
  206.             return studio
  207.         end,
  208.         change = function(...)
  209.             local args = {...}
  210.             for index, property in ipairs(args) do
  211.                 if index == #args then
  212.                     break
  213.                 end
  214.                 object[property] = args[#args]
  215.             end
  216.             return studio
  217.         end,
  218.         move = function(position)
  219.             if object:IsA("BasePart") then
  220.                 object.Position = position
  221.             elseif object:IsA("Model") then
  222.                 object:MoveTo(position)
  223.             end
  224.             return studio
  225.         end,
  226.         destroy = function(event)
  227.             event()
  228.             object:Destroy()
  229.             return studio
  230.         end,
  231.        
  232.         --begin object functions
  233.         clicked = function(func)
  234.             if object:IsA("TextButton") or object:IsA("ImageButton") then
  235.                 object.MouseButton1Click:connect(func)
  236.             end
  237.             return studio
  238.         end,
  239.         newChild = function(func)
  240.             object.ChildAdded:connect(func)
  241.             return studio
  242.         end,
  243.         newPlayer = function(func)
  244.             if object:IsA("Players") then
  245.                 object.PlayerAdded:connect(func)
  246.             end
  247.             return studio
  248.         end,
  249.         playerLeaving = function(func)
  250.             if object:IsA("Players") then
  251.                 object.PlayerRemoving:connect(func)
  252.             end
  253.             return studio
  254.         end
  255.     }
  256.     return studio
  257. end
Advertisement
Add Comment
Please, Sign In to add comment