Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How would I deactivate a plugin (stop it from using mouse events)?

Asked by 8 years ago

I'm working on a ModuleScript (it is always called using the command line) which creates it's own plugin in order to listen for mouse events (specifically mouse movement and clicks). When the ModuleScript is required and called, the plugin is activated with exclusive access to the mouse. The ModuleScript also creates a gui and within the gui is a close button which disconnects and removes old objects (this is ware I would like to deactivate the plugin). Essentially, the ModuleScript is acting as a development tool.

I'm not asking how to uninstall a plugin (nor can it be uninstalled, since it was never installed). I'm just wondering how to deactivate the plugin within the ModuleScript (stop it from having exclusive access to the mouse and preventing objects from being selected). Is there any method I could call to do this?

Here is my primary ModuleScript (simplified):

local Plugin = PluginManager():CreatePlugin()
local GuiManager = require(script.GuiManager)
local inStudio = game:GetService"RunService":IsStudio()

return function()
    if inStudio and GuiManager.gui == nil then
        Plugin:Activate(true)
        GuiManager:create(Plugin)
    end
end

And here is the GuiManager (simplified):

local Manager = {}

Manager.gui = nil
Manager.tracking = {}

function Manager:setupButton(button, callback)
    button.MouseButton1Click:connect(callback)
end

function Manager:create(plugin)
    self.gui = script.CloudBuilderGuiTemplate:Clone()
    self.gui.Name = "CloudBuilderGui"
    self.gui.Archivable = false
    self.gui.Parent = game:GetService"CoreGui"
    self:setupButton(
        self.gui.Container.Close,
        function()
            local Gui = self.gui
            Gui.Parent = nil
            for _, v in ipairs(self.tracking) do
                if v.disconnect ~= nil then
                    v:disconnect()
                else
                    v:Destroy()
                end
            end
            self.tracking = {}
            -- TODO: Deactivate the plugin somehow.
            self.gui = nil
            Gui:Destroy()
        end
    )
end

return Manager

1 answer

Log in to vote
0
Answered by 8 years ago

The line Plugin:Activate(true) is what enables mouse access for your plugin. Whenever some other plugin calls this method, your plugin would get disabled and it would loose its mouse access.

To deactivate it yourself, simply call the same method with false as argument: Plugin:Activate(false)

Ad

Answer this question