I am building quite a complex and large plugin, so i love to split the plugin files like this:
File A.cs
File B.csCode:// Requires: B // Requires: Cnamespace Oxide.Plugins { [Info("A", "Test", "1.0.0")] public class A : RustPlugin { B b = new B(); C c = new C(); void Init() { b.Setup(this); c.Setup(this); } } }
File C.csCode:namespace Oxide.Plugins { [Info("B", "Test", "1.0.0")] public class B : RustPlugin { A a; public void Setup(A a) { this.a = a; } void Foo() { Puts("Foo"); } } }
I tried addingCode:namespace Oxide.Plugins { [Info("C", "Test", "1.0.0")] public class C : RustPlugin { A a; public void Setup(A a) { this.a = a; this.a.b.Foo(); } } }to both files C and B, but then it gets stuck because it has to wait on each other.Code:// Requires: A
Solved Splitting plugin over multiple files
Discussion in 'Rust Development' started by black flame, Nov 10, 2017.
-
Wulf Community Admin
If referencing other plugins using // Requires, those methods would need to be public, not private. All dependent plugins will load after their parent has been loaded.
-
-
Wulf Community Admin
-
-
Wulf Community Admin
-
Foo.cs
Code:// Requires: Bar // Requires: Yaynamespace Oxide.Plugins { [Info("Foo", "Test", "1.0.0")] public class Foo : RustPlugin { public string x = "Hello World!"; public Bar bar = new Bar(); public Yay yay = new Yay(); void Init() { bar.Setup(this); yay.Setup(this); } } }
Code:namespace Oxide.Plugins { [Info("Bar", "Test", "1.0.0")] public class Bar : RustPlugin { private Foo foo = null; public void Setup(Foo foo) { this.foo = foo; } public void DoStuff() { Puts("Thanks wulf :)"); } } }
Code:namespace Oxide.Plugins { [Info("Yay", "Test", "1.0.0")] public class Yay : RustPlugin { private Foo foo = null; public void Setup(Foo foo) { this.foo = foo; this.foo.bar.DoStuff(); } } }
Code:Foo plugin is waiting for requirements to be loaded: Bar and Yay Loaded plugin Yay v1.0.0 by Test Foo plugin is waiting for requirements to be loaded: Bar Loaded plugin Bar v1.0.0 by Test [Bar] Thanks wulf :) Loaded plugin Foo v1.0.0 by Test
---
Then one small other thing, to load plugin requirements i should useCode:// Requires: Yay
Code:// Require: Yay