Kakaoen404 1 Posted August 1, 2015 Share Posted August 1, 2015 (edited) 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 Edited August 1, 2015 by Kakaoen404 1 Link to post Share on other sites
GeorgeZhang 25 Posted August 2, 2015 Share Posted August 2, 2015 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:) Link to post Share on other sites
SaladinoGW 0 Posted August 2, 2015 Share Posted August 2, 2015 But this works on c++? Link to post Share on other sites
Kakaoen404 1 Posted August 2, 2015 Author Share Posted August 2, 2015 (edited) 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 August 2, 2015 by Kakaoen404 Link to post Share on other sites
leftas 125 Posted August 2, 2015 Share Posted August 2, 2015 But this works on c++?In CLR, yes. All the best, Paul. Link to post Share on other sites
SYNTHES1SE 5 Posted August 3, 2015 Share Posted August 3, 2015 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. Link to post Share on other sites
GeorgeZhang 25 Posted August 3, 2015 Share Posted August 3, 2015 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:) Link to post Share on other sites
ClareXoBearrx3R9 250 Posted August 3, 2015 Share Posted August 3, 2015 (edited) 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 August 3, 2015 by ClareXoBearrx3 1 Link to post Share on other sites
alloc8or 426 Posted August 5, 2015 Share Posted August 5, 2015 (edited) 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 August 5, 2015 by Unknown_Modder Link to post Share on other sites
vizzminzi 1 Posted August 9, 2015 Share Posted August 9, 2015 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? Link to post Share on other sites
alloc8or 426 Posted August 13, 2015 Share Posted August 13, 2015 [Controls] Open Menu = 0x78 Close / Go Back = 0x60 Up = 0x68 Select = 0x65 Down = 0x62 Left = 0x64 Right = 0x66 Link to post Share on other sites
whorse 26 Posted August 23, 2015 Share Posted August 23, 2015 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 Link to post Share on other sites
GeorgeZhang 25 Posted August 23, 2015 Share Posted August 23, 2015 Does anyone knows how to store/read a "Vector3" in .ini file? (Aside from reading x/y/z separately) Link to post Share on other sites
ClareXoBearrx3R9 250 Posted September 14, 2015 Share Posted September 14, 2015 (edited) 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 September 14, 2015 by ClareXoBearrx3 1 Link to post Share on other sites
MrGTAmodsgerman 296 Posted September 16, 2015 Share Posted September 16, 2015 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 Link to post Share on other sites
GeorgeZhang 25 Posted September 16, 2015 Share Posted September 16, 2015 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. Link to post Share on other sites
CamxxCore 156 Posted September 17, 2015 Share Posted September 17, 2015 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. Link to post Share on other sites
GeorgeZhang 25 Posted September 17, 2015 Share Posted September 17, 2015 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:) Link to post Share on other sites