Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- Studio+ by ForeverDev. Project started September 23rd, 2014.
- What is Studio+ ?
- Studio+ is a module script designed to allow more scripting in fewer lines. It
- has a very simplistic syntax. One feature of Studio+ is the use of table manipulation.
- Studio+ allows you to manipulate tables in many different ways. Consider the following code
- local array = {1, 3, 5, 7, 9, 11}
- sp(array).drop(1, 5, 7)
- print(table.concat(array, ", ")) --> 3, 9, 11
- Studio+ also allows you to easily edit objects. For example, the following code changes a
- frame's border, background, and text color to red.
- sp(frame).change("BackgroundColor3", "TextColor3", "BorderColor3", Color3.new(1, 0, 0))
- Isn't that a lot easier to read and better looking than the following?
- frame.BackgroundColor3 = Color3.new(1, 0, 0)
- frame.TextColor3 = Color3.new(1, 0, 0)
- frame.BorderColor3 = Color3.new(1, 0, 0)
- How do I use Studio+ ?
- It's very easy to enable Studio+ in your script. First, make sure this module script
- is located inside of ServerScriptService. To allow any script to use Studio+, place
- the following line of code at the top of any script:
- local sp = require(game.ServerScriptService.StudioPlus)
- If you want to edit the properties of an object, you first have to 'point' to it. To
- do this, you would use the following code in your script:
- sp(PATH_TO_OBJECT)
- For example, if you wanted to 'point' to the BasePlate, you would do the following:
- sp(Workspace.BasePlate)
- Then, you can edit the BasePlate. You can use as many SP (Studio+) functions as you
- want in a row, as long as you don't interrupt it with other Lua code.
- sp(Workspace.BasePlate)
- .val("hi")
- .change("Transparency", 1)
- Here is an example of how NOT to use SP.
- sp(Workspace.BasePlate)
- .val("hi")
- print("hello!") <-- this print line will cause an error
- .change("Transparency", 1)
- As stated earlier, SP can perform many different functions on tables. To
- manipulate a table with SP, you 'point' to a table the same way you point to an
- object. For example:
- local array = {1, 3, 5, 7}
- local median = sp(array).median()
- local sum = sp(array).add()
- print(median) --> 4
- print(sum) --> 16
- Finally, SP can handle events. The following code would execute when a player joins the game:
- sp(game.Players).newPlayer(function(player) print(player.Name) end)
- All SP functions are listed below.
- -------------------------------------------------------------------------------------------------------------------------
- Current SP functions :
- TABLE FUNCTIONS:
- --> .add()
- returns the sum of all numbers inside of the table
- --> .average()
- returns the average of all numbers inside of the table
- --> .drop(...)
- removes all given values from the table
- --> .median()
- retuns the median of all numbers inside of the table
- --> .multiply()
- returns the product of all numbers inside of the table
- --> .order()
- sorts all numbers inside of the table by value
- --> .shuffle()
- moves table[1] to table[#table], and moves each other index up one
- ex) sp({1, 2, 3, 4, 5}).shuffle() == {2, 3, 4, 5, 1}
- OBJECT FUNCTIONS:
- --> .change(String property1, ..., value)
- changes all the given properties to the last argument
- --> .destroy(Function f[ARGS: NONE])
- destroys the object, executes f if provided (basically an object.onDestroy event)
- --> .move(Vector3/CFrame location)
- moves the object (also works with models) to the given Vector3 location.
- --> .val(String value)
- creates a string value inside of object with a value of value
- --> .val()
- returns the value inside of an object, or nil
- OBJECT EVENTS:
- --> .clicked(Function f[ARGS: NONE])
- executes f when object is clicked
- --> .newChild(Function f[ARGS: Instance child])
- executes f when a child is added to object. 'child' is the new child
- --> .newPlayer(Function f[ARGS: Instance player])
- executes f when a player is added. only works if object is game.Players. 'player' is the new player
- --> .playerLeaving(Function f[ARGS: Instance player])
- executes f when a player leaves. only works if object is game.Players. 'player' is the player that left
- ]]
- return function(object)
- local studio;
- studio = {
- --begin table functions
- add = function()
- if type(object) == "table" then
- local sum = 0
- for _, number in ipairs(object) do
- sum = sum + number
- end
- return sum
- end
- end,
- multiply = function()
- if type(object) == "table" then
- local product = 1
- for _, number in ipairs(object) do
- product = product * number
- end
- return product
- end
- end,
- average = function()
- if type(object) == "table" then
- local average = 0
- for _, number in ipairs(object) do
- average = average + number
- end
- return average / #object
- end
- end,
- shuffle = function()
- if type(object) == "table" then
- local shift = {}
- for index, value in ipairs(object) do
- if index == 1 then
- shift[#object] = value
- else
- shift[index - 1] = value
- end
- end
- object = shift
- return object
- end
- end,
- median = function()
- if type(object) == "table" then
- local replicated = object
- table.sort(replicated)
- repeat
- table.remove(replicated, 1)
- table.remove(replicated, #replicated)
- until #replicated <= 2
- if #replicated == 2 then
- return (replicated[1] + replicated[2]) / 2
- else
- return replicated[1]
- end
- end
- end,
- drop = function(...)
- if type(object) == "table" then
- for index, value in ipairs(object) do
- for _, search in ipairs({...}) do
- if search == value then
- table.remove(object, index)
- end
- end
- end
- return object
- end
- end,
- order = function()
- if type(object) == "table" then
- local sorted = {unpack(object)}
- table.sort(sorted)
- return sorted
- end
- end,
- --begin object functions
- val = function(value)
- if not value then
- return object:FindFirstChild("Storage") and object.Storage.Value or nil
- elseif not object:FindFirstChild("Storage") then
- Instance.new("StringValue", object).Name = "Storage"
- end
- object.Storage.Value = tostring(value)
- return studio
- end,
- change = function(...)
- local args = {...}
- for index, property in ipairs(args) do
- if index == #args then
- break
- end
- object[property] = args[#args]
- end
- return studio
- end,
- move = function(position)
- if object:IsA("BasePart") then
- object.Position = position
- elseif object:IsA("Model") then
- object:MoveTo(position)
- end
- return studio
- end,
- destroy = function(event)
- event()
- object:Destroy()
- return studio
- end,
- --begin object functions
- clicked = function(func)
- if object:IsA("TextButton") or object:IsA("ImageButton") then
- object.MouseButton1Click:connect(func)
- end
- return studio
- end,
- newChild = function(func)
- object.ChildAdded:connect(func)
- return studio
- end,
- newPlayer = function(func)
- if object:IsA("Players") then
- object.PlayerAdded:connect(func)
- end
- return studio
- end,
- playerLeaving = function(func)
- if object:IsA("Players") then
- object.PlayerRemoving:connect(func)
- end
- return studio
- end
- }
- return studio
- end
Advertisement
Add Comment
Please, Sign In to add comment