Skip to content

Configuration

Mike Puskar edited this page Dec 29, 2021 · 15 revisions

IPT.Common contains an abstract Configuration class that can be inherited. This provides a simple interface to external INI files. Each desired setting is declared as a public instance member and is automatically loaded via the built-in LoadINI method. The settings can then be referenced using the Value property of each member. You must override the Load method.

NOTE: For user inputs, adding "Modifier" to the INI entry automatically adds it to the combo. See below for an example.

Example

using IPT.Common.User;
using IPT.Common.Settings;

namespace IPT.TestPlugin
{
    internal class Config : Configuration
    {
        public SettingKeyCombo PerformActionKey = new SettingKeyCombo("Hotkeys", "PerformActionKey", "Performs an action.");
        public SettingInt PedCount = new SettingInt("Peds", "PedCount", "The number of Peds affected by the action.", 3, 0, 5, 1);
        public SettingFloat ActionRange = new SettingFloat("Peds", "ActionRange", "The range affected by the action.", 100f, 10f, 200f, 10f);

        public override void Load()
        {
            LoadINI("plugins/LSPDFR/TestPlugin.ini");
        }
    }
}

Usage

var config = new Config();
Console.WriteLine(config.PedCount.Value);  // prints the default (3) 
config.Load();
Console.WriteLine(config.PedCount.Value);  // prints the INI value (5)

INI File

[Hotkeys]
PerformActionKey=NumPad0
PerformActionKeyModifier=LControl

[Peds]
PedCount=5
ActionRange=100
Clone this wiki locally