1. I'm pretty sure this a common question and has been answered many times but this just isn't working for me.

    I'm just starting out with C# so go easy if I ask something stoopid please :)

    I have created two basic plugins, the first plugin is below:

    Code:
    using System;
    using System.Linq;using Rust;using Oxide.Plugins;
    using Oxide.Core.Plugins;namespace Oxide.Plugins {    [Info("Something", "Rebajas", "2016.12.17")]
        [Description("Something")]    public class EventLogger : RustPlugin {        public void AppendToLog() {            Puts("AppendToLog function called");        }    }}
    Additional plugins feed data into the first:

    Code:
            ...
            [PluginReference] Plugin EventLogger;        void OnLootPlayer(BasePlayer player, BasePlayer target) {            EventLogger?.Call("AppendToLog");        }
    My problem at the moment is that I'm not seeing the AppendToLog Puts fire when the OnLootPlayer event triggers. Every example I've seen so far seems the same so I don't really know what else to change.

    Thanks in advance for any help.


    Tony.
     
    Last edited by a moderator: Dec 18, 2016
  2. Got it working!

    Had a public class then a public method - didn't like it :)
     
  3. Wulf

    Wulf Community Admin

    If using // Requires, they'd need to be public. If using [PluginReference] and .Call, they'd need to be private.
     
  4. Hey Wulf,

    Can you expand upon this a bit?

    I want to reference another plugin directly, without having to use [PluginReference]. I want to be able to call public methods from that class as well as use the public data classes inside of it.

    How can I go about reference the instance of this plugin?

    Thanks!

    Adam
    [DOUBLEPOST=1482280005][/DOUBLEPOST]Bah, right as i posted this i figured it out.

    // Requires: ClassType

    at the top.

    I'm leaving all this here incase anyone else has the same problem!
     
  5. Wulf

    Wulf Community Admin

    It actually goes by the file name, which the class usually has to match.
     
  6. Hey Wulf,

    I'm still having some issues.

    My script looks like this:

    Code:
    // Requires: OtherClassnamespace Oxide.Plugins
    {
        [Info("MyClass", "EinTime", "1.1.1")]
        class MyClass : RustPlugin
        {
            private static OtherClass otherClass;
            void Loaded()
            {
                otherClass = (OtherClass)plugins.Find(nameof(OtherClass));
            }
        }
    }
    However, whenever i try to access a member: otherClass.DoMethod(); I get a null reference exception


    Could this be a compilation order issue? Or an issue with getting the OtherClass reference from inside Loaded() ?
     
  7. Wulf

    Wulf Community Admin

    If using // Requires, you do not need to use plugins.Find. If you do use // Requires though, the methods in your other plugin need to be public, not private. I'm not sure why you're trying to cast though?
     
  8. If using // Requires, and not using plugins.Find or a cast how do I get a reference to the instance of OtherClass?
     
  9. Wulf

    Wulf Community Admin

    You can call methods directly if using // Requires, just make sure to add the using statements as necessary.
     
  10. Awesome. Thanks so much for your time Wulf!