Solved Plugin.GetPlugin()?

Jakkee

Retired Staff
Retired Staff
Plugin Developer
Jul 28, 2014
1,465
932
113
Australia
How does one get a plugin from another plugin, E.G: Js to Python.
JavaScript:
function On_Command(Player, cmd, args)
{
    if(cmd == "test")
    {
        //var donatorrank = Plugin.GetPlugin("DonatorRank");
        var donatorrank = Fougerite.GlobalPluginCollector.GetPlugin("DonatorRank");
        if(donatorrank != null)
        {
            Player.Message("Found plugin!");
            var rank = donatorrank.Invoke("CheckPerm", Player.SteamID, "Rank");
            Player.Message("Your rank is: " + rank);
        }
        else
        {
            Player.Message("Can not find plugin!");
        }
    }
}
Plugin.GetPlugin just shows "Can not find plugin Plugin.XYZ" in console and I assume GlobalPluginCollector is not used for this
 

DreTaX

Probably knows the answer...
Administrator
Jun 29, 2014
4,093
4,784
113
At your house.
github.com
How does one get a plugin from another plugin, E.G: Js to Python.
JavaScript:
function On_Command(Player, cmd, args)
{
    if(cmd == "test")
    {
        //var donatorrank = Plugin.GetPlugin("DonatorRank");
        var donatorrank = Fougerite.GlobalPluginCollector.GetPlugin("DonatorRank");
        if(donatorrank != null)
        {
            Player.Message("Found plugin!");
            var rank = donatorrank.Invoke("CheckPerm", Player.SteamID, "Rank");
            Player.Message("Your rank is: " + rank);
        }
        else
        {
            Player.Message("Can not find plugin!");
        }
    }
}
Plugin.GetPlugin just shows "Can not find plugin Plugin.XYZ" in console and I assume GlobalPluginCollector is not used for this
GlobalPluginCollector is exactly used for this. Did that work?

Sent From My Samsung Galaxy S4
 

Jakkee

Retired Staff
Retired Staff
Plugin Developer
Jul 28, 2014
1,465
932
113
Australia
Python to Lua & Python to Lua to Python always return Nil
Python:
if cmd == "f":
    lua = Fougerite.GlobalPluginCollector.GetPlugin(Fougerite.GlobalPluginCollector.GetPluginCollector(), "LuaTest")
    result = lua.Invoke("TestFunction", Player.SteamID)
    Util.Log(result)
Code:
function TestFunction(SteamID)
    donatorrank = Fougerite.GlobalPluginCollector.GetPlugin(Fougerite.GlobalPluginCollector.GetPluginCollector(), "DonatorRank")
    rank = donatorrank.Invoke("CheckPerm", SteamID, "Rank")
    return rank
end
Error:
Code:
[6/21/2016 10:55:11 PM] [Error] [MoonSharp] Error in plugin LuaTest:
[6/21/2016 10:55:11 PM] [Error] [MoonSharp] Invoke failed: MoonSharp.Interpreter.ScriptRuntimeException: attempt to index a nil value
  at MoonSharp.Interpreter.Execution.VM.Processor.ExecIndex (MoonSharp.Interpreter.Execution.VM.Instruction i, Int32 instructionPtr) [0x00000] in <filename unknown>:0
  at MoonSharp.Interpreter.Execution.VM.Processor.Processing_Loop (Int32 instructionPtr) [0x00000] in <filename unknown>:0
BUT
Doing Python to Lua and in the lua function Util.Log("Blah Blah") will work, Just seems it doesn't want to return any values (Above error).

Magma's invoke is internal use only.

Haven't tried C#

------------------------------------------------------------------------------------------------------------------------
EDIT:
trying to do C#, It will not compile
Code:
Severity    Code    Description    Project    File    Line    Suppression State
Error    CS1501    No overload for method 'GetPlugin' takes 2 arguments    CTestPlugin    C:\Users\****\Desktop\CTestPlugin\CTestPlugin\Class1.cs    51    Active

Severity    Code    Description    Project    File    Line    Suppression State
Error    CS1061    'object' does not contain a definition for 'Invoke' and no extension method 'Invoke' accepting a first argument of type 'object' could be found (are you missing a using directive or an assembly reference?)    CTestPlugin    C:\Users\****\Desktop\CTestPlugin\CTestPlugin\Class1.cs    52    Active
C#:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Fougerite;
using IronPythonModule;
using MagmaModule;

namespace CTestPlugin
{
    public class CTestPlugin : Fougerite.Module
    {
        public override string Name
        {
            get
            {
                return "CTestPlugin";
            }
        }

        public override string Author
        {
            get
            {
                return "Jakkee";
            }
        }

        public override Version Version
        {
            get
            {
                return new Version("1.0");
            }
        }

        public override void Initialize()
        {
            Hooks.OnCommand += HandleCommand;
        }

        public override void DeInitialize()
        {
            Hooks.OnCommand -= HandleCommand;
        }

        public void HandleCommand(Fougerite.Player player, string cmd, string[] args)
        {
            if (cmd == "TestC")
            {
                var donatorrank = GlobalPluginCollector.GetPlugin(GlobalPluginCollector.GetPluginCollector(), "DonatorRank");
                var rank = donatorrank.Invoke("CheckPerm", player.SteamID, "Rank");
                player.Message("Your rank is: " + rank);
            }
        }
    }
}
 
Last edited:

DreTaX

Probably knows the answer...
Administrator
Jun 29, 2014
4,093
4,784
113
At your house.
github.com
Python to Lua & Python to Lua to Python always return Nil
Python:
if cmd == "f":
    lua = Fougerite.GlobalPluginCollector.GetPlugin(Fougerite.GlobalPluginCollector.GetPluginCollector(), "LuaTest")
    result = lua.Invoke("TestFunction", Player.SteamID)
    Util.Log(result)
Code:
function TestFunction(SteamID)
    donatorrank = Fougerite.GlobalPluginCollector.GetPlugin(Fougerite.GlobalPluginCollector.GetPluginCollector(), "DonatorRank")
    rank = donatorrank.Invoke("CheckPerm", SteamID, "Rank")
    return rank
end
Error:
Code:
[6/21/2016 10:55:11 PM] [Error] [MoonSharp] Error in plugin LuaTest:
[6/21/2016 10:55:11 PM] [Error] [MoonSharp] Invoke failed: MoonSharp.Interpreter.ScriptRuntimeException: attempt to index a nil value
  at MoonSharp.Interpreter.Execution.VM.Processor.ExecIndex (MoonSharp.Interpreter.Execution.VM.Instruction i, Int32 instructionPtr) [0x00000] in <filename unknown>:0
  at MoonSharp.Interpreter.Execution.VM.Processor.Processing_Loop (Int32 instructionPtr) [0x00000] in <filename unknown>:0
BUT
Doing Python to Lua and in the lua function Util.Log("Blah Blah") will work, Just seems it doesn't want to return any values (Above error).

Magma's invoke is internal use only.

Haven't tried C#

------------------------------------------------------------------------------------------------------------------------
EDIT:
trying to do C#, It will not compile
Code:
Severity    Code    Description    Project    File    Line    Suppression State
Error    CS1501    No overload for method 'GetPlugin' takes 2 arguments    CTestPlugin    C:\Users\****\Desktop\CTestPlugin\CTestPlugin\Class1.cs    51    Active

Severity    Code    Description    Project    File    Line    Suppression State
Error    CS1061    'object' does not contain a definition for 'Invoke' and no extension method 'Invoke' accepting a first argument of type 'object' could be found (are you missing a using directive or an assembly reference?)    CTestPlugin    C:\Users\****\Desktop\CTestPlugin\CTestPlugin\Class1.cs    52    Active
C#:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Fougerite;
using IronPythonModule;
using MagmaModule;

namespace CTestPlugin
{
    public class CTestPlugin : Fougerite.Module
    {
        public override string Name
        {
            get
            {
                return "CTestPlugin";
            }
        }

        public override string Author
        {
            get
            {
                return "Jakkee";
            }
        }

        public override Version Version
        {
            get
            {
                return new Version("1.0");
            }
        }

        public override void Initialize()
        {
            Hooks.OnCommand += HandleCommand;
        }

        public override void DeInitialize()
        {
            Hooks.OnCommand -= HandleCommand;
        }

        public void HandleCommand(Fougerite.Player player, string cmd, string[] args)
        {
            if (cmd == "TestC")
            {
                var donatorrank = GlobalPluginCollector.GetPlugin(GlobalPluginCollector.GetPluginCollector(), "DonatorRank");
                var rank = donatorrank.Invoke("CheckPerm", player.SteamID, "Rank");
                player.Message("Your rank is: " + rank);
            }
        }
    }
}
Should be good now.
 
  • Like
Reactions: Jakkee

DreTaX

Probably knows the answer...
Administrator
Jun 29, 2014
4,093
4,784
113
At your house.
github.com
Python to Lua & Python to Lua to Python always return Nil
Python:
if cmd == "f":
    lua = Fougerite.GlobalPluginCollector.GetPlugin(Fougerite.GlobalPluginCollector.GetPluginCollector(), "LuaTest")
    result = lua.Invoke("TestFunction", Player.SteamID)
    Util.Log(result)
Code:
function TestFunction(SteamID)
    donatorrank = Fougerite.GlobalPluginCollector.GetPlugin(Fougerite.GlobalPluginCollector.GetPluginCollector(), "DonatorRank")
    rank = donatorrank.Invoke("CheckPerm", SteamID, "Rank")
    return rank
end
Error:
Code:
[6/21/2016 10:55:11 PM] [Error] [MoonSharp] Error in plugin LuaTest:
[6/21/2016 10:55:11 PM] [Error] [MoonSharp] Invoke failed: MoonSharp.Interpreter.ScriptRuntimeException: attempt to index a nil value
  at MoonSharp.Interpreter.Execution.VM.Processor.ExecIndex (MoonSharp.Interpreter.Execution.VM.Instruction i, Int32 instructionPtr) [0x00000] in <filename unknown>:0
  at MoonSharp.Interpreter.Execution.VM.Processor.Processing_Loop (Int32 instructionPtr) [0x00000] in <filename unknown>:0
BUT
Doing Python to Lua and in the lua function Util.Log("Blah Blah") will work, Just seems it doesn't want to return any values (Above error).

Magma's invoke is internal use only.

Haven't tried C#

------------------------------------------------------------------------------------------------------------------------
EDIT:
trying to do C#, It will not compile
Code:
Severity    Code    Description    Project    File    Line    Suppression State
Error    CS1501    No overload for method 'GetPlugin' takes 2 arguments    CTestPlugin    C:\Users\****\Desktop\CTestPlugin\CTestPlugin\Class1.cs    51    Active

Severity    Code    Description    Project    File    Line    Suppression State
Error    CS1061    'object' does not contain a definition for 'Invoke' and no extension method 'Invoke' accepting a first argument of type 'object' could be found (are you missing a using directive or an assembly reference?)    CTestPlugin    C:\Users\****\Desktop\CTestPlugin\CTestPlugin\Class1.cs    52    Active
C#:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Fougerite;
using IronPythonModule;
using MagmaModule;

namespace CTestPlugin
{
    public class CTestPlugin : Fougerite.Module
    {
        public override string Name
        {
            get
            {
                return "CTestPlugin";
            }
        }

        public override string Author
        {
            get
            {
                return "Jakkee";
            }
        }

        public override Version Version
        {
            get
            {
                return new Version("1.0");
            }
        }

        public override void Initialize()
        {
            Hooks.OnCommand += HandleCommand;
        }

        public override void DeInitialize()
        {
            Hooks.OnCommand -= HandleCommand;
        }

        public void HandleCommand(Fougerite.Player player, string cmd, string[] args)
        {
            if (cmd == "TestC")
            {
                var donatorrank = GlobalPluginCollector.GetPlugin(GlobalPluginCollector.GetPluginCollector(), "DonatorRank");
                var rank = donatorrank.Invoke("CheckPerm", player.SteamID, "Rank");
                player.Message("Your rank is: " + rank);
            }
        }
    }
}
Fougerite.GlobalPluginCollector

Simply use

GlobalPluginCollector