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
- --> .child(String childName)
- returns true if a child named childName is located inside of object.
- does not return an instance like :FindFirstChild()
- --> .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:
- --> .changed(Function f[ARGS: String property])
- executes f when a property of object is changed
- --> .clicked(Function f[ARGS: NONE])
- executes f when object is clicked
- --> .childAdded(Function f[ARGS: Instance child])
- executes f when a child is added to object. 'child' is the new child
- --> .childRemoved(Function f[ARGS: Instance child])
- executes f when a child under object is removed. 'child' is the instance that was removed
- --> .mouseEnter(Function f[ARGS: NONE])
- executes f when the player hovers their mouse over a GUI
- --> .mouseLeave(Function f[ARGS: NONE])
- executes f when the players takes their mouse off of a GUI
- --> .playerAdded(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
- --> .renderStep(Function f[ARGS: NONE])
- executes sixty times per second, only works in a local script
- ]]
- 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
- return #replicated == 2 and (replicated[1] + replicated[2]) / 2 or replicated[1]
- 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
- table.sort(object)
- end
- return object
- 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)
- object:Destroy()
- return studio
- end,
- child = function(name)
- return object:FindFirstChild(name)
- end,
- --begin object functions
- clicked = function(func)
- if object:IsA("TextButton") or object:IsA("ImageButton") then
- object.MouseButton1Click:connect(func)
- elseif object:IsA("ClickDetector") then
- object.MouseClick:connect(func)
- end
- return studio
- end,
- mouseEnter = function(func)
- object.MouseEnter:connect(func)
- return studio
- end,
- mouseLeave = function(func)
- object.MouseLeave:connect(func)
- return studio
- end,
- childAdded = function(func)
- object.ChildAdded:connect(func)
- return studio
- end,
- childRemoved = function(func)
- object.ChildRemoved:connect(func)
- return studio
- end,
- changed = function(func)
- object.Changed:connect(func)
- return studio
- end,
- playerAdded = 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,
- renderStep = function(func)
- game:GetService("RunService").RenderStepped:connect(func)
- return studio
- end
- }
- return studio
- end
Advertisement
Add Comment
Please, Sign In to add comment