SA-MP Forums Archive
Retrieving one line from a player file. - 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: Retrieving one line from a player file. (/showthread.php?tid=458682)



Retrieving one line from a player file. - Binx - 18.08.2013

Hello,

I have a player file created with Y_INI, however I only want to load one line from this file. The way I want to do this is with native SAMP File Functions (Found here: https://sampwiki.blast.hk/wiki/File_Functions), however I cannot make head or tail of it.

The line I want to retrieve is: "IP = ***.***.***.***"

I do not want to parse the whole file as the player isn't going to be actively online for this function, however I also don't want to use Y_INI to parse one line of information.

I have tried attempting this myself:
pawn Код:
new File:PlayerIP = fopen(LuckyGuy, io_read);
    new string[15 + 5];
    while(fread(PlayerIP, string))
    {
        if(strcmp(string, "IP = ", true)==0)
        {
            strmid(string, string, 5, 20, 15);
        }
    }

    format(LuckyGuy, sizeof(LuckyGuy), Ban_Path, string);
    if(fremove(LuckyGuy)) return SendClientMessage(playerid, COLOR_RED, "|-- Error: Account Deletion Failed!");
As you can see here I am trying to delete a ban file using the IP from within "LuckyGuys" file, which I have set this to the correct path.

pawn Код:
format(LuckyGuy, sizeof(LuckyGuy), PATH, LuckyGuy);
This is shown here by the inital LuckyGuy result back from sccanf is being formatted into string.


Re: Retrieving one line from a player file. - Binx - 18.08.2013

Anyone?


Re: Retrieving one line from a player file. - Jefff - 18.08.2013

pawn Код:
new File:PlayerIP = fopen(LuckyGuy, io_read);
new string[MAX_PLAYER_NAME],len;
while((len = fread(PlayerIP, string)))
    if(strcmp(string, "IP = ", true)==0)
    {
        string[len-2] = 0;
        strdel(string,0,5);
        break; // stop searching
    }

fclose(PlayerIP);
format(LuckyGuy, sizeof(LuckyGuy), Ban_Path, string);
if(!fremove(LuckyGuy)) return SendClientMessage(playerid, COLOR_RED, "|-- Error: Account Deletion Failed!");



Re: Retrieving one line from a player file. - Binx - 18.08.2013

when I type their correct name, it says it's an unknown command, with the "break".


Re: Retrieving one line from a player file. - Jefff - 18.08.2013

You need type some IP and use print under every line then you will see where code stops


Re: Retrieving one line from a player file. - Binx - 18.08.2013

pawn Код:
CMD:unban(playerid, params[])
{
    new LuckyGuy[MAX_PLAYER_NAME + 6 + 4];
    if(PlayerInfo[playerid][pAdmin] <= 4) return SendClientMessage(playerid, COLOR_RED, "Error: "COL_WHITE" You're not a high enough Administrator.");
    if(sscanf(params, "s[24]", LuckyGuy)) return SendClientMessage(playerid, COLOR_RED, "Error: "COL_WHITE"/unban [Name] (Example: Jammie Dodger)");

    format(LuckyGuy, sizeof(LuckyGuy), PATH, LuckyGuy);

    if(!fexist(LuckyGuy)) return SendClientMessage(playerid, COLOR_RED, "Error: Player doesn't exist! (Tips: Don't use _ | Example Jammie Dodger)");

    new INI:File = INI_Open(LuckyGuy);
    print("File opened");
    INI_SetTag(File, "Statistics");
    print("SetTag");
    INI_WriteInt(File, "Banned", 0);
    print("Set banned");
    INI_Close(File);
    print("Closed File.");
   
    new File:PlayerIP = fopen(LuckyGuy, io_read);
    new string[16 + 7],len;
    while((len = fread(PlayerIP, string)))
    if(strcmp(string, "IP = ", true)==0)
    {
        string[len-2] = 0;
        strdel(string,0,5);
        break; // stop searching
    }

    format(LuckyGuy, sizeof(LuckyGuy), Ban_Path, string);
    if(!fremove(LuckyGuy)) return SendClientMessage(playerid, COLOR_RED, "|-- Error: Account Deletion Failed!");
    SendClientMessage(playerid, COLOR_GREEN, "Account Unbanned!");
    return 1;
}
This says Unknown command..
"/ban player name" 2 parameters? It says it's an unknown command.

E: This is the debug although it said it's an unknown command:
Код:
[19:53:48] File opened
[19:53:48] SetTag
[19:53:48] Set banned



Re: Retrieving one line from a player file. - avivelkayam - 18.08.2013

hey!

try this..

do like this:

Код:
new File:PlayerIP = fopen(LuckyGuy, io_read);
new string[50], Ip[20];
while (fread(PlayerIP, string))
{
     if(!strcmp(string, "IP = ",true, strlen("IP = ")))
     {
            strmid(Ip, string, strlen("IP = "), strlen(string) - 2);
     }
}



Re: Retrieving one line from a player file. - Ada32 - 18.08.2013

pawn Код:
new
    name[6],
    value[16];
       
new File:PlayerIP = fopen(LuckyGuy, io_read);
new string[24];
   
while(fread(PlayerIP, string))
{
    if(!sscanf(string, "P<= >", name, value))
    {
        if(!strcmp(name, "IP ="))
        {
            //code
            break;
        }
    }
}
fclose(PlayerIP);