I'm usgin that:
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!"; } } }And the error persists.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]); } } }
I have the last version of the server and oxide mod.
Solved Run a function from another PLUGIN if it doesn't have an API function?
Discussion in 'Rust Development' started by TheRotAG, Feb 10, 2015.
-
Are you sure my plugin is being loaded first then ptest?
-
Now its working :S, i change the name of method from Test to NewMethod and this work. Next i change again to Test and works again
Thanks Hatemail for your help! -
Guys,
I'm trying to call the C_Balance function from 00-Economics plugin from Bombardir but no success at all until the moment...
Code:[ChatCommand("check")] void cmdMoney(BasePlayer player, string command, string[] args) { var checkMoney = plugins.Find("00-Economics"); var currentPurse = checkMoney.CallHook("C_Balance", player, ""); Puts("#################### SUCCESS ####################"); SendReply(player, "Current money in the purse: "+currentPurse.ToString()); }
-
-
-
Code:EconomyData = GetEconomy.Call("GetUserDataFromPlayer", player);
Since C_Balance takes 3 arguments it would probably be
Code:.Call("C_Balance", player, null, "PlayerName")
When you send "*.CallHook("C_Balance", player, "PlayerName")" then "PlayerName" fills in the cmd argument slot. Maybe null is an incorrect method or maybe you should send cmd instead of null. -
C_Balance doesn't return anything so why are you trying to get a return value?
Also the call is just simple: checkMoney.CallHook("C_Balance", player, null, args); -
What about calling GetUserDataFromPlayer, I am using
Code:GetEconomy = plugins.Find('00-Economics') || false; GetEconomy.Call("GetUserDataFromPlayer", player);
Code:[Oxide] 10:05 PM [Debug] ExType: TargetInvocationException [Oxide] 10:05 PM [Error] Failed to call hook 'cmdBounty' on plugin 'Bounty Board ' (NullReferenceException: Object reference not set to an instance of an object)
-
GetUserDataFromPlayer isn't a plugin function...so you can't call it.
-
-
-
-
Get a reference to the economics plugin.
Call the GetEconomyAPI function on the stored plugin reference and cast it to a LuaTable.
Loops through all the tables keys and check if its a lua function, store the function you want to call in a variable.
Create an array with the table reference and the ags you want to pass to the function.
Using reflection and the LuaPlugin reference get the Method CallLuaFunction.
Invoke said method passing in the plugin reference, and an array of the function and arguments.
Cast results back accordingly. -
You should rather use the PluginReference C# plugin feature instead of having to use plugins.Find every time you want to call a method. You can find an example of usage in the Rust SamplePlugin.
-
How would you go about using this feature through JavaScript? Would it just be for example?
Code:var test = Plugin.PluginReference(00-Economics);
-
It is a C# plugin specific feature which is exposed via C# custom attributes.
-