Quantcast
Jump to content
Search In
  • More options...
Find results that contain...
Find results in...
    1. Welcome to GTAForums!

    1. GTANet.com

    1. GTA Online

      1. The Cayo Perico Heist
      2. The Diamond Casino Heist
      3. Find Lobbies & Players
      4. Guides & Strategies
      5. Vehicles
      6. Content Creator
      7. Help & Support
    2. Red Dead Online

      1. Frontier Pursuits
      2. Find Lobbies & Outlaws
      3. Help & Support
    3. Crews

    1. Red Dead Redemption 2

      1. PC
      2. Help & Support
    2. Red Dead Redemption

    1. Grand Theft Auto Series

    2. GTA VI

      1. St. Andrews Cathedral
    3. GTA V

      1. Guides & Strategies
      2. Help & Support
    4. GTA IV

      1. The Lost and Damned
      2. The Ballad of Gay Tony
      3. Guides & Strategies
      4. Help & Support
    5. GTA San Andreas

      1. Guides & Strategies
      2. Help & Support
    6. GTA Vice City

      1. Guides & Strategies
      2. Help & Support
    7. GTA III

      1. Guides & Strategies
      2. Help & Support
    8. Portable Games

      1. GTA Chinatown Wars
      2. GTA Vice City Stories
      3. GTA Liberty City Stories
    9. Top-Down Games

      1. GTA Advance
      2. GTA 2
      3. GTA
    1. GTA Mods

      1. GTA V
      2. GTA IV
      3. GTA III, VC & SA
      4. Tutorials
    2. Red Dead Mods

      1. Documentation
    3. Mod Showroom

      1. Scripts & Plugins
      2. Maps
      3. Total Conversions
      4. Vehicles
      5. Textures
      6. Characters
      7. Tools
      8. Other
      9. Workshop
    4. Featured Mods

      1. Design Your Own Mission
      2. OpenIV
      3. GTA: Underground
      4. GTA: Liberty City
      5. GTA: State of Liberty
    1. Rockstar Games

    2. Rockstar Collectors

    1. Off-Topic

      1. General Chat
      2. Gaming
      3. Technology
      4. Movies & TV
      5. Music
      6. Sports
      7. Vehicles
    2. Expression

      1. Graphics / Visual Arts
      2. GFX Requests & Tutorials
      3. Writers' Discussion
      4. Debates & Discussion
    3. Gangs

    1. Announcements

    2. Support

    3. Suggestions

Kakaoen404

.ini file how to?

Recommended Posts

Kakaoen404

So as the title is suggesting i am trying to make a .ini file for my script in gta v so anyone know how to do this please help me :D

Edited by Kakaoen404
  • Like 1

Share this post


Link to post
Share on other sites
GeorgeZhang

note: test = your mod's name

