1. juk3b0x

    juk3b0x Wood Hoarder Plugin Developer

    Hi to everyone,

    No matter which plugin i look at,

    I cant figure out how to make my plugin configurable....

    To start easy i made a plugin with only ONE variable float that i want to make "configurable"

    can anyone tell me how to do this, so Oxide uses it (and creates the config file of course)?

    Code (Text):
    private float SpeedMultiplier = 0.25f;
     
  2. Wulf

    Wulf Community Admin Community Admin Oxide Developer

    Super basic example:
    Code (C#):
    protected override void LoadDefaultConfig()
    {
        Config["SpeedMultiplier"] = 0.25f;
    }
    With this you'd call Config["SpeedMultiplier"] where needed.

    Slightly advanced example:
    Code (C#):
    float speedMultiplier = Config.Get<float>("SpeedMultiplier")

    protected override void LoadDefaultConfig()
    {
        Config["SpeedMultiplier"] = 0.25f;
    }
    With this you'd call speedMultiplier where needed.

    More advanced example:
    Code (C#):
    float speedMultiplier;

    void Init() => LoadDefaultConfig();

    protected override void LoadDefaultConfig()
    {
        Config["SpeedMultiplier"] = speedMultiplier = GetConfig("SpeedMultiplier", 0.25f);
        SaveConfig();
    }

    T GetConfig<T>(string name, T defaultValue) => Config[name] == null ? defaultValue : (T)System.Convert.ChangeType(Config[name], typeof(T));
    With this you'd call speedMultiplier where needed.
     
    Last edited: Jul 31, 2016
  3. juk3b0x

    juk3b0x Wood Hoarder Plugin Developer

    And this does also save the file to the oxide/configs folder?
    --- Double Post Merged, Jul 31, 2016 ---
    taking the advanced one:
    gives me:

    "a field initializer cannot reference the non static field method or property "Plugin.Config"
     
  4. Wulf

    Wulf Community Admin Community Admin Oxide Developer

    You'd need to add the using statements needed. The middle one I didn't really test, the last one is what I use.
     
  5. juk3b0x

    juk3b0x Wood Hoarder Plugin Developer

    i have the using directives added... it still says this
     
  6. Wulf

    Wulf Community Admin Community Admin Oxide Developer

    Like I said, untested for the 2nd. You may need to experiment a bit, else try one of the other examples. ;)

    I use the 3rd example, which I know works.
     
  7. juk3b0x

    juk3b0x Wood Hoarder Plugin Developer

    now it tells me:

    method needs a return value (@ float SpeedMultiplier;)
    --- Double Post Merged, Jul 31, 2016 ---
    must have a return type, sorry
     
  8. Wulf

    Wulf Community Admin Community Admin Oxide Developer

    That's not a method, it doesn't have a return. How exactly are you using it right now?
     
  9. juk3b0x

    juk3b0x Wood Hoarder Plugin Developer

    like you posted?

    just copy pasted
     
  10. Wulf

    Wulf Community Admin Community Admin Oxide Developer

    Could I see your code so far?
     
  11. juk3b0x

    juk3b0x Wood Hoarder Plugin Developer

  12. Wulf

    Wulf Community Admin Community Admin Oxide Developer

    Are you sure you don't have that inside a method or something or have an issue above that?
     
  13. juk3b0x

    juk3b0x Wood Hoarder Plugin Developer

    definately...
    when setting float SpeeMultiplier = 0.25 and deleting the rest, everything works fine
     
  14. Wulf

    Wulf Community Admin Community Admin Oxide Developer

    There's something else going on in your code then, because that's standard C# code and I've been using it like that for over a year. ;)

    I'd need to see the rest to tell what's up.
     
  15. juk3b0x

    juk3b0x Wood Hoarder Plugin Developer

    i have removed Init()=>

    and it works
     
  16. Wulf

    Wulf Community Admin Community Admin Oxide Developer

    Ahh, I see... it was just missing a void there in front of it. Somehow missed that earlier. ;)

    The error wasn't actually with the float. I updated the example, good catch.
     
  17. juk3b0x

    juk3b0x Wood Hoarder Plugin Developer

    in any way:

    NOW I HVE MY FIRST FULLY WORKING configurable plugin WITH LANGUAGE Support!
    my i publish that now ?
    --- Double Post Merged, Jul 31, 2016 ---
    :p:p:p
     
  18. juk3b0x

    juk3b0x Wood Hoarder Plugin Developer

    Ok Fully working was a bit early...

    can u imagine why this happens:

    in my class i have a function:

    Code (Text):
    private float TimeFromCrestToTarget (Player player, Player targetPlayer)
            {
                var crestScheme = SocialAPI.Get<CrestScheme>();
                var crest = crestScheme.GetCrest(player.Id);
                Vector3 CrestPosition = crest.Position;
                Puts(CrestPosition.ToString());
                Vector3 targetPlayerPosition = targetPlayer.Entity.Position;
                Puts(targetPlayerPosition.ToString());
                float distance = float.Parse((Vector3.Distance(CrestPosition, targetPlayerPosition)*SpeedMultiplier).ToString());
                Puts(distance.ToString());
                return distance;
               
            }
    the Puts return the following:

    (-188.4, 148.7, 1185.0)
    (-188.6, 148.1, 1187.1)
    AND
    33.12627

    the two objects positions are correct (i am standing right in front of the Object) the distance should be something like "1" overall.
    it still is more than 33?!?!
    --- Double Post Merged, Jul 31, 2016 ---
    ok ok , Rollback...
    the problem is the parsing....
    nevermind.
    solved...
    --- Double Post Merged, Jul 31, 2016 ---
    ok now i have another problem:

    if i change the value in the config file, i HAVE TO reload the plugin so it recognizes the new value.
    Is this supposed to be like that?

    can i not change the config file "OnTheFly"?
     
  19. Mughisi

    Mughisi Grenade Master Community Mod Oxide Developer

    It is supposed to be like that :)
     
  20. juk3b0x

    juk3b0x Wood Hoarder Plugin Developer

    Ah, ok, then im good ;)