How can i read a file and get a line from that file.
#1

Ok i am making an admin script, but i cant figure out how to read files. I want the script to read the file of a user and then if that user is an admin, it reads what level and then it either does the command or says: you need to be a certain level. i am not usinc dcmd im using strcmp no plugins or anything, can someone help?
Reply
#2

First you will need to use a file-system, that means... INI, XML DJson, whatever...
If you don't want to use a already made system, you can try that way (in this example, I will use INI system):

pawn Код:
stock GetAdminLevel(playerid)
{
    new name[64];
    GetPlayerName(playerid, name, sizeof name);
    format(name, sizeof name, "%s.ini", name);

    new File:file = fopen("file.ini", io_read), line[128];
    while(fread(file, line))
    {
        new first = strfind(line, "=", true);
        if(strcmp(line, "admin_level", true, first) == 0)
        {
            new value[32];
            strmid(value, line, first + 1, strlen(line));
            return strval(value);
        }
    }
    return 0;
}
So now we can use, e.g.:

pawn Код:
if(GetAdminLevel(playerid) < 5)
{
    return SendClientMessage(playerid, 0xFFFFFFAA, "You must be at least 5 admin level.");
}
Of course if you want to simplify the whole system, you can still choose to use an include made by someone else (in case you don't understand the example), or try to make some functions like this one above.
Reply
#3

https://sampwiki.blast.hk/wiki/File_Functions

That will show you how to read from files, but for player files in the "scriptfiles" folder, you want to use INI, which can read player files which are created if someone for example /registers on your server. I think...
Reply
#4

i have a .sav file. so how would i manage that? I still dont get how to go through with this.
Reply
#5

pawn Код:
stock GetAdminLevel(playerid)
{
    new name[64];
    GetPlayerName(playerid, name, sizeof name);
    format(name, sizeof name, "ladmin/users/%s.sav", name);

    new File:file = fopen("file.sav", io_read), line[128];
    while(fread(file, line))
    {
        new first = strfind(line, "=", true);
        if(strcmp(line, "level", true, first) == 0)
        {
            new value[32];
            strmid(value, line, first + 1, strlen(line));
            return strval(value);
        }
    }
    return 0;
}
ok when i use this the server doesnt load, so ahow can i fix it to make it load properly and read the file?
Reply
#6

ok the real reason im asking this is because, i want to make a system that reads my files located in scriptfiles/ladmin/users/, and i want to make it so when they connect they will be the color green.
Reply
#7

Look in LADMIN pwn, there should be a way to read the files.
To set a player's color:
pawn Код:
SetPlayerColor(playerid,0x00FF00FF); // that would be green.
Reply
#8

But i want it to only be for admins :S
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)