public class test : Script{    private ScriptSettings config;    Keys my_key;    int myvalue;    public test()    {        config = ScriptSettings.Load("scripts\\test.ini");        my_key = config.GetValue<Keys>("General", "my_key", Keys.F9);//(category, name, default value)        myvalue = config.GetValue<int>("General", "myvalue", 100);    }}

implement those and then create test.ini and write in something like:

[General]my_key=F9 //descriptionsmyvalue=1249 //descriptions

hope it helped:)

Share this post


Link to post
Share on other sites
SaladinoGW

But this works on c++?

Share this post


Link to post
Share on other sites
Kakaoen404

note: test = your mod's name

public class test : Script{    private ScriptSettings config;    Keys my_key;    int myvalue;    public test()    {        config = ScriptSettings.Load("scripts\\test.ini");        my_key = config.GetValue<Keys>("General", "my_key", Keys.F9);//(category, name, default value)        myvalue = config.GetValue<int>("General", "myvalue", 100);    }}

implement those and then create test.ini and write in something like:

[General]my_key=F9 //descriptionsmyvalue=1249 //descriptions

hope it helped:)

I have one question though and that is what does the myvalue and mykey? what i think you mean with the mykey is what key i have set in my script correct me if i am wrong on that. and one more thing does it recognize if i have multiple keys setup in my script?

Edited by Kakaoen404

Share this post


Link to post
Share on other sites
leftas

But this works on c++?

In CLR, yes.

 

All the best,

Paul.

Share this post


Link to post
Share on other sites
SYNTHES1SE

 

note: test = your mod's name

public class test : Script{    private ScriptSettings config;    Keys my_key;    int myvalue;    public test()    {        config = ScriptSettings.Load("scripts\\test.ini");        my_key = config.GetValue<Keys>("General", "my_key", Keys.F9);//(category, name, default value)        myvalue = config.GetValue<int>("General", "myvalue", 100);    }}

implement those and then create test.ini and write in something like:

[General]my_key=F9 //descriptionsmyvalue=1249 //descriptions

hope it helped:)

I have one question though and that is what does the myvalue and mykey? what i think you mean with the mykey is what key i have set in my script correct me if i am wrong on that. and one more thing does it recognize if i have multiple keys setup in my script?

 

 

A section is the value enclosed in [], a key is the text before an =.

see this for more information on .ini files and how they work.

Share this post


Link to post
Share on other sites
GeorgeZhang

 

note: test = your mod's name

public class test : Script{    private ScriptSettings config;    Keys my_key;    int myvalue;    public test()    {        config = ScriptSettings.Load("scripts\\test.ini");        my_key = config.GetValue<Keys>("General", "my_key", Keys.F9);//(category, name, default value)        myvalue = config.GetValue<int>("General", "myvalue", 100);    }}

implement those and then create test.ini and write in something like:

[General]my_key=F9 //descriptionsmyvalue=1249 //descriptions

hope it helped:)

I have one question though and that is what does the myvalue and mykey? what i think you mean with the mykey is what key i have set in my script correct me if i am wrong on that. and one more thing does it recognize if i have multiple keys setup in my script?

 

yes, it is the key/value you want to set. you can add more by 1.declare another key/value 2.add more lines similar to the lines i wrote:)

Share this post


Link to post
Share on other sites
ClareXoBearrx3R9

Skorpro also posted some helpful wrapper functions too for INI Files here: http://gtaforums.com/topic/576633-how-to-use-arus-c-scripthook-sdk/?do=findComment&comment=1066870399.

 

Summary of what he wrote:

// INI/FILE FUNCTIONS#define INI_Name "./test mod.ini"// STRINGchar* SKP::SkorproReadString(char* Section, char* Key, const char* DefaultString){    char* Result = new char[255];    memset(Result, 0x00, 255);    GetPrivateProfileStringA(Section, Key, DefaultString, Result, 255, INI_Name);    return Result;}void SKP::SkorproWriteString(char* Section, char* Key, const char* ValueString){    WritePrivateProfileStringA(Section, Key, ValueString, INI_Name);}// INTint SKP::SkorproReadInteger(char* Section, char* Key, int DefaultInt){     int Result = GetPrivateProfileIntA(Section, Key, DefaultInt, INI_Name);     return Result;}void SKP::SkorproWriteInteger(char* Section, char* Key, int ValueInt, b8 DecHex){    char tmpValue[255];    if (DecHex == 0) { sprintf_s(tmpValue, 255, "%d", ValueInt); } // %d = DEC    if (DecHex == 1) { sprintf_s(tmpValue, 255, "%x", ValueInt); } // %x = HEX    WritePrivateProfileStringA(Section, Key, tmpValue, INI_Name); }// FLOATfloat SKP::SkorproReadFloat(char* szSection, char* szKey, float DefaultFloat){    char szResult[255];    char szDefault[255];    double dResult;    float fResult;    sprintf_s(szDefault, "%f",DefaultFloat);    GetPrivateProfileStringA(szSection, szKey, szDefault, szResult, 255, INI_Name);    dResult = atof(szResult);    fResult = (f32) dResult;    return fResult;}void SKP::SkorproWriteFloat(char* szSection, char* szKey, float ValueFloat, int Nachkommastellen){    char szValue[255];    if (Nachkommastellen <= 1) sprintf_s(szValue, "%.1f", ValueFloat);    else if (Nachkommastellen == 2) sprintf_s(szValue, "%.2f", ValueFloat);    else if (Nachkommastellen == 3) sprintf_s(szValue, "%.3f", ValueFloat);    else if (Nachkommastellen == 4) sprintf_s(szValue, "%.4f", ValueFloat);    else if (Nachkommastellen == 5) sprintf_s(szValue, "%.5f", ValueFloat);    else if (Nachkommastellen == 6) sprintf_s(szValue, "%.6f", ValueFloat);    else if (Nachkommastellen >= 7) sprintf_s(szValue, "%.7f", ValueFloat);    WritePrivateProfileStringA(szSection, szKey, szValue, INI_Name); }// Backupvoid SKP::SkorproBackupINI(){    char BackupINI[64];    strncpy_s(BackupINI, INI_Name, 54);    strncat_s(BackupINI, ".backup", 10);    CopyFileA(INI_Name, BackupINI, false); // "false" überschreibt "BackupINI", falls diese existiert!}

(Credits to Skorpro for this).

 

Hope that helps :)

 

EDT: Be sure to remove the SKP:: namespace as necessary, since you probably don't have that -- unless you wish to define it of course ;)

Edited by ClareXoBearrx3
  • Like 1

Share this post


Link to post
Share on other sites
alloc8or

Simple code that I use in my trainer (for the controls):

// .ini file settingsint openMenu = GetPrivateProfileInt("Controls", "Open Menu", 0x78, "./ModMenu.ini"); // 'F9'int closeMenu = GetPrivateProfileInt("Controls", "Close / Go Back", 0x60, "./ModMenu.ini"); // 'NUMPAD0'int menuUp = GetPrivateProfileInt("Controls", "Up", 0x68, "./ModMenu.ini"); // 'NUMPAD8'int menuSelect = GetPrivateProfileInt("Controls", "Select", 0x65, "./ModMenu.ini"); // 'NUMPAD5'int menuDown = GetPrivateProfileInt("Controls", "Down", 0x62, "./ModMenu.ini"); // 'NUMPAD2'int menuLeft = GetPrivateProfileInt("Controls", "Left", 0x64, "./ModMenu.ini"); // 'NUMPAD4'int menuRight = GetPrivateProfileInt("Controls", "Right", 0x66, "./ModMenu.ini"); // 'NUMPAD6'
Edited by Unknown_Modder

Share this post


Link to post
Share on other sites
vizzminzi

 

Simple code that I use in my trainer (for the controls):

// .ini file settingsint openMenu = GetPrivateProfileInt("Controls", "Open Menu", 0x78, "./ModMenu.ini"); // 'F9'int closeMenu = GetPrivateProfileInt("Controls", "Close / Go Back", 0x60, "./ModMenu.ini"); // 'NUMPAD0'int menuUp = GetPrivateProfileInt("Controls", "Up", 0x68, "./ModMenu.ini"); // 'NUMPAD8'int menuSelect = GetPrivateProfileInt("Controls", "Select", 0x65, "./ModMenu.ini"); // 'NUMPAD5'int menuDown = GetPrivateProfileInt("Controls", "Down", 0x62, "./ModMenu.ini"); // 'NUMPAD2'int menuLeft = GetPrivateProfileInt("Controls", "Left", 0x64, "./ModMenu.ini"); // 'NUMPAD4'int menuRight = GetPrivateProfileInt("Controls", "Right", 0x66, "./ModMenu.ini"); // 'NUMPAD6'

 

Can you show whats inside the .ini file?

Share this post


Link to post
Share on other sites
alloc8or

[Controls]
Open Menu = 0x78
Close / Go Back = 0x60
Up = 0x68
Select = 0x65
Down = 0x62
Left = 0x64
Right = 0x66

Share this post


Link to post
Share on other sites
whorse

One easy way to do it is with fscanf:

 

FILE * pFile;int KEY;int optionOne = 0;pFile = fopen("mymod.ini", "r");if (pFile){     fscanf(pFile, "My Mod by me%*\n", NULL);     fscanf(pFile, "\nMAIN OPTIONS:%*\n", NULL);     fscanf(pFile, "Hotkey = [%x]%*\n", &KEY);     fscanf(pFile, "Enable option 1 = [%d]%*\n", &optionOne);     fclose(pFile);}

"%x" means scan for a hex code. 0x61 is numpad-one, 0x63 is numpad=three.

"%d" means scan for a whole number

"%f" means scan for a float.

"%*" means scan for the following character and discard it (I use it here to invalidate newlines, as in "\n")

"%s" scans for a string

"%[^]" scans for a string of specific characters, or scans for a string while ignoring whitespace. Using this with strtok tokens and delimiters can let you make a customizable array of hash key strings (char*[])

 

You assign the scanned value to your variable in the third part (that says &varName). For fscanf to work, you must scan every character in the file in-order (this is why title-lines are assigned to "NULL"). If one character in the file is off, all the text below that character will not be scanned correctly.

 

The mymod.ini file would end up looking like this:

My Mod by meMAIN OPTIONS:Hotkey = [0x6D]Enable option 1 = [1]

Hope this helps

 

Share this post


Link to post
Share on other sites
GeorgeZhang

Does anyone knows how to store/read a "Vector3" in .ini file?

(Aside from reading x/y/z separately)

Share this post


Link to post
Share on other sites
ClareXoBearrx3R9

Does anyone knows how to store/read a "Vector3" in .ini file?

(Aside from reading x/y/z separately)

 

Sorry to bump a 3 week-old threat but... I don't think you can. A Vector3 is a struct that consists of an x, y and z value, of type float. INI's can't deal with a struct AFAIK.

 

Of course, if I'm wrong, someone feel free to correct me. :)

Edited by ClareXoBearrx3
  • Like 1

Share this post


Link to post
Share on other sites
MrGTAmodsgerman

 

Does anyone knows how to store/read a "Vector3" in .ini file?

(Aside from reading x/y/z separately)

 

Sorry to bump a 3 week-old threat but... I don't think you can. A Vector3 is a struct that consists of an x, y and z value, of type float. INI's can't deal with a struct AFAIK.

 

Of course, if I'm wrong, someone feel free to correct me. :)

 

thanks for bump that thread, i dont see it and i need it

Share this post


Link to post
Share on other sites
GeorgeZhang

 

Does anyone knows how to store/read a "Vector3" in .ini file?

(Aside from reading x/y/z separately)

Sorry to bump a 3 week-old threat but... I don't think you can. A Vector3 is a struct that consists of an x, y and z value, of type float. INI's can't deal with a struct AFAIK.

 

Of course, if I'm wrong, someone feel free to correct me. :)

Ok thanks.

Share this post


Link to post
Share on other sites
CamxxCore

Does anyone knows how to store/read a "Vector3" in .ini file?

(Aside from reading x/y/z separately)

Of course you could just append the x, y and z values into a single string and write a method to parse them back into a Vector3 when reading the file.

Share this post


Link to post
Share on other sites
GeorgeZhang

 

Does anyone knows how to store/read a "Vector3" in .ini file?

(Aside from reading x/y/z separately)

Of course you could just append the x, y and z values into a single string and write a method to parse them back into a Vector3 when reading the file.Yeah that us what I did as a work around:)

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • 2 Users Currently Viewing
    0 members, 0 Anonymous, 2 Guests

×
×
  • Create New...

Important Information

By using GTAForums.com, you agree to our Terms of Use and Privacy Policy.