Jump to content
Fiskey111

INI help!

Recommended Posts

So, I've seen the github and the previous post about inis, and I made one.  However, I'm not sure where to put my code since my callouts won't recognize it.  This is my code: 

namespace INI
{
    public class EntryPoint
    {
        public static InitializationFile initializeFile()
        {
            InitializationFile ini = new InitializationFile("Plugins/LSPDFR/SecondaryCallouts.ini");
            ini.Create();
            return ini;
        }
        public static String getVehicleType()
        {
            InitializationFile ini = initializeFile();
            string VehicleType = ini.ReadString("Vehicle", "VehicleType", "Police3");
            return VehicleType;
        }
    }
}

Do I put this in the "Secondary Callouts" namespace, make my own above it (like code above), or do I put it under Main?  I've tried all three but I can't get it to work.  This is what I used to try to fetch the ini option:

 myCopCar = new Vehicle("" + VehicleType + ".", SpawnPoint, 0f);

and it won't register the vehicle type stated by the ini.  Any help?

Thanks!

 

Share this post


Link to post
Share on other sites
39 minutes ago, fiskey111 said:

So, I've seen the github and the previous post about inis, and I made one.  However, I'm not sure where to put my code since my callouts won't recognize it.  This is my code: 

namespace INI
{
    public class EntryPoint
    {
        public static InitializationFile initializeFile()
        {
            InitializationFile ini = new InitializationFile("Plugins/LSPDFR/SecondaryCallouts.ini");
            ini.Create();
            return ini;
        }
        public static String getVehicleType()
        {
            InitializationFile ini = initializeFile();
            string VehicleType = ini.ReadString("Vehicle", "VehicleType", "Police3");
            return VehicleType;
        }
    }
}

Do I put this in the "Secondary Callouts" namespace, make my own above it (like code above), or do I put it under Main?  I've tried all three but I can't get it to work.  This is what I used to try to fetch the ini option:

 myCopCar = new Vehicle("" + VehicleType + ".", SpawnPoint, 0f);

and it won't register the vehicle type stated by the ini.  Any help?

Thanks!

 

to be honest I don't use the ragehook defined ini class I use my own that is built off of the windows kernel's own ability to create/read/write ini files

Share this post


Link to post
Share on other sites

What I do is create a static class named Settings(or whatever you want to name it) and there have a static field with the InitializationFile and static properties with the settings:

Example:

namespace SecondaryCallouts
{
    	using Rage;
    	using System.Windows.Forms;

	public static class Settings
	{
	    public static InitializationFile INIFile = new InitializationFile(@"Plugins\INIFileName.ini");
	    
	    public static Keys Key1 { get { return Settings.INIFile.ReadEnum<Keys>("Keys", "Key1", Keys.Y); } }
	}
}

Then in other parts of your code you can call your settings like this:

        Settings.Key1

Edited by alexguirre

Share this post


Link to post
Share on other sites
1 hour ago, alexguirre said:

What I do is create a static class named Settings(or whatever you want to name it) and there have a static field with the InitializationFile and static properties with the settings:

Example:


namespace SecondaryCallouts
{
    	using Rage;
    	using System.Windows.Forms;

	public static class Settings
	{
	    public static InitializationFile INIFile = new InitializationFile(@"Plugins\INIFileName.ini");
	    
	    public static Keys Key1 { get { return Settings.INIFile.ReadEnum<Keys>("Keys", "Key1", Keys.Y); } }
	}
}

Then in other parts of your code you can call your settings like this:

        Settings.Key1

The issue is that I don't need a key, I'm looking for a vehicle.  I tried using that, but I'm getting the error "Cannot implicitly convert type 'String' to 'Rage.Vehicle'"

public static Vehicle VehicleType { get { return Settings.INIFile.ReadEnum<String>("Vehicles", "VehicleType", "Police3"); } } (that's my code for the error)

How do I convert from a string to a vehicle?

Thanks for you help!

Share this post


Link to post
Share on other sites
4 minutes ago, fiskey111 said:

The issue is that I don't need a key, I'm looking for a vehicle.  I tried using that, but I'm getting the error "Cannot implicitly convert type 'String' to 'Rage.Vehicle'"

public static Vehicle VehicleType { get { return Settings.INIFile.ReadEnum<String>("Vehicles", "VehicleType", "Police3"); } } (that's my code for the error)

How do I convert from a string to a vehicle?

Thanks for you help!

What you need is the model.

Example:

 

public static Model VehModel { get { return Settings.INIFile.ReadString("General", "Vehicle Model", "police3"); } }
Edited by alexguirre

Share this post


Link to post
Share on other sites

Ignore this, I was just being dumb!!  Thank you so much for your help!!!

Edited by fiskey111
Not a good coder...

Share this post


Link to post
Share on other sites
On 12/29/2015 at 2:30 PM, alexguirre said:

What you need is the model.

Example:

 


public static Model VehModel { get { return Settings.INIFile.ReadString("General", "Vehicle Model", "police3"); } }

Just another quick question.  I got approval from Stealth33 to use the Beats/Units/Areas in my callout pack, but I'm having some trouble figuring out how to set it up in the ini.  I'd like to use that above method, but what do I use in place of "Model"?   I've tried searching for the correct term but I've come up empty handed!  It's no big deal, I'll survive without it, but it would be nice to have!

Thanks anyone!

Share this post


Link to post
Share on other sites
42 minutes ago, fiskey111 said:

Just another quick question.  I got approval from Stealth33 to use the Beats/Units/Areas in my callout pack, but I'm having some trouble figuring out how to set it up in the ini.  I'd like to use that above method, but what do I use in place of "Model"?   I've tried searching for the correct term but I've come up empty handed!  It's no big deal, I'll survive without it, but it would be nice to have!

Thanks anyone!

I don't know how Stealth does it but I will go for string.

Share this post


Link to post
Share on other sites
2 hours ago, alexguirre said:

I don't know how Stealth does it but I will go for string.

Thank you, that worked! I thought I had tried that, but I guess I either did it wrong or am going crazy!

 

1 hour ago, Stealth22 said:

I built a class of Enums for every audio file. But string will work just as well. 

Thank you, it worked as string so I'm going to leave it be so I don't screw it up, haha!

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×