1. juk3b0x

    juk3b0x Wood Hoarder Plugin Developer

    I have written two plugins, one for NoKoS and a Duel Plugin.

    i want people to be able to duel each other, even when NoKoS is on.

    so i came up with the idea to create a public static bool in my Duels Plugin, which i wanted to use in my NoKoS.

    like this:

    Code (Text):
    public class Duels : ReignOfKingsPlugin
        {
            public static bool isDuel = false;

     
    Code (Text):
    if (
                        (attackerName.ToLower() == duel[0].ToLower() && defenderName.ToLower() == duel[1].ToLower())
                                                                                ||
                        (attackerName.ToLower() == duel[1].ToLower() && defenderName.ToLower() == duel[0].ToLower())
                       )
                    {
                        isDuel = true;

    and the code from NoKoS:

    Code (Text):
      private void OnEntityDeath(EntityDeathEvent e, Player player)
            {
                if (e.KillingDamage.DamageSource == null || e.KillingDamage.DamageSource.Owner == null)
                {
                    return;
                }
                if (Duels.isDuel == true)
                {
                    return;
                }

    of course it does not work... otherrwise i would not ask.

    VS2015 gives no error.
    Server does not compile due to:

    The Name "Duels" does not exist in the current context.

    yes i tried to go:

    Code (Text):
    Oxide.Plugins.Duels.isDuel
     
    doesnt work either
     
  2. Wulf

    Wulf Community Admin Community Admin Oxide Developer

    You can't access things in another plugin like that, you'll only be able to do so via calling another plugin's method through PluginReference.
     
  3. juk3b0x

    juk3b0x Wood Hoarder Plugin Developer

    and that means?
     
  4. Mughisi

    Mughisi Grenade Master Community Mod Oxide Developer

    To access a public static object you can use the magic Requires reference on top to reference the plugin type you need, in your case

    PluginA.cs:
    Code (C):
    public class PluginA: ReignOfKingsPlugin
    {
        public static bool isBool = false;
    }
     
    PluginB.cs
    Code (C):

    // Requires: PluginA

    public class PluginB: ReignOfKingsPlugin
    {
        private void Loaded()
            => Puts($"PluginA is holding the boolean value {PluginA.isBool}");
    }
     
    Another option would be to add a private method to return the value of the boolean and use a PluginReference attribute to create a reference to the plugin holding that method to call that method to obtain the value.


    PluginA.cs:
    Code (C):
    public class PluginA: ReignOfKingsPlugin
    {
        public bool isBool = false;

        private bool GetBool() => isBool;
    }
     
    PluginB.cs
    Code (C):
    using Oxide.Core.Plugins;

    [PluginReference] Plugin PluginA;
    public class PluginB: ReignOfKingsPlugin
    {
        private void Loaded()
            => Puts($"PluginA is holding the boolean value {PluginA.CallHook("GetBool")}");
    }
     
     
  5. juk3b0x

    juk3b0x Wood Hoarder Plugin Developer

    why are you guys always so complicated / out of the book...
    really, what does this have to do with Puts?

    does that mean, that i need to put it in
    void loaded

    and HOW!

    it cant be done with a "Puts" i guess....
     
  6. Mughisi

    Mughisi Grenade Master Community Mod Oxide Developer

    The Puts is just an example, you can store it in your variable like `isDuel = yourPlugin.yourObject` or `isDuel = yourPlugin.CallHook("method") as bool;`
    --- Double Post Merged, Jul 25, 2016 ---
    In the previous post I just gave you an example case with PluginA and PluginB where PluginB is using a value (bool) that it obtains from the plugin PluginA. Which is basically the information you need to do what you asked.
     
  7. juk3b0x

    juk3b0x Wood Hoarder Plugin Developer

    THAT was way easier to understand ;)

    thank you very much !

    i know... trying to code plugins while not mastering (or even learning) th language from scratch is kinda stupid, but so far I did well i think, there are just things that i cant imagine :(
     
  8. Mughisi

    Mughisi Grenade Master Community Mod Oxide Developer

    Should have said from the beginning that it was just an example test case with a PluginA and PluginB, sorry for the confusion. And the forums are here for when you have questions ;)
     
  9. juk3b0x

    juk3b0x Wood Hoarder Plugin Developer

    Still does not work, though...
    its still says: Duels does not exist in the current context
     
  10. Mughisi

    Mughisi Grenade Master Community Mod Oxide Developer

    Can you post the full code of both plugins? And if anything would be private and you don't want it out here you can also pm me if you prefer to do that.
     
  11. juk3b0x

    juk3b0x Wood Hoarder Plugin Developer

    nah, i dont mind, if someone sees it, most of my plugins are not usable here on the forums anyway, because they dont meet the plugin requirements for distribution... :p:p:p

    so here are the two files

    the first is the Duels.CS it generates a Duel between two players (and if they kill each other, removes the duel, gives arena points to the winner and so on)
    the second (NoKoS) shall call the bool "isDuel" and shall return; if it is true
     
  12. Mughisi

    Mughisi Grenade Master Community Mod Oxide Developer

    In the NoKoS plugin you need to set the reference to the Duels plugin by using the following on top above the using statements:
    Code (Text):
    // Requires: Duels
     
  13. juk3b0x

    juk3b0x Wood Hoarder Plugin Developer

    with the //?
     
  14. Mughisi

    Mughisi Grenade Master Community Mod Oxide Developer

    Yup :)
     
  15. juk3b0x

    juk3b0x Wood Hoarder Plugin Developer

    ok i tried every combination of what you said....

    putting it ABOVE the using statements like

    Requires : Duels

    gives me:

    "A namespace cannot directly contain members such as fields or methods"

    putting it ABOVE using like:

    //Requires : Duels

    does absolutely nothing

    putting it in the class does not work either
     
  16. Wulf

    Wulf Community Admin Community Admin Oxide Developer

    Could you provide the updated files you have right now?

    That would only be required if you used this for the PluginReference:

    [PluginReference] PluginA PluginA;

    This allows you to call methods from the other plugin directly, ie. PluginA.GetBool().

    The other method like you had was [PluginReference] Plugin PluginA;, but this method would require you to use the .Call / .CallHook to get what you want.
     
  17. juk3b0x

    juk3b0x Wood Hoarder Plugin Developer

    lol there is not much to upload (updated files) because i just did what mughisi said, and failed already :)

    putting //Requires : Duels above the using directives
    has absolutely NO effect

    so I did not go on
    --- Double Post Merged, Jul 25, 2016 ---
    is there any plugin you know of, that already does such a thing ?

    i might look at that to understand how it works
     
  18. Wulf

    Wulf Community Admin Community Admin Oxide Developer

    You can look at my Slack plugins, they use a combo of the // Requires and the Call method. There are also Call examples the Overview for my Email API, Push API, and other similar plugins.
     
  19. Mughisi

    Mughisi Grenade Master Community Mod Oxide Developer

    Code (Text):
    // Requires: Duels
    is parsed by the C# extension and should give the NoKoS plugin access to use the public static objects. Make sure that nothing else is above that reference.
     
  20. Wulf

    Wulf Community Admin Community Admin Oxide Developer

    You'd still have to change the reference to not just have "Plugin" for that method to work, and you wouldn't use Call/CallHook with it.