Y_INI read from ini, set variable
#1

So, I have an "/OOC" chat, and I a "settings.ini" file in my scriptfiles. I have a line in the "settings.ini" that says "ooc = 0" stating that OOC is disabled. (I am using Y_INI). How can I set the value of "ooc" to a string in SA:MP so I can do the following?
pawn Code:
new ooc[2];
ooc = ?????; // <----- The value of "ooc" in "scriptfiles/settings.ini"

if(ooc == 1){

    //continue with sending message

} else {
    SendClientMessage(playerid, COLOR_LIGHTBLUE, "/OOC chat has been disabled by admins.");
}
bumpppp, anyone know how to load info from INI and use it as a string? Like for example, could someone write a small script checks what "money" is equal to in a file "scriptfiles/users/user.ini", and update their amount of money? Then, I can just refrence that every time I need to get something from an ini file

I find it hard to believe that no one knows how to retrive values from INI files, when almost all the gamemodes and filterscripts out there do it.
Reply
#2

Why would yuo want to use it as a string? Either read and store as integer or bool.
Reply
#3

Quote:
Originally Posted by LarzI
View Post
Why would yuo want to use it as a string? Either read and store as integer or bool.
But what if one of the lines in the INI file is something like...
Faction = LSPD

or does everything have to be integers? like..
Faction_ID = 3

Or what is bool?
Reply
#4

Quote:
Originally Posted by Nathan_Taylor
View Post
But what if one of the lines in the INI file is something like...
Faction = LSPD

or does everything have to be integers? like..
Faction_ID = 3

Or what is bool?
It can be however you like. Reading from a file is done with INI_ParseFile, like so..

Say you wanted to read from "scriptfiles/settings.ini"...

pawn Code:
INI_ParseFile( "settings.ini", "LoadSettings_%s" );
// "settings.ini" is our file, and "LoadSettings" is our callback.
pawn Code:
public LoadSettings_info ( name[], value[] )
{
    // Every time you write information to the settings file, you have to use INI_SetTag( fileVariable, "info" );

    INI_Int(            "OOC",              ooc );
    // This loads the integer "OOC" into the variable "ooc"

    INI_String(         "FACTION_0",          FactionNames [ 0 ], 64 );
    // This loads the string "Faction" into the variable "FactionNames [ 0 ]" with a length of 64 cells.
}
Writing to the settings file would be like this..

pawn Code:
new
    INI: mySettingFile = INI_Open( "settings.ini" );

INI_SetTag( mySettingFile, "info" );

INI_WriteInt( mySettingFile, "OOC", 1 );

INI_WriteString( mySettingFile, "FACTION_0", "LSPD" );

INI_Close( mySettingFile );
// Don't forget to close the file after you're done working with it!
I'm pretty sure Y_INI supports booleans as well but I have never really messed with them, so I'm not positive.
Reply
#5

Have this in gamemode code
pawn Code:
//load config file

INI_ParseFile( "settings.ini", "LoadSettings_%s" );

public LoadSettings_info ( name[], value[] )
{
    // Every time you write information to the settings file, you have to use INI_SetTag( fileVariable, "info" );

    INI_Int("OOC", ooc);
   
  return 1;
}
Following errors
pawn Code:
F:\SAMP\gamemodes\naterp.pwn(198) : error 025: function heading differs from prototype
F:\SAMP\gamemodes\naterp.pwn(198) : error 021: symbol already defined: "INI_ParseFile"
F:\SAMP\gamemodes\naterp.pwn(200) : warning 235: public function lacks forward declaration (symbol "LoadSettings_info")
F:\SAMP\gamemodes\naterp.pwn(204) : error 033: array must be indexed (variable "ooc")
F:\SAMP\gamemodes\naterp.pwn(206) : warning 217: loose indentation
F:\SAMP\gamemodes\naterp.pwn(206) : error 079: inconsistent return types (array & non-array)
Reply
#6

pawn Code:
forward LoadSettings_info ( name[], value[] );
You also have to forward the Load callbacks, sorry!
Reply
#7

pawn Code:
//load config file
forward LoadSettings_info ( name[], value[] );
INI_ParseFile( "settings.ini", "LoadSettings_%s" );

public LoadSettings_info ( name[], value[] )
{
    // Every time you write information to the settings file, you have to use INI_SetTag( fileVariable, "info" );

    INI_Int("OOC", ooc);
   
  return 1;
}
Still errors, am I doing something wrong? That code isn't in a callback or anything

pawn Code:
F:\SAMP\gamemodes\naterp.pwn(198) : error 025: function heading differs from prototype
F:\SAMP\gamemodes\naterp.pwn(198) : error 021: symbol already defined: "INI_ParseFile"
F:\SAMP\gamemodes\naterp.pwn(204) : error 033: array must be indexed (variable "ooc")
F:\SAMP\gamemodes\naterp.pwn(206) : warning 217: loose indentation
F:\SAMP\gamemodes\naterp.pwn(206) : error 079: inconsistent return types (array & non-array)
Reply
#8

That's odd, take a look at this test script I made in a few minutes for ya. Works perfectly fine on my end, compile it on your end and try it to make sure your Y_INI is working correctly, then check and see how it works, and duplicate it on your end. (I've included comments explaining virtually everything)

http://pastebin.com/raw.php?i=RhgGyULP
Reply
#9

That one compiles just fine. this is my full file
http://pastebin.com/DVL6pi7C
Maybe you can DL it and try it on your end?
Reply
#10

Quote:
Originally Posted by Nathan_Taylor
View Post
That one compiles just fine. this is my full file
http://pastebin.com/DVL6pi7C
Maybe you can DL it and try it on your end?
Put ParseFile in OnGameModeInit and see what it does, it's not like a callback, it's a literal function and can't be called outside of a callback.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)