Hiya,
Having a spot of bother with calling methods from another plugin - I have the following code in my 'core' plugin:
And this in a second plugin:Code:using Oxide.Core.Plugins; using Oxide.Core.Libraries;namespace Oxide.Plugins { [Info("Core", "Rebajas", "0.0.1")] [Description("Oxide plugin.")] class RustAlertCore : RustPlugin { string privateKey; protected override void LoadDefaultConfig() { Config.Clear(); Config["privateKey"] = "11111111111111111111111111111111"; SaveConfig(); } void Init() { privateKey = (string)Config["privateKey"]; } string GetPrivateKey() { /* Make the private key accessible to other plugins */ Puts("In GetPrivateKey: " + privateKey); return privateKey; } }}
But the value is not returnedCode:[PluginReference] Plugin RustAlertCore; string privateKey; void Init() { /* Get the private key from core */ privateKey = (string)RustAlertCore?.Call("GetPrivateKey"); Puts("Private key: " + privateKey); }additionally I don't see the message from the core method in the console.
Any help appreciated,
T.
Solved Call to plugin method from second plugin not working (calling in Init())
Discussion in 'Rust Development' started by Rebajas, Jun 22, 2018.
-
I think you have to precede GetPrivateKey() with [HookMethod("GetPrivateKey")] to make it accessible to other plugs.
-
If I do the method call like this:
Code:void Init() { var RustAlertCore = plugins.Find("RustAlertCore"); privateKey = (string)RustAlertCore?.Call("GetPrivateKey"); Puts("Private key: " + privateKey); }
Basically I am trying to tidy up some code and the way as described in my first post seems the cleanest.
---
Steenamaroo: not sure where you mean - literally on the line before I define the method? I've not seen an example using this syntax before... -
Yep.
My knowledge is very limited here but any time I've seen/used external calls it's been
Code:[HookMethod("NameHere")] public string NameHere() { //return some string }
string result = (string)SomePlugin?.CallHook("NameHere");Last edited by a moderator: Jun 22, 2018 -
Hmm, I had tried that but it didn't seem to make any difference - I see you added in more info but I've started down a different route now
If what I'm trying now doesn't sort this out I'll revisit using your syntax.
-
Ok, cool.
I'm sure there's more than one way to skin the cat.
That's just the one I'm using. -
My plugin looks like Frankenstien's Monster right now
I am wondering if it might have been some sort of race condition where the Init was firing before the other plugin was ready. I changed the Init to OnPluginLoaded and it seems to be working now... fingers crossed. -
I think you can check if a referenced plugin is null.
In your case - if (RustAlertCore == null) -
Oo, that might be useful later - currently looking at something else I've managed to break while getting this sorted
-
Wulf Community Admin
-
Hi Wulf, I think I'm getting there - piecing things together slowly. Alot of it seemed to be the Init() not triggering when I thought it would... anyway, getting there
-
Wulf Community Admin
-
Good to know, thanks. ^^