SA-MP Forums Archive
Fread - 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: Fread (/showthread.php?tid=486852)



Fread - ChrisYo - 10.01.2014

Hi!

I need help with "Fread" files function.

First of all I'll show You what I've got here:

pawn Код:
// OnPlayerCommandText

// Command: "/NameSearch"
ShowPlayerDialog(playerid, 1, DIALOG_STYLE_INPUT, "Name Search", "Enter the account name You wanted to see if exists or not, here:", "Search", "Cancel");

// OnDialogResponse

    // Name Search
    if(dialogid == 1 && response == 1)
    {
 
    new File:players= fopen("Players.txt", io_read);
    while(fread(players, inputtext))
    {
          /*
          I've tried everything, also ******d it billion times and nothing.
          I just need a code here which is going to say if the searched name is registered (exists) or not.
          */

    }
    fclose(players);

    }
The main scripter of the server is not able to help me now, and I really need this as soon as possible, please!
Please, anybody?


Re: Fread - Pottus - 10.01.2014

I'll give you my view on this, typically with an INI system you save the player data to file such as, [uL]Pottus.ini so really you only have to do if(fexists("filepath/[uL]Pottus.ini")) instead of what your trying to do. But I would recommend using SQLite instead of an INI system.

@Seif- Bad idea dude, your putting a bandaid on a fundamental design flaw which is worse than his first mistake.


Re: Fread - Seif- - 10.01.2014

What you need is strfind. strfind will search through a string for what you want. fread will read the file and requires a string object so it can extract line by line what it's reading.
pawn Код:
new string[MAX_PLAYER_NAME]; // If your file has each registered name in 1 line instead of having 1 per line, then change this.
    new File:players= fopen("Players.txt", io_read);
    while(fread(players, string))
    {
        if (strfind(string, inputtext, true) != -1)
        {
            // Found it
        }
    }