1. Want to know exactly what is described in the title.
     
  2. Wulf

    Wulf Community Admin

    Yes, here's an example for Lua:
    Code:
        local emailApi = plugins.Find("email")
        if not emailApi then print("Email API is not loaded! http://oxidemod.org/resources/712/"); return end
        emailApi.Object:EmailMessage("This is a test email", "This is a test of the Email API for Oxide!")
    
     
  3. Luv u Wulf!
    Would kiss u if I could <3
     
  4. tisk tisk tisk lol use the new correct way.

    Use emailApi.CallHook("EmailMessage", "This is a test email", "This is a test of the Email API for Oxide!")
     
  5. Wulf

    Wulf Community Admin

    Thanks, forgot about that one already ha. I guess I should update my plugins with it.
     
  6. But how would CallHook call the function "EmailMessage" as sugested by Wulf?
     
  7. Update answer copy-paste not my friend.
     
  8. New doubt my friends!!!

    In LUA we can do plugins.Find, and how about C#, JS and Python?

    NVM. We can call plugins.Find from any variable inside any language ;)
     
    Last edited by a moderator: Feb 19, 2015
  9. But how can i call a function of MyPlugin in C#?

    I have "MyPlugin" and using plugins.Fing("MyPlugin") i can get it, but when i try to use "MyFunction"

    Plugin myPlugin = plugins.Find("MyPlugin");
    string returnData = myPlugin.MyFunction();

    I have an error because the Plugin Class hasn't the function "MyFuncion". But it i try with direct MyPlugin Class and not Plugin

    MyPlugin myPlugin = plugins.Find("MyPlugin");
    string returnData = myPlugin.MyFunction();

    I have an error because not found MyPlugin Class. :S
     
  10. Wulf

    Wulf Community Admin

    http://oxidemod.org/threads/run-a-f...-doesnt-have-an-api-function.6796/#post-65902

    Use CallHook.
     
  11. Im using CallHook, but the server send me
    Code:
    [Oxide] 1:28 AM [Error] NullReferenceException while calling MyFunction: (Null
    ReferenceException: Object reference not set to an instance of an object)
    MyFunction is
    Code:
    [ChatCommand("ChatCommand")]
            void MyFunction(BasePlayer player, string cmd, string[] args)
            {
                Plugin MyPlugin = plugins.Find("MyPlugin");
                string message=MyPlugin.CallHook("TestFunction", new object[] { ""TestHook" });
                ConsoleSystem.Broadcast("chat.add \"SERVER\" " + message.QuoteSafe(), new object[0]);
            }
    if i change the line "string message= MyPlugin.CallHook......" to stirng message="help"

    The Broadcast Messages appear in the Chat. I use if (MyPlugin != null) this.Puts(MyPlugin.Name)

    to see the name of plugin and verify if plugin var is not null.

    What is wrong?
     
    Last edited by a moderator: May 26, 2015
  12. string message=MyPlugin.CallHook("TestFunction", new object[] { ""TestHook" });
     
  13. Sorry, but this is an error when i copy the original code
     
  14. Well I'm surprised you even got your code to compile then..
    string message=MyPlugin.CallHook("TestFunction", new object[] { "TestHook" }); is invalid as CallHook returns a object every time.

    Your better off posting both plugins or pming me them for me to take a look if you want help.
     
  15. Here are my both plugins, are only for test the CallHook function

    This is the plugin that use CallHook
    Code:
    // Reference: Oxide.Ext.Rustusing System.Collections.Generic;
    using System;
    using UnityEngine;
    using Oxide.Core;
    using Oxide.Core.Configuration;
    using Oxide.Core.Plugins;namespace Oxide.Plugins
    {
        [Info("MyPlugin", "Xephiro", "0.0.1")]
        class MyPlugin : RustPlugin
        {
            private Plugin PluginTest;        void Loaded()
            {
                LoadConfig();
            }        void OnServerInitialized()
            {
                if (plugins.Exists("PTest"))
                {
                    PluginTest = plugins.Find("PTest");                if (PluginTest != null)
                        this.Puts(PluginTest.Name);
                }
            }        [ChatCommand("testingcallhook")]
            void TestingCallHook(BasePlayer player, string cmd, string[] args)
            {          
                string message = "Hello World!";
                message = PluginTest.CallHook("Test", message).ToString();
                ConsoleSystem.Broadcast("chat.add \"SERVER\" " + message.QuoteSafe(), new object[0]);
            }
        }
    }

    This is the another plugin
    Code:
    // Reference: Oxide.Ext.Rustusing System.Collections.Generic;
    using System;
    using UnityEngine;
    using Oxide.Core;
    using Oxide.Core.Plugins;namespace Oxide.Plugins
    {
        [Info("PTest", "Xephiro", "0.0.1")]
        class PTest : RustPlugin
        {
            public string Test(string text)
            {          
                return text + " -- CallHook its works!";
            }
        }
    }
     
  16. Remove the public modifier on your function Test
     
  17. Nop

    Code:
    [Oxide] 2:21 AM [Error] NullReferenceException while calling TestingCallHook: (Null
    ReferenceException: Object reference not set to an instance of an object)
    [Oxide] 2:21 AM [Debug]   at Oxide.Plugins.MyPlugin.TestingCallHook(.BasePlayer player
    , System.String cmd, System.String[] args) [0x00000] in <filename unknown>:0
      at (wrapper managed-to-native) System.Reflection.MonoMethod:InternalInvoke (ob
    ject,object[],System.Exception&)                           
      at System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invoke
    Attr, System.Reflection.Binder binder, System.Object[] parameters, System.Global
     
  18. Opps sorry was on an older build..
    You now have to explicitly state that the method is a hook with recent changes to oxide.

    Code:
    // Reference: Oxide.Ext.Rustusing System.Collections.Generic;
    using System;
    using UnityEngine;
    using Oxide.Core;
    using Oxide.Core.Plugins;namespace Oxide.Plugins
    {
        [Info("PTest", "Xephiro", "0.0.1")]
        class PTest : RustPlugin
        {
            [HookMethod("Test")]
           public string Test(string text)
            {         
                return text + " -- CallHook its works!";
            }
        }
    }
    [DOUBLEPOST=1424930643][/DOUBLEPOST]Also just a little tip: You can use the
    PluginReferenceAttribute for setting of the plugin field, When the plugin that needs referenced the field is set with that instance of said plugin.

    Example:

    Code:
    // Reference: Oxide.Ext.Rustusing System.Collections.Generic;
    using System;
    using UnityEngine;
    using Oxide.Core;
    using Oxide.Core.Configuration;
    using Oxide.Core.Plugins;namespace Oxide.Plugins
    {
        [Info("MyPlugin", "Xephiro", "0.0.1")]
        class MyPlugin : RustPlugin
        {
            [PluginReference("PTest")]
            private Plugin PluginTest;        void Loaded()
            {
                LoadConfig();
            }        void OnServerInitialized()
            {
                if (PluginTest != null)
                    this.Puts(PluginTest.Name);
            }        [ChatCommand("testingcallhook")]
            void TestingCallHook(BasePlayer player, string cmd, string[] args)
            {         
                string message = "Hello World!";
                message = PluginTest.CallHook("Test", message).ToString();
                ConsoleSystem.Broadcast("chat.add \"SERVER\" " + message.QuoteSafe(), new object[0]);
            }
        }
    }
     
  19. Sorry but i have the same error.

    I put "[HookMethod("Test")]" over Test method and "[PluginReference("PTest")]" Over declaration of PluginTest in MyPlugin

    Any other idea ? :(
     
  20. HookMethod is only needed if you wanted you hook method to be public.

    This example works:

    Code:
    // Reference: Oxide.Ext.Rustusing System.Collections.Generic;
    using System;
    using UnityEngine;
    using Oxide.Core;
    using Oxide.Core.Plugins;namespace Oxide.Plugins
    {
        [Info("PTest", "Xephiro", "0.0.2")]
        class PTest : RustPlugin
        {
            string Test(string text)
            {          
                return text + " -- CallHook its works!";
            }
        }
    }
    Code:
    // Reference: Oxide.Ext.Rustusing System.Collections.Generic;
    using System;
    using UnityEngine;
    using Oxide.Core;
    using Oxide.Core.Configuration;
    using Oxide.Core.Plugins;namespace Oxide.Plugins
    {
        [Info("MyPlugin", "Xephiro", "0.0.1")]
        class MyPlugin : RustPlugin
        {
            [PluginReference("PTest")]
            private Plugin PluginTest;        void Loaded()
            {
                LoadConfig();
            }        [ChatCommand("testingcallhook")]
            void TestingCallHook(BasePlayer player, string cmd, string[] args)
            {         
                string message = "Hello World!";
                Puts("Plugin Name: {0}", PluginTest.Name);
                message = PluginTest.CallHook("Test", message).ToString();
                ConsoleSystem.Broadcast("chat.add \"SERVER\" " + message.QuoteSafe(), new object[0]);
            }
        }
    }
    Make sure you are on the latest version of oxide..