SA-MP Forums Archive
Loading Error - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Loading Error (/showthread.php?tid=388644)



Loading Error - maramizo - 29.10.2012

pawn Код:
stock LoadContacts(playerid)
{
    new str[MAX_PLAYER_NAME+20];
    format(str, MAX_PLAYER_NAME+4, "contacts/%s.cfg",GetPlayerNameEx(playerid));
    if(!fexist(str)) fcreate(str);
    new binfo[2][MAX_PLAYER_NAME];
    new string[256];
    new File:file = fopen(str, io_read);
    if(file)
    {
        new idx = 1;
        while(idx < 20)
        {
            fread(file, string);
            split(string, binfo, '|');
            format(Contacts[playerid][idx], MAX_PLAYER_NAME, "%s", binfo[0]);
            format(ContactsNum[playerid][idx], 6, "%s", binfo[1]);
            idx++;
        }
    }
    print("Contacts loaded successfully.");
    return 1;
}
This code opens the files of wrong players, I.e sometimes I'm online when someone else logs on he's got the information that I should have.
Any help is appreciated.


Re: Loading Error - maramizo - 29.10.2012

pawn Код:
stock LoadContacts(playerid)
{
    new str[MAX_PLAYER_NAME+20];
    format(str, MAX_PLAYER_NAME+20, "/contacts/%s.ini",GetPlayerNameEx(playerid));
    if(!fexist(str)) fcreate(str);
    new string[256];
    new File:file = fopen(str, io_read);
    if(file)
    {
        new idx = 0;
        while(fread(file, string))
        {
            sscanf(string,"s[MAX_PLAYER_NAME]s[6]", Contacts[playerid][idx], ContactsNum[playerid][idx]);
            idx++;
        }
    }
    fclose(file);
    print("Contacts loaded successfully.");
    return 1;
}
This causes player to get data from the file of another player.
Any help?


Re: Loading Error - maramizo - 29.10.2012

Please, can anyone help me?
I don't mind if you make a different string loading system.


Re: Loading Error - maramizo - 30.10.2012

Bump.


Re: Loading Error - maramizo - 30.10.2012

After extreme debugging and raging and fapping, I seem to have found the answer:
pawn Код:
stock LoadContacts(playerid)
{
    new str[MAX_PLAYER_NAME+20];
    format(str, MAX_PLAYER_NAME+20, "/contacts/%s.ini",GetPlayerNameEx(playerid));
    if(!fexist(str)) fcreate(str);
    new string[MAX_PLAYER_NAME+8];
    new File:file = fopen(str, io_read);
    new idx = 0;
    while(fread(file, string) && idx < 20)
    {
        sscanf(string,"s[MAX_PLAYER_NAME]s[6]", Contacts[playerid][idx], ContactsNum[playerid][idx]);
        /*new strr[128];
        format(strr,128, "Contact: %s , Number: %s, Location: %s", Contacts[playerid][idx], ContactsNum[playerid][idx], str);
        print(strr);*/

        idx++;
    }
    format(string, MAX_PLAYER_NAME+8, "");
    format(str, MAX_PLAYER_NAME+20, "");
    fclose(file);
//  print("Contacts loaded successfully.");
    return 1;
}