Loading/Saving from .cfg file???
#1

Hello!!!!!!!!!!!!

GOOD DAY!!!!!!!!!!!!!!!!!!!!!!

I want to ask if im possible to make a loading/saving a data from .cfg file


For example:

I set the color of family 1 to "red"

then it will store all the data into .cfg

Is it possible?

and i how could i load it when somebody execute this command:

/bandana

for example your in family 1, so every time you do /bandana your name tag color will be set to "red"
Thats i all

Im glad to your helps!!

Thanks in advance!
Reply
#2

It's pretty simple to read the content of a file. To be able to use this function on /bandana just put "ReadFile(playerid);" inside the command.

pawn Код:
#define FILEPATH "/FileName.cfg"
new FamilyColor[MAX_PLAYERS];

stock ReadFile(playerid)
{
    new string[500];
    new File:File=fopen(FILEPATH, io_read);
    while(fread(File, string))
    {
        FamilyColor[playerid] = strval(string);
        SetPlayerColor(playerid, FamilyColor[playerid]);
    }
    fclose(File);
}
EDIT: To save the color to the file:
pawn Код:
new File:File1=fopen(FILENAME, io_write);
format(string, sizeof(string), "PUT YOUR COLOR INSIDE HERE");
fwrite(File1, string);
fclose(File1);
You can also make the command input the color also using a variable, like: new color = GetPlayerColor(playerid);, and so on.

Hope it helps!
Reply
#3

Quote:
Originally Posted by SickAttack
Посмотреть сообщение
It's pretty simple to read the content of a file. To be able to use this function on /bandana just put "ReadFile(playerid);" inside the command.

pawn Код:
#define FILEPATH "/FileName.cfg"
new FamilyColor[MAX_PLAYERS];

stock ReadFile(playerid)
{
    new string[500];
    new File:File=fopen(FILEPATH, io_read);
    while(fread(File, string))
    {
        FamilyColor[playerid] = strval(string);
        SetPlayerColor(playerid, FamilyColor[playerid]);
    }
    fclose(File);
}
Hope it helps!
Hey can you please explain each line ?

So i can do it more unique
Reply
#4

pawn Код:
#define FILEPATH "/FileName.cfg" // Path within scriptfiles.
new FamilyColor[MAX_PLAYERS]; // Variable were the color will be stored.
 // Black space.
stock ReadFile(playerid) // A stock.
{ // A character.
    new string[128]; // A variable, well you know what this is for right?
    new File:File=fopen(FILEPATH, io_read); // Open the file and read it.
    while(fread(File, string)) // While the code reads the file.
    { // A character.
        FamilyColor[playerid] = strval(string); // Store the color in the variable and convert the string to an integer.
        SetPlayerColor(playerid, FamilyColor[playerid]); // Set the players color to the color read from the file.
    } // A character.
    fclose(File); // Close the file.
} // A character.
pawn Код:
new string[128]; // Define the cells of the string.
new File:File1=fopen(FILENAME, io_write); // Open the file and write a string.
format(string, sizeof(string), "PUT YOUR COLOR INSIDE HERE"); // String to write.
fwrite(File1, string); // Write the string.
fclose(File1); // Close the file.
Done. I just don't understand how are you going to make it more unique?
Reply
#5

Quote:
Originally Posted by SickAttack
Посмотреть сообщение
pawn Код:
#define FILEPATH "/FileName.cfg" // Path within scriptfiles.
new FamilyColor[MAX_PLAYERS]; // Variable were the color will be stored.
 // Black space.
stock ReadFile(playerid) // A stock.
{ // A character.
    new string[128]; // A variable, well you know what this is for right?
    new File:File=fopen(FILEPATH, io_read); // Open the file and read it.
    while(fread(File, string)) // While the code reads the file.
    { // A character.
        FamilyColor[playerid] = strval(string); // Store the color in the variable and convert the string to an integer.
        SetPlayerColor(playerid, FamilyColor[playerid]); // Set the players color to the color read from the file.
    } // A character.
    fclose(File); // Close the file.
} // A character.
pawn Код:
new string[128]; // Define the cells of the string.
new File:File1=fopen(FILENAME, io_write); // Open the file and write a string.
format(string, sizeof(string), "PUT YOUR COLOR INSIDE HERE"); // String to write.
fwrite(File1, string); // Write the string.
fclose(File1); // Close the file.
Done. I just don't understand how are you going to make it more unique?
CHEEE!!

Thanks

But i can i set the color on every family slot and save it on .cfg ??

CMD:families(playerid, params[])
{
new string[128], familyid;

if(sscanf(params, "d", familyid))
{
new number = 0;
for(new i = 0; i < sizeof(FamilyInfo); i++)
{
number ++;
format(string, sizeof(string), "Family %d | Name: %s | Leader: %s | Members: %d",number,FamilyInfo[i][FamilyName],FamilyInfo[i][FamilyLeader],FamilyInfo[i][FamilyMembers]);
SendClientMessage(playerid, COLOR_WHITE, string);
}
return 1;
}

if(familyid < 1 || familyid > MAX_FAMILY) { SendClientMessage(playerid, COLOR_GREY, "Family slot must be between 1 and 14."); return 1; }
familyid -= 1;
if(FamilyInfo[familyid][FamilyTaken] != 1)
{
SendClientMessage(playerid, COLOR_GREY, "That family slot is empty.");
return 1;
}
foreach(Player, i)
{
if(PlayerInfo[i][pGang] == familyid && (AdminDuty[i] != 1))
{
if(PlayerInfo[i][pRank] == 1)
{
format(string, sizeof(string), "* %s: %s | Rank: %s (1).",FamilyInfo[familyid][FamilyName],GetPlayerNameEx(i),FamilyInfo[familyid][FamilyRank1]);
}
else if(PlayerInfo[i][pRank] == 2)
{
format(string, sizeof(string), "* %s: %s | Rank: %s (2).",FamilyInfo[familyid][FamilyName],GetPlayerNameEx(i),FamilyInfo[familyid][FamilyRank2]);
}
else if(PlayerInfo[i][pRank] == 3)
{
format(string, sizeof(string), "* %s: %s | Rank: %s (3).",FamilyInfo[familyid][FamilyName],GetPlayerNameEx(i),FamilyInfo[familyid][FamilyRank3]);
}
else if(PlayerInfo[i][pRank] == 4)
{
format(string, sizeof(string), "* %s: %s | Rank: %s (4).",FamilyInfo[familyid][FamilyName],GetPlayerNameEx(i),FamilyInfo[familyid][FamilyRank4]);
}
else if(PlayerInfo[i][pRank] == 5)
{
format(string, sizeof(string), "* %s: %s | Rank: %s (5).",FamilyInfo[familyid][FamilyName],GetPlayerNameEx(i),FamilyInfo[familyid][FamilyRank5]);
}
else if(PlayerInfo[i][pRank] == 6)
{
format(string, sizeof(string), "* %s: %s | Rank: %s (6).",FamilyInfo[familyid][FamilyName],GetPlayerNameEx(i),FamilyInfo[familyid][FamilyRank6]);
}
else
{
format(string, sizeof(string), "* %s: %s | Rank: %s.",FamilyInfo[familyid][FamilyName],GetPlayerNameEx(i),FamilyInfo[familyid][FamilyRank1]);
}
SendClientMessage(playerid, COLOR_GREY, string);
}
}
return 1;
}
Reply
#6

Yes, but you'll have to make some adjustments so that the code could read it and store it into the string, but If you're going to use it for that then use y_ini instead.
Reply
#7

Quote:
Originally Posted by SickAttack
Посмотреть сообщение
Yes, but you'll have to make some adjustments so that the code could read it and store it into the string, but If you're going to use it for that then use y_ini instead.
Can you give me a example?

Of setting the COLOR inside the .cfg file ?

and loading the color /badana
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)