Member name saving in a file
#1

When I invited someone to join a faction, I want his name to be auto written in a file. For example, I invited John_Smith into LSPD and his name will be written in "factions/LSPDMembers.ini". I have no idea how those function does because most of the thing got deleted...

Can anyone teach me??

Код:
stock Facmembersave() {

	new
		szFileStr[30],
		File: iFileHandle = fopen("factions/LSPD.ini", io_write);

      What should I write here???????????
	fclose(iFileHandle);
}
And how to write the name when he got invited into the file?
Reply
#2

I never did INI, but you should do this:
Код:
new pname[MAX_PLAYER_NAME];
GetPlayerName(playerid, pname, sizeof(pname));

printf("[TEST] Player's name is: %s", pname);
I guess you should save the name (string) like this:
Код:
INI_WriteString(iFileHandle, "string_data", "pname"); // Saving string
And this is how it saves: string_data = John
Reply
#3

Why I need to print it?
Reply
#4

You don't, it's for testing to see if it works...
Reply
#5

Well... undefined symbol INI_WriteString...

EDIT: The whole server crashed...
Reply
#6

-DELETE-
Reply
#7

Open the file with io_append and write the name to it
pawn Код:
stock AddTextToFile(filename[], text[]) {
    if(text[0] == EOS) {
        return false;
    }
    new
        File: file = fopen(filename, (fexist(filename) ? io_append : io_write))
    ;
    if(!file) {
        return false;
    }
    fwrite(file, text);
    fclose(file);

    return true;
}
That will add the text to the file
pawn Код:
stock FacAddMemberToFile(playerid) {
    new
        tmp[MAX_PLAYER_NAME + 2]
    ;
    if(GetPlayerName(playerid, tmp, MAX_PLAYER_NAME)) {
        strcat(tmp, "\r\n"); // new line after the name

        return AddTextToFile("factions/LSPDMembers.ini", tmp);
    }
    return false;
}
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)