• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Pawn] how to load every user.ini in scriptfiles using YINI
#11
(2021-02-14, 09:12 AM)Kwarde Wrote: You usually don't have to include "params[]" when not using it, thus: CMD:test(playerid). That way you don't have to use pragma unused.

Runtime error 19 means the file or function is not found (as it exactly says), meaning the plugin wasn't properly loaded. Did you actually load the plugin? You might be missing some (32 bit) vcredist package.

I used to have these installed (in this order): 2010, 2010-SP1, 2012-U4, 2015



As you can see, when looping through the directory with that code, you can use variable "type" to check whether the file is a directory or a file.

If your userfiles are under "scriptfiles/users" you'd have to open that directory. Then every file would be a userfile (assuming there are no other files in it).



Here's a script I wrote some time ago for some server to convert changelog textfiles to the database during initialisation:

Code:
hook OnGameModeInit()

{

    new dir:changelog_dir = dir_open("scriptfiles/changelog");

    new list_file[15], list_type;

    

    while (dir_list(changelog_dir, list_file, list_type))

    {

        if (list_type == FM_DIR) continue;

        new find;

        if ((find = strfind(list_file, ".txt")) == -1) continue;

        strdel(list_file, find, find  4);

        new Cache:res_upper = mysql_query(dbHandle, sprintf("SELECT version FROM changelog WHERE version = '%s';", list_file));

        if (!cache_num_rows())

        {

            printf("[ ] Found new changelog %s", list_file);

            cache_delete(res_upper);

            new Cache:res = mysql_query(dbHandle, sprintf("INSERT INTO changelog (version) VALUES ('%s');", list_file));

            new new_cl_id = cache_insert_id();

            cache_delete(res);

            new File:cl_file = fopen(sprintf("changelog/%s.txt", list_file), io_read);

            if (cl_file)

            {

                new cl_entry[130], cl_lines, i;

                

                while (fread(cl_file, cl_entry)) cl_lines;

                fseek(cl_file, _, seek_start);

                

                while (fread(cl_file, cl_entry))

                {

                    new cl_query[190];

                    i;

                    if (i < cl_lines) strdel(cl_entry, strlen(cl_entry) - 1, strlen(cl_entry));

                    mysql_format(dbHandle, cl_query, sizeof(cl_query), "INSERT INTO changelog_entries (clid, entry) VALUES (%i, '%e');", new_cl_id, cl_entry);

                    mysql_query(dbHandle, cl_query, false);

                }

                printf("[OK] Changelog for %s added to database", list_file);

                fclose(cl_file);

            }

        }

        else cache_delete(res_upper);

    }

    dir_close(changelog_dir);

    return Y_HOOKS_CONTINUE_RETURN_1;

}



As you can see it scans directory scriptfiles/changelog and only opens files when they're actually a file (and not a directory) and when the end of the filename is ".txt".

You could do something similar (eg. if your userfiles are using extension .ini, you could choose to only open userfiles).



On a sidenote, I highly recommend using MySQL, especially if the SAMP server runs on Windows. If there are alot of userfiles, expect huge laggs if you are opening every userfile during runtime.

Keep in mind SAMP is single threaded, thus if you are running a code that loops through all the userfiles the script does nothing else, resulting in laggs for everyone. OnPlayerUpdate() isn't handled, chat not being updated, it does nothing untill your code is done.



seeing this code is a little bit hard to digest, therefore i decided to go with Radical's way, as it uses mysql stuff so my chances of having it to work are automatically low.



i used his way and so far it posts a name, but for some reason it replaces the player's name who first registered with the one who just registered. is it possible to make it list all names using \n or something?



and when it comes to executing commands like this:



Code:
CMD:test(playerid, params[])

{

    new File: handle = fopen("allusers.txt", io_read), nick[24],INI: file;

    new string[32], gsflevel;

    if((IsPlayerAdmin(playerid)) || PlayerInfo[playerid][AdminLevel] == 3) {

        if(sscanf(params, "i", gsflevel)) return SendClientMessage(playerid, COLOR_RED, "Syntax: /setallgsf <level>");

        if(gsflevel > 13) return SendClientMessage(playerid, COLOR_RED, "ERROR: Max GSF level is 13");

        if(gsflevel < 0) return SendClientMessage(playerid, COLOR_RED, "ERROR: Cannot set lower than 0");

        if(handle)

        {

            while(fread(handle, nick))

            {

                  format(string, 28, "scriptfiles/Users/%s.ini", nick);

                file = INI_Open(string);

                INI_SetTag(file, "=|PlayerData|=");

                INI_WriteInt(file, "GSFLevel", gsflevel);

                INI_Close(file);

             }

            fclose(handle);

        } else {

            print("The file \"allusers.txt\" does not exist, or can't be opened.");

        }

        return 1;

    } else return SendClientMessage(playerid, COLOR_RED, "ERROR: Authorization revoked.");

}



it sends this warning:
Code:
*** YSI Warning: INI_Open could not find or create file scriptfiles/Users/mems

.in



code's the same as Radical's but still imma post it:



Code:
                new File: handle = fopen("allusers.txt", io_write), Name[MAX_PLAYER_NAME];

                GetPlayerName(playerid, Name, sizeof(Name));

                format(Name, sizeof(Name), "%s\r\n", Name);

                fwrite(handle, Name);

                fclose(handle);
that's put on when a player registers
  Reply


Messages In This Thread
RE: how to load every user.ini in scriptfiles using YINI - by mems - 2021-02-14, 11:37 AM

Forum Jump: