Using classes from another plugin
Discussion in 'Rust Development' started by [wRECK] Enth, Oct 3, 2015.
-
something like this?
Code:using Oxide.Core.Plugins; namespace Oxide.Plugins { [Info("Main Plugin", "Zhahaman2001", 1.0, ResourceId = 0)] class MainPlugin : RustPlugin { [PluginReference] Plugin OtherPlugin; string GetStringFromOtherPlugin(string PassThis) { string ReturnString = OtherPlugin?.Call("SendHelloMessage", PassThis) as string; return ReturnString; } } }Code:namespace Oxide.Plugins { [Info("Other Plugin", "Zhahaman2001", 1.0, ResourceId = 0)] class OtherPlugin : RustPlugin { string SendHelloMessage(string PassThis) { return "Hello world - " + PassThis; } } } -
Wulf Community Admin
You can actually have an include file, but that wouldn't be recommended for public plugins right now. The plugin would also have to be packaged as a zip and manually unpacked, which users would then need to manually unpack.
There are also some other limitations currently, include files aren't preparsed yet, so they can't have requirements, references or 'using' statements.
@bawNg would know more about it though. -
Well at the moment You can try to parse the class in a dictionary to be called by another plugin And then unparse it to the class.
It' s a huge workaround, but at the moment there is no other way.
You could also save it as a class inside a file And load it from the other plugin, but that's worse as it Will use a lot of resource to save And load a filé especially if it's big -
The nice thing about shipping a single .cs file is that its really easy for people use - and this is really important. For this reason, I also dislike dependencies between mods - you're just making it more complex for people to use your mod.
The down side is that does indeed put some handcuffs on us as developers. For more complex plug-ins, I really want don't everything in a single class, I don't much care for nested classes, and having to work in a single 700 (and growing) line file is cumbersome. (It also makes unit testing hard).
So, I choose to view the final .cs file as just the delivery package. I've split my work across multiple files, and so I can work as I like. Then I use a small script (written in PowerShell), to assemble all the parts back into a single file. My little script is very specific to the mod I'm working on, but I'm certain it could be generalized for more cases - I'd probably look at using .Net T4 templates for doing this.
For smaller mods, just stick with a single .cs file, and cut and paste your library code around.
Just my 2c.
![[wRECK] Enth](/assets/styles/oxide/logo.og.png)