Last active
February 13, 2018 05:19
-
-
Save Corecii/c3827e46721890d50b4ae3730ff3fc30 to your computer and use it in GitHub Desktop.
PlacePlugins Original Source Code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
local placePlugins = game:GetService('ServerStorage'):WaitForChild('PlacePlugins', math.huge) | |
local loaded = {} | |
local function loadPlugin(name, pluginBase) | |
local newPlugin = PluginManager():CreatePlugin() | |
newPlugin.Name = name | |
if typeof(pluginBase) == "Instance" then | |
pluginBase.Parent = newPlugin | |
else | |
for _, v in next, pluginBase do | |
v.Parent = newPlugin | |
end | |
end | |
local descendants = newPlugin:GetDescendants() | |
local ranAtLeastOne = false | |
for _, v in next, descendants do | |
if v:IsA('Script') and not v.Disabled then | |
local scriptFunction, syntaxError = loadstring(v.Source, v:GetFullName()) | |
if syntaxError then | |
warn(syntaxError) | |
else | |
local event = Instance.new('BindableEvent') | |
event.Event:Connect(function() | |
local env = getfenv(scriptFunction) | |
setfenv(scriptFunction, setmetatable({ | |
plugin = newPlugin, | |
script = v | |
}, {__index = env})) | |
scriptFunction() | |
end) | |
event:Fire() | |
ranAtLeastOne = true | |
end | |
end | |
end | |
return ranAtLeastOne | |
end | |
local function loadNew() | |
for _, pluginBase in next, placePlugins:GetChildren() do | |
if not loaded[pluginBase.Name] then | |
if (pluginBase:IsA('NumberValue') or pluginBase:IsA('StringValue')) and #pluginBase:GetChildren() == 0 then | |
local assetUrl = pluginBase.Value | |
if tonumber(assetUrl) then | |
assetUrl = 'rbxassetid://'..assetUrl | |
end | |
local success, errorOrChildren = pcall(game.GetObjects, game, assetUrl) | |
if not success then | |
warn(string.format('Failed to load plugin \'%s\' because: %s', pluginBase.Name, errorOrChildren)) | |
else | |
if loadPlugin(pluginBase.Name, errorOrChildren) then | |
loaded[pluginBase.Name] = true | |
end | |
end | |
else | |
if loadPlugin(pluginBase.Name, pluginBase:Clone()) then | |
loaded[pluginBase.Name] = true | |
end | |
end | |
end | |
end | |
end | |
local toolbar = plugin:CreateToolbar('Place Plugins') | |
local button = toolbar:CreateButton('Load New', 'Load any unloaded place plugins', '') | |
button.Click:Connect(function() | |
loadNew() | |
end) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment