open.mp forum
[Pawn] how to load every user.ini in scriptfiles using YINI - Printable Version

+ open.mp forum (https://forum.open.mp)
-- Forum: SA-MP (https://forum.open.mp/forumdisplay.php?fid=3)
--- Forum: Pawn Scripting (https://forum.open.mp/forumdisplay.php?fid=10)
--- Thread: [Pawn] how to load every user.ini in scriptfiles using YINI (/showthread.php?tid=1663)



how to load every user.ini in scriptfiles using YINI - mems - 2021-02-11

greetings,

title says it all i guess. i'm planning to make a command which has to do with setting levels to people who are in a specific gang the offline way. much appreciated if anyone helps!


RE: how to load every user.ini in scriptfiles using YINI - Pinch - 2021-02-11

The reason why RDBMS exists.


RE: how to load every user.ini in scriptfiles using YINI - mems - 2021-02-12

(2021-02-11, 10:39 PM)Pinch Wrote: The reason why RDBMS exists.

i want to do it with yini instead. i've read about rdbms since i don't know whats that and i've seen that it has to do with mysql, something that i don't want to try for now.


RE: how to load every user.ini in scriptfiles using YINI - Radical - 2021-02-12

Save gang members to a file.
Then load them all name through fread and set them level...

If you do not understand, see this:
Code:
new File: handle = fopen("gang_members.txt", io_read), string[28], nick[24], INI: file;

if(handle)
{
while(fread(handle, nick)) {
? ? ? ? ? ? format(string, 28, "Users/%s.ini", nick);
? ? ? ? ? ? file = INI_Open(string);
? ? ? ? ? ? INI_WriteInt(file, "p_level", 100);
? ? ? ? ? ? INI_Close(file);
? ? ? ? }
fclose(handle);
} else {
print("The file \"gang_members.txt\" does not exists, or can't be opened.");
}

// Notice : The names of the members you have saved in the file 'gang_members.txt' should be the name of each one in a new line

If you use MySQL, you can do this easily with just one query.
Code:
UPDATE `users` SET `level` = `level`  100 WHERE `gangid` = 1



RE: how to load every user.ini in scriptfiles using YINI - mems - 2021-02-12

(2021-02-12, 08:57 PM)Radical Wrote: Save gang members to a file.

Then load them all name through fread and set them level...



If you do not understand, see this:

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



if(handle)

{

while(fread(handle, nick)) {

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

? ? ? ? ? ? file = INI_Open(string);

? ? ? ? ? ? INI_WriteInt(file, "p_level", 100);

? ? ? ? ? ? INI_Close(file);

? ? ? ? }

fclose(handle);

} else {

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

}



// Notice : The names of the members you have saved in the file 'gang_members.txt' should be the name of each one in a new line



If you use MySQL, you can do this easily with just one query.

Code:
UPDATE `users` SET `level` = `level`  100 WHERE `gangid` = 1



i guess i should've elaborated a bit on the gang part. that gang thing is made out of just commands, like "/gangmembers" or "/setganglevel" simple stuff. what you're doing is actually close but i'd like an example which has to do with loading every account from the scriptfiles folder. i could elaborate more on the scriptfiles part if you don't understand.


RE: how to load every user.ini in scriptfiles using YINI - Radical - 2021-02-13

(2021-02-12, 10:04 PM)mems Wrote: i guess i should've elaborated a bit on the gang part. that gang thing is made out of just commands, like "/gangmembers" or "/setganglevel" simple stuff. what you're doing is actually close but i'd like an example which has to do with loading every account from the scriptfiles folder. i could elaborate more on the scriptfiles part if you don't understand.

To do this we need the readdir() (Read a Directory) function that does not exist in the SA-MP library.

But I still have a way for you to do it. look:

When a new player registered,?add him name to the 'allusers.txt' file.
Code:
new File: handle = fopen("allusers.txt", io_write), Name[28];
GetPlayerName(playerid, Name, 24);
format(Name, 28, "%s\r\n", Name);
fwrite(handle, Name);
fclose(handle);

Now with the previous code I gave, like that, you can load all the players data or you can set or give?all players level or something.
Code:
new File: handle = fopen("allusers.txt", io_read), nick[24];

if(handle)
{
while(fread(handle, nick)) {
? ? ? ? ? ? // things ...
? ? ? ? }
fclose(handle);
} else {
print("The file \"allusers.txt\" does not exists, or can't be opened.");
}

I hope it works for you.


RE: how to load every user.ini in scriptfiles using YINI - mems - 2021-02-13

(2021-02-13, 12:53 AM)Radical Wrote:
(2021-02-12, 10:04 PM)mems Wrote: i guess i should've elaborated a bit on the gang part. that gang thing is made out of just commands, like "/gangmembers" or "/setganglevel" simple stuff. what you're doing is actually close but i'd like an example which has to do with loading every account from the scriptfiles folder. i could elaborate more on the scriptfiles part if you don't understand.



To do this we need the readdir() (Read a Directory) function that does not exist in the SA-MP library.



But I still have a way for you to do it. look:



When a new player registered,?add him name to the 'allusers.txt' file.

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

GetPlayerName(playerid, Name, 24);

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

fwrite(handle, Name);

fclose(handle);



Now with the previous code I gave, like that, you can load all the players data or you can set or give?all players level or something.

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



if(handle)

{

while(fread(handle, nick)) {

? ? ? ? ? ? // things ...

? ? ? ? }

fclose(handle);

} else {

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

}



I hope it works for you.



mind also showing me that readdir way?


RE: how to load every user.ini in scriptfiles using YINI - Kwarde - 2021-02-13

You can use FileManager for that: https://github.com/JaTochNietDan/SA-MP-FileManager

There is already an example on the Github page that shows you how to read files in a directory.


RE: how to load every user.ini in scriptfiles using YINI - mems - 2021-02-13

(2021-02-13, 06:56 AM)Kwarde Wrote: You can use FileManager for that: https://github.com/JaTochNietDan/SA-MP-FileManager

There is already an example on the Github page that shows you how to read files in a directory.



sorry for such a late reply. is there a way to read every user's file though ? if so, could you give any examples ?



edit: i tried it and my server won't load up. here's the error:
Code:
[jit] Compilation was disabled

Script[gamemodes/fps.amx]: Run time error 19: "File or function is not found"

Number of vehicle models: 173



i used that code example to see what it looks like:
Code:
CMD:test(playerid, params[])

{

    #pragma unused params

    new dir:dHandle = dir_open("./");

    new item[40], type;



    while(dir_list(dHandle, item, type))

    {

        if(type == FM_FILE) printf("%s is a file", item);

        else if(type == FM_DIR) printf("%s is a directory", item);

    }



    dir_close(dHandle);

}

and i also included filemanager.


RE: how to load every user.ini in scriptfiles using YINI - Kwarde - 2021-02-14

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.


RE: how to load every user.ini in scriptfiles using YINI - mems - 2021-02-14

(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


RE: how to load every user.ini in scriptfiles using YINI - Kwarde - 2021-02-14

Cannot open or create file:

===

scriptfiles/Users/mems

.in

===

Seems it is read as "scriptfiles/Users/mems\n.in"



While reading your code just now:

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

Length of "scriptfiles/Users/.ini" is 22. Max player's name length is 24. 22 = 46. You're formatting with maxlength 28. It checks out:

"scriptfiles/Users/mems\n.in" is 27 characters.



When reading an entire line in a file it includes characters such as "new line" and "reset carrier". In this case, "mems" is actually "mems\r\n"



You've gotta make sure:

- The array you hold the file location in can hold all the data

- y_ini is relative to ./scriptfiles -- So when trying to open "scriptfiles/somefile.txt" it actually tries to open (relative to your samp executable file): scriptfiles/scriptfiles/somefile.txt -- You only can access below scriptfiles through plugins (like with FileManager)

^- when that's fixed you no longer actually need to focus on the first point

- You remove characters \r and \n

- Don't run that command in a production environment (live server) when there's alot of user account files.


RE: how to load every user.ini in scriptfiles using YINI - mems - 2021-02-14

(2021-02-14, 11:57 AM)Kwarde Wrote: Cannot open or create file:

===

scriptfiles/Users/mems

.in

===

Seems it is read as "scriptfiles/Users/mems\n.in"



While reading your code just now:

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

Length of "scriptfiles/Users/.ini" is 22. Max player's name length is 24. 22 = 46. You're formatting with maxlength 28. It checks out:

"scriptfiles/Users/mems\n.in" is 27 characters.



When reading an entire line in a file it includes characters such as "new line" and "reset carrier". In this case, "mems" is actually "mems\r\n"



You've gotta make sure:

- The array you hold the file location in can hold all the data

- y_ini is relative to ./scriptfiles -- So when trying to open "scriptfiles/somefile.txt" it actually tries to open (relative to your samp executable file): scriptfiles/scriptfiles/somefile.txt -- You only can access below scriptfiles through plugins (like with FileManager)

^- when that's fixed you no longer actually need to focus on the first point

- You remove characters \r and \n

- Don't run that command in a production environment (live server) when there's alot of user account files.



i fixed the length of the string so that `.in` thing becomes `.ini` and now almost everything is working fine, with 2 more problems to solve.



1. i removed these \r and \n characters you told me to, but it still did not work.

2. not really a problem, more like a question. is it possible to make if statements when scanning for specific stuff?


RE: how to load every user.ini in scriptfiles using YINI - Kwarde - 2021-02-14

Why is it still not working? What do the logs say?

As for the question, what kind of specific stuff are you talking about? (The answer is yes anyway)


RE: how to load every user.ini in scriptfiles using YINI - mems - 2021-02-14

(2021-02-14, 12:19 PM)Kwarde Wrote: Why is it still not working? What do the logs say?

As for the question, what kind of specific stuff are you talking about? (The answer is yes anyway)



to clarify stuff here, the command works normally as expected to, but the file "allusers.txt" doesn't list players, instead replaces them. it's like this:



Code:
mems



if someone registers as mems1:



Code:
mems1



and not
Code:
mems

mems1



the specific stuff im talking about have to do with checking if from every user they have a specific gang level. in this case, it's:
Code:
GSFLevel
so i need to somehow make that if statement before continuing the level change procedure.


RE: how to load every user.ini in scriptfiles using YINI - Kwarde - 2021-02-14

Ah I see. You used filemode io_write. io_write clears the entire file before writing to it. You'll need io_append. https://open.mp/nl/docs/scripting/functions/fopen



As for checking GSFLevel, just load that value using y_ini to a temporary (read: local) variable and do your if check there?


RE: how to load every user.ini in scriptfiles using YINI - mems - 2021-02-14

(2021-02-14, 01:53 PM)Kwarde Wrote: Ah I see. You used filemode io_write. io_write clears the entire file before writing to it. You'll need io_append. https://open.mp/nl/docs/scripting/functions/fopen



As for checking GSFLevel, just load that value using y_ini to a temporary (read: local) variable and do your if check there?



i don't know but this reminds me of that function someone made on the samp forum



Code:
forward LoadPlayerBan(tag[], name[], value[]);

public LoadPlayerBan(tag[], name[], value[])

{

    if(!strcmp("=|PlayerData|=", tag))

    INI_Int("Banned", BanInfo);

    return 1;

}
is this even close?


RE: how to load every user.ini in scriptfiles using YINI - Radical - 2021-02-14

(2021-02-14, 01:02 PM)mems Wrote:
(2021-02-14, 12:19 PM)Kwarde Wrote: Why is it still not working? What do the logs say?

As for the question, what kind of specific stuff are you talking about? (The answer is yes anyway)



to clarify stuff here, the command works normally as expected to, but the file "allusers.txt" doesn't list players, instead replaces them. it's like this:



Code:
mems



if someone registers as mems1:



Code:
mems1



and not
Code:
mems

mems1



the specific stuff im talking about have to do with checking if from every user they have a specific gang level. in this case, it's:
Code:
GSFLevel
so i need to somehow make that if statement before continuing the level change procedure.



Try this:

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

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

? ? ? ? ? ? ? ? strcat(Name,?"\r\n");

? ? ? ? ? ? ? ? fwrite(handle, Name);

? ? ? ? ? ? ? ? fclose(handle);



RE: how to load every user.ini in scriptfiles using YINI - mems - 2021-02-14

(2021-02-14, 02:03 PM)Radical Wrote:
(2021-02-14, 01:02 PM)mems Wrote:
(2021-02-14, 12:19 PM)Kwarde Wrote: Why is it still not working? What do the logs say?
As for the question, what kind of specific stuff are you talking about? (The answer is yes anyway)

to clarify stuff here, the command works normally as expected to, but the file "allusers.txt" doesn't list players, instead replaces them. it's like this:

Code:
mems

if someone registers as mems1:

Code:
mems1

and not
Code:
mems
mems1

the specific stuff im talking about have to do with checking if from every user they have a specific gang level. in this case, it's:
Code:
GSFLevel
so i need to somehow make that if statement before continuing the level change procedure.

Try this:
Code:
new File: handle = fopen("allusers.txt",?io_append), Name[MAX_PLAYER_NAME];
? ? ? ? ? ? ? ? GetPlayerName(playerid, Name, sizeof(Name));
? ? ? ? ? ? ? ? strcat(Name,?"\r\n");
? ? ? ? ? ? ? ? fwrite(handle, Name);
? ? ? ? ? ? ? ? fclose(handle);

thank you, that worked

edit: for some reason this error kicks in again:

Code:
*** YSI Warning: INI_Open could not find or create file Users/mems
.ini
*** YSI Warning: INI_Open could not find or create file Users/mems1
.ini



RE: how to load every user.ini in scriptfiles using YINI - Kwarde - 2021-02-14

There's still a new line between "username" and ".ini"


RE: how to load every user.ini in scriptfiles using YINI - mems - 2021-02-14

(2021-02-14, 02:38 PM)Kwarde Wrote: There's still a new line between "username" and ".ini"



what do you mean exactly? and in which code?


RE: how to load every user.ini in scriptfiles using YINI - Radical - 2021-02-14

(2021-02-14, 02:47 PM)mems Wrote:
(2021-02-14, 02:38 PM)Kwarde Wrote: There's still a new line between "username" and ".ini"



what do you mean exactly? and in which code?







PHP Code:
CMD:test(playeridparams[])

{

? ? new 
Filehandle fopen("allusers.txt"io_read), nick[24],INIfile;

? ? new 
string[46], gsflevel;

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

? ? ? ? if(
sscanf(params"i"gsflevel)) return SendClientMessage(playeridCOLOR_RED"Syntax: /setallgsf <level>");

? ? ? ? if(
gsflevel 13) return SendClientMessage(playeridCOLOR_RED"ERROR: Max GSF level is 13");

? ? ? ? if(
gsflevel 0) return SendClientMessage(playeridCOLOR_RED"ERROR: Cannot set lower than 0");

? ? ? ? if(
handle)

? ? ? ? {

? ? ? ? ? ? while(
fread(handlenick))

? ? ? ? ? ? {

? ? ? ? ? ? ? ? ? 
StripNewLine(nick);

? ? ? ? ? ? ? ? ? 
format(string46"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(playeridCOLOR_RED"ERROR: Authorization revoked.");





PHP Code:
/** BY DRACOBLUE

*? Strips Newline from the end of a string.

*? Idea: Y_Less, Bugfixing (when length=1) by DracoBlue

*? @param? string

*/

stock StripNewLine(string[])

{

new 
len strlen(string);

if (
string[0]==0) return ;

if ((
string[len 1] == '\n') || (string[len 1] == '\r')) {

string[len 1] = 0;

if (
string[0]==0) return ;

if ((
string[len 2] == '\n') || (string[len 2] == '\r')) string[len 2] = 0;

}





RE: how to load every user.ini in scriptfiles using YINI - mems - 2021-02-14

(2021-02-14, 05:50 PM)Radical Wrote:
(2021-02-14, 02:47 PM)mems Wrote:
(2021-02-14, 02:38 PM)Kwarde Wrote: There's still a new line between "username" and ".ini"



what do you mean exactly? and in which code?







PHP Code:
CMD:test(playeridparams[])

{

? ? new 
Filehandle fopen("allusers.txt"io_read), nick[24],INIfile;

? ? new 
string[46], gsflevel;

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

? ? ? ? if(
sscanf(params"i"gsflevel)) return SendClientMessage(playeridCOLOR_RED"Syntax: /setallgsf <level>");

? ? ? ? if(
gsflevel 13) return SendClientMessage(playeridCOLOR_RED"ERROR: Max GSF level is 13");

? ? ? ? if(
gsflevel 0) return SendClientMessage(playeridCOLOR_RED"ERROR: Cannot set lower than 0");

? ? ? ? if(
handle)

? ? ? ? {

? ? ? ? ? ? while(
fread(handlenick))

? ? ? ? ? ? {

? ? ? ? ? ? ? ? ? 
StripNewLine(nick);

? ? ? ? ? ? ? ? ? 
format(string46"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(playeridCOLOR_RED"ERROR: Authorization revoked.");





PHP Code:
/** BY DRACOBLUE

*? Strips Newline from the end of a string.

*? Idea: Y_Less, Bugfixing (when length=1) by DracoBlue

*? @param? string

*/

stock StripNewLine(string[])

{

new 
len strlen(string);

if (
string[0]==0) return ;

if ((
string[len 1] == '\n') || (string[len 1] == '\r')) {

string[len 1] = 0;

if (
string[0]==0) return ;

if ((
string[len 2] == '\n') || (string[len 2] == '\r')) string[len 2] = 0;

}





thank you, that worked x2, it wouldn't work tho because you included "scriptfiles", so i removed it and now it works x3. if possible, could you explain me what you did so in the future if i ever come across this again i won't have any problems using that?


RE: how to load every user.ini in scriptfiles using YINI - mems - 2021-02-14

btw, is there any way to make those if statements ? i've tried myself but it wouldn't work:



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

{

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

    new string[192], fstring[46], pname[MAX_PLAYER_NAME], gsflevel;

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

        if(sscanf(params, "i", gsflevel)) return SendClientMessage(playerid, COLOR_RED, "Syntax: /osetallgsf <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(fstring, 46, "Users/%s.ini", nick);

                if(INI_ParseFile(fstring, "LoadGSFLevel", .bPassTag = true)) {

                    if(GSFLevelInfo >= 1) {

                        GetPlayerName(playerid, pname, sizeof(pname));

                        format(string, sizeof(string), "[STAFF]: \"%s\" has issued the command: {FF0000}OSETALLGSF{00FFFF}.", pname);

                        SendToRCON(COLOR_AQUA, string);

                        format(string, sizeof(string), "[{FF0000}GSF{FFFFFF}]: Successfully offline set {FF0000}%s's{FFFFFF} GSF level to: %i.", nick, gsflevel);

                        SendClientMessage(playerid, COLOR_WHITE, string);

                        StripNewLine(nick);

                        file = INI_Open(fstring);

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

                        INI_WriteInt(file, "GSFLevel", gsflevel);

                        INI_Close(file);

                    } else return SendClientMessage(playerid, COLOR_RED, "ERROR: No account was found having a GSF level.");

                }

            }

            fclose(handle);

        } else return SendClientMessage(playerid, COLOR_RED, "ERROR: The file \"allusers.txt\" does not exist, therefore canceling the process.");

        return 1;

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

}



and the function that i used:



Code:
forward LoadGSFLevel(tag[], name[], value[]);

public LoadGSFLevel(tag[], name[], value[])

{

    if(!strcmp("=|PlayerData|=", tag))

    INI_Int("GSFLevel", GSFLevelInfo);

    return 1;

}



RE: how to load every user.ini in scriptfiles using YINI - Radical - 2021-02-14

(2021-02-14, 08:01 PM)mems Wrote: btw, is there any way to make those if statements ? i've tried myself but it wouldn't work:



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

{

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

? ? new string[192], fstring[46], pname[MAX_PLAYER_NAME], gsflevel;

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

? ? ? ? if(sscanf(params, "i", gsflevel)) return SendClientMessage(playerid, COLOR_RED, "Syntax: /osetallgsf <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(fstring, 46, "Users/%s.ini", nick);

? ? ? ? ? ? if(INI_ParseFile(fstring, "LoadGSFLevel", .bPassTag = true)) {

? ? ? ? ? ? if(GSFLevelInfo >= 1) {

GetPlayerName(playerid, pname, sizeof(pname));

? ? ? ? ? ? ? ? format(string, sizeof(string), "[STAFF]: \"%s\" has issued the command: {FF0000}OSETALLGSF{00FFFF}.", pname);

? ? ? ? ? ? ? ? SendToRCON(COLOR_AQUA, string);

? ? ? ? ? ? ? ? format(string, sizeof(string), "[{FF0000}GSF{FFFFFF}]: Successfully offline set {FF0000}%s's{FFFFFF} GSF level to: %i.", nick, gsflevel);

? ? ? ? ? ? ? ? SendClientMessage(playerid, COLOR_WHITE, string);

? ? ? ? ? ? ? ? StripNewLine(nick);

? ? ? ? ? ? ? ? file = INI_Open(fstring);

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

? ? ? ? ? ? ? ? INI_WriteInt(file, "GSFLevel", gsflevel);

? ? ? ? ? ? ? ? INI_Close(file);

? ? ? ? ? ? } else return SendClientMessage(playerid, COLOR_RED, "ERROR: No account was found having a GSF level.");

}

? ? ? ? ? ? }

? ? ? ? ? ? fclose(handle);

? ? ? ? } else return SendClientMessage(playerid, COLOR_RED, "ERROR: The file \"allusers.txt\" does not exist, therefore canceling the process.");

? ? ? ? return 1;

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

}



and the function that i used:



Code:
forward LoadGSFLevel(tag[], name[], value[]);

public LoadGSFLevel(tag[], name[], value[])

{

? ? if(!strcmp("=|PlayerData|=", tag))

? ? INI_Int("GSFLevel", GSFLevelInfo);

? ? return 1;

}

Sorry I didn't understand what you want to do. Explain more


RE: how to load every user.ini in scriptfiles using YINI - mems - 2021-02-14

(2021-02-14, 08:30 PM)Radical Wrote:
(2021-02-14, 08:01 PM)mems Wrote: btw, is there any way to make those if statements ? i've tried myself but it wouldn't work:



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

{

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

? ? new string[192], fstring[46], pname[MAX_PLAYER_NAME], gsflevel;

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

? ? ? ? if(sscanf(params, "i", gsflevel)) return SendClientMessage(playerid, COLOR_RED, "Syntax: /osetallgsf <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(fstring, 46, "Users/%s.ini", nick);

? ? ? ? ? ? if(INI_ParseFile(fstring, "LoadGSFLevel", .bPassTag = true)) {

? ? ? ? ? ? if(GSFLevelInfo >= 1) {

GetPlayerName(playerid, pname, sizeof(pname));

? ? ? ? ? ? ? ? format(string, sizeof(string), "[STAFF]: \"%s\" has issued the command: {FF0000}OSETALLGSF{00FFFF}.", pname);

? ? ? ? ? ? ? ? SendToRCON(COLOR_AQUA, string);

? ? ? ? ? ? ? ? format(string, sizeof(string), "[{FF0000}GSF{FFFFFF}]: Successfully offline set {FF0000}%s's{FFFFFF} GSF level to: %i.", nick, gsflevel);

? ? ? ? ? ? ? ? SendClientMessage(playerid, COLOR_WHITE, string);

? ? ? ? ? ? ? ? StripNewLine(nick);

? ? ? ? ? ? ? ? file = INI_Open(fstring);

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

? ? ? ? ? ? ? ? INI_WriteInt(file, "GSFLevel", gsflevel);

? ? ? ? ? ? ? ? INI_Close(file);

? ? ? ? ? ? } else return SendClientMessage(playerid, COLOR_RED, "ERROR: No account was found having a GSF level.");

}

? ? ? ? ? ? }

? ? ? ? ? ? fclose(handle);

? ? ? ? } else return SendClientMessage(playerid, COLOR_RED, "ERROR: The file \"allusers.txt\" does not exist, therefore canceling the process.");

? ? ? ? return 1;

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

}



and the function that i used:



Code:
forward LoadGSFLevel(tag[], name[], value[]);

public LoadGSFLevel(tag[], name[], value[])

{

? ? if(!strcmp("=|PlayerData|=", tag))

? ? INI_Int("GSFLevel", GSFLevelInfo);

? ? return 1;

}

Sorry I didn't understand what you want to do. Explain more



i want to make if statements to check if those users have a specific GSF level in order to continue the procedure of setting them the level the player wishes to


RE: how to load every user.ini in scriptfiles using YINI - mems - 2021-02-15

umm if you still don't get it:



a way must be found to make this code



Code:
if(PlayerInfo[playerid][GSFLevel] >= 1) {



but the offline version and for every user file


RE: how to load every user.ini in scriptfiles using YINI - Radical - 2021-02-15

Try this:

PHP Code:
CMD:osetallgsf(playeridparams[])

{

? ? new 
gsflevel;

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

? ? ? ? if(
sscanf(params"i"gsflevel)) return SendClientMessage(playeridCOLOR_RED"Syntax: /osetallgsf <level>");

? ? ? ? if(
gsflevel 13) return SendClientMessage(playeridCOLOR_RED"ERROR: Max GSF level is 13");

? ? ? ? if(
gsflevel 0) return SendClientMessage(playeridCOLOR_RED"ERROR: Cannot set lower than 0");

? ? ? ? new 
Filehandle fopen("allusers.txt"io_read), nick[MAX_PLAYER_NAME], INIfilestring[192], fstring[46], pname[MAX_PLAYER_NAME];

? ? ? ? 
GetPlayerName(playeridpnamesizeof(pname));

? ? ? ? if(
handle)

? ? ? ? {

? ? ? ? ? ? while(
fread(handlenick))

? ? ? ? ? ? {

? ? ? ? ? ? ? ? 
StripNewLine(nick);

? ? ? ? ? ? ? ? 

? ? ? ? ? ? ? ? 
format(fstring46"Users/%s.ini"nick);

? ? ? ? ? ? if(
INI_ParseFile(fstring"LoadGSFLevel", .bPassTag true)) {

? ? ? ? ? ? if(
GSFLevelInfo >= 1) {

? ? ? ? ? ? ? ? 
format(stringsizeof(string), "[STAFF]: \"%s\" has issued the command: {FF0000}OSETALLGSF{00FFFF}."pname);

? ? ? ? ? ? ? ? 
SendToRCON(COLOR_AQUAstring);

? ? ? ? ? ? ? ? 
format(stringsizeof(string), "[{FF0000}GSF{FFFFFF}]: Successfully offline set {FF0000}%s's{FFFFFF} GSF level to: %i."nickgsflevel);

? ? ? ? ? ? ? ? 
SendClientMessage(playeridCOLOR_WHITEstring);

? ? ? ? ? ? ? ? 
file INI_Open(fstring);

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

? ? ? ? ? ? ? ? 
INI_WriteInt(file"GSFLevel"gsflevel);

? ? ? ? ? ? ? ? 
INI_Close(file);

? ? ? ? ? ? } else return 
SendClientMessage(playeridCOLOR_RED"ERROR: No account was found having a GSF level.");

}

? ? ? ? ? ? }

? ? ? ? ? ? 
fclose(handle);

? ? ? ? } else return 
SendClientMessage(playeridCOLOR_RED"ERROR: The file \"allusers.txt\" does not exist, therefore canceling the process.");

? ? ? ? return 
1;

? ? } else return 
SendClientMessage(playeridCOLOR_RED"ERROR: Authorization revoked.");





RE: how to load every user.ini in scriptfiles using YINI - mems - 2021-02-15

(2021-02-15, 09:32 PM)Radical Wrote: Try this:
PHP Code:
CMD:osetallgsf(playeridparams[])
{
? ? new 
gsflevel;
? ? if((
IsPlayerAdmin(playerid)) || PlayerInfo[playerid][AdminLevel] == 3) {
? ? ? ? if(
sscanf(params"i"gsflevel)) return SendClientMessage(playeridCOLOR_RED"Syntax: /osetallgsf <level>");
? ? ? ? if(
gsflevel 13) return SendClientMessage(playeridCOLOR_RED"ERROR: Max GSF level is 13");
? ? ? ? if(
gsflevel 0) return SendClientMessage(playeridCOLOR_RED"ERROR: Cannot set lower than 0");
? ? ? ? new 
Filehandle fopen("allusers.txt"io_read), nick[MAX_PLAYER_NAME], INIfilestring[192], fstring[46], pname[MAX_PLAYER_NAME];
? ? ? ? 
GetPlayerName(playeridpnamesizeof(pname));
? ? ? ? if(
handle)
? ? ? ? {
? ? ? ? ? ? while(
fread(handlenick))
? ? ? ? ? ? {
? ? ? ? ? ? ? ? 
StripNewLine(nick);
? ? ? ? ? ? ? ? 
? ? ? ? ? ? ? ? 
format(fstring46"Users/%s.ini"nick);
? ? ? ? ? ? if(
INI_ParseFile(fstring"LoadGSFLevel", .bPassTag true)) {
? ? ? ? ? ? if(
GSFLevelInfo >= 1) {
? ? ? ? ? ? ? ? 
format(stringsizeof(string), "[STAFF]: \"%s\" has issued the command: {FF0000}OSETALLGSF{00FFFF}."pname);
? ? ? ? ? ? ? ? 
SendToRCON(COLOR_AQUAstring);
? ? ? ? ? ? ? ? 
format(stringsizeof(string), "[{FF0000}GSF{FFFFFF}]: Successfully offline set {FF0000}%s's{FFFFFF} GSF level to: %i."nickgsflevel);
? ? ? ? ? ? ? ? 
SendClientMessage(playeridCOLOR_WHITEstring);
? ? ? ? ? ? ? ? 
file INI_Open(fstring);
? ? ? ? ? ? ? ? 
INI_SetTag(file"=|PlayerData|=");
? ? ? ? ? ? ? ? 
INI_WriteInt(file"GSFLevel"gsflevel);
? ? ? ? ? ? ? ? 
INI_Close(file);
? ? ? ? ? ? } else return 
SendClientMessage(playeridCOLOR_RED"ERROR: No account was found having a GSF level.");
}
? ? ? ? ? ? }
? ? ? ? ? ? 
fclose(handle);
? ? ? ? } else return 
SendClientMessage(playeridCOLOR_RED"ERROR: The file \"allusers.txt\" does not exist, therefore canceling the process.");
? ? ? ? return 
1;
? ? } else return 
SendClientMessage(playeridCOLOR_RED"ERROR: Authorization revoked.");


this code worked but if it checked one player who didnt have a level it would stop so i made this code. however a message isn't sent when gsflevel isn't >= 1 or if player's online:

PHP Code:
CMD:osetallgsf(playeridparams[])
{
    new 
Filehandle fopen("allusers.txt"io_read), nick[MAX_PLAYER_NAME], INIfile;
    new 
string[192], fstring[46], pname[MAX_PLAYER_NAME], gsflevel;
    
GetPlayerName(playeridpnamesizeof(pname));
    if((
IsPlayerAdmin(playerid)) || PlayerInfo[playerid][AdminLevel] == 3) {
        if(
sscanf(params"i"gsflevel)) return SendClientMessage(playeridCOLOR_RED"Syntax: /osetallgsf <level>");
        if(
gsflevel 13) return SendClientMessage(playeridCOLOR_RED"ERROR: Max GSF level is 13");
        if(
gsflevel 0) return SendClientMessage(playeridCOLOR_RED"ERROR: Cannot set lower than 0");
        if(
handle)
        {
            while(
fread(handlenick))
            {
                
StripNewLine(nick);
                
format(fstring46"Users/%s.ini"nick);
                if(
INI_ParseFile(fstring"LoadGSFLevel", .bPassTag true)) {
                    if(
onlineinfo || !GSFLevelInfo) continue;
                    if(
GSFLevelInfo >= && !onlineinfo) {
                        
format(stringsizeof(string), "[STAFF]: \"%s\" has issued the command: {FF0000}OSETALLGSF{00FFFF}."pname);
                        
SendToRCON(COLOR_AQUAstring);
                        
format(stringsizeof(string), "[{FF0000}GSF{FFFFFF}]: Successfully offline set {FF0000}%s's{FFFFFF} GSF level to: %i."nickgsflevel);
                        
SendClientMessage(playeridCOLOR_WHITEstring);
                        
file INI_Open(fstring);
                        
INI_SetTag(file"=|PlayerData|=");
                        
INI_WriteInt(file"GSFLevel"gsflevel);
                        
INI_Close(file);
                    } else return 
SendClientMessage(playeridCOLOR_RED"ERROR: No account was found having a GSF level.");
                }
            }
            
fclose(handle);
        } else return 
SendClientMessage(playeridCOLOR_RED"ERROR: The file \"allusers.txt\" does not exist, therefore canceling the process.");
        return 
1;
    } else return 
SendClientMessage(playeridCOLOR_RED"ERROR: Authorization revoked.");


and i have one question, is it possible to make this
Code:
            format(string, sizeof(string), "[STAFF]: \"%s\" has issued the command: {FF0000}OSETALLGSF{00FFFF}.", pname);
                        SendToRCON(COLOR_AQUA, string);
be sent only once even tho it's inside the loop ?


RE: how to load every user.ini in scriptfiles using YINI - Radical - 2021-02-15

(2021-02-15, 11:07 PM)mems Wrote:
(2021-02-15, 09:32 PM)Radical Wrote: Try this:

PHP Code:
CMD:osetallgsf(playeridparams[])

{

? ? new 
gsflevel;

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

? ? ? ? if(
sscanf(params"i"gsflevel)) return SendClientMessage(playeridCOLOR_RED"Syntax: /osetallgsf <level>");

? ? ? ? if(
gsflevel 13) return SendClientMessage(playeridCOLOR_RED"ERROR: Max GSF level is 13");

? ? ? ? if(
gsflevel 0) return SendClientMessage(playeridCOLOR_RED"ERROR: Cannot set lower than 0");

? ? ? ? new 
Filehandle fopen("allusers.txt"io_read), nick[MAX_PLAYER_NAME], INIfilestring[192], fstring[46], pname[MAX_PLAYER_NAME];

? ? ? ? 
GetPlayerName(playeridpnamesizeof(pname));

? ? ? ? if(
handle)

? ? ? ? {

? ? ? ? ? ? while(
fread(handlenick))

? ? ? ? ? ? {

? ? ? ? ? ? ? ? 
StripNewLine(nick);

? ? ? ? ? ? ? ? 

? ? ? ? ? ? ? ? 
format(fstring46"Users/%s.ini"nick);

? ? ? ? ? ? if(
INI_ParseFile(fstring"LoadGSFLevel", .bPassTag true)) {

? ? ? ? ? ? if(
GSFLevelInfo >= 1) {

? ? ? ? ? ? ? ? 
format(stringsizeof(string), "[STAFF]: \"%s\" has issued the command: {FF0000}OSETALLGSF{00FFFF}."pname);

? ? ? ? ? ? ? ? 
SendToRCON(COLOR_AQUAstring);

? ? ? ? ? ? ? ? 
format(stringsizeof(string), "[{FF0000}GSF{FFFFFF}]: Successfully offline set {FF0000}%s's{FFFFFF} GSF level to: %i."nickgsflevel);

? ? ? ? ? ? ? ? 
SendClientMessage(playeridCOLOR_WHITEstring);

? ? ? ? ? ? ? ? 
file INI_Open(fstring);

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

? ? ? ? ? ? ? ? 
INI_WriteInt(file"GSFLevel"gsflevel);

? ? ? ? ? ? ? ? 
INI_Close(file);

? ? ? ? ? ? } else return 
SendClientMessage(playeridCOLOR_RED"ERROR: No account was found having a GSF level.");

}

? ? ? ? ? ? }

? ? ? ? ? ? 
fclose(handle);

? ? ? ? } else return 
SendClientMessage(playeridCOLOR_RED"ERROR: The file \"allusers.txt\" does not exist, therefore canceling the process.");

? ? ? ? return 
1;

? ? } else return 
SendClientMessage(playeridCOLOR_RED"ERROR: Authorization revoked.");





this code worked but if it checked one player who didnt have a level it would stop so i made this code. however a message isn't sent when gsflevel isn't >= 1 or if player's online:



PHP Code:
CMD:osetallgsf(playeridparams[])

{

? ? new 
Filehandle fopen("allusers.txt"io_read), nick[MAX_PLAYER_NAME], INIfile;

? ? new 
string[192], fstring[46], pname[MAX_PLAYER_NAME], gsflevel;

? ? 
GetPlayerName(playeridpnamesizeof(pname));

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

? ? ? ? if(
sscanf(params"i"gsflevel)) return SendClientMessage(playeridCOLOR_RED"Syntax: /osetallgsf <level>");

? ? ? ? if(
gsflevel 13) return SendClientMessage(playeridCOLOR_RED"ERROR: Max GSF level is 13");

? ? ? ? if(
gsflevel 0) return SendClientMessage(playeridCOLOR_RED"ERROR: Cannot set lower than 0");

? ? ? ? if(
handle)

? ? ? ? {

? ? ? ? ? ? while(
fread(handlenick))

? ? ? ? ? ? {

? ? ? ? ? ? ? ? 
StripNewLine(nick);

? ? ? ? ? ? ? ? 
format(fstring46"Users/%s.ini"nick);

? ? ? ? ? ? if(
INI_ParseFile(fstring"LoadGSFLevel", .bPassTag true)) {

? ? ? ? ? ? ? ? if(
onlineinfo || !GSFLevelInfo) continue;

? ? ? ? ? ? if(
GSFLevelInfo >= && !onlineinfo) {

? ? ? ? ? ? 
format(stringsizeof(string), "[STAFF]: \"%s\" has issued the command: {FF0000}OSETALLGSF{00FFFF}."pname);

? ? ? ? 
SendToRCON(COLOR_AQUAstring);

? ? ? ? ? ? ? ? 
format(stringsizeof(string), "[{FF0000}GSF{FFFFFF}]: Successfully offline set {FF0000}%s's{FFFFFF} GSF level to: %i."nickgsflevel);

? ? ? ? ? ? ? ? 
SendClientMessage(playeridCOLOR_WHITEstring);

? ? ? ? ? ? ? ? 
file INI_Open(fstring);

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

? ? ? ? ? ? ? ? 
INI_WriteInt(file"GSFLevel"gsflevel);

? ? ? ? ? ? ? ? 
INI_Close(file);

? ? ? ? ? ? } else return 
SendClientMessage(playeridCOLOR_RED"ERROR: No account was found having a GSF level.");

}

? ? ? ? ? ? }

? ? ? ? ? ? 
fclose(handle);

? ? ? ? } else return 
SendClientMessage(playeridCOLOR_RED"ERROR: The file \"allusers.txt\" does not exist, therefore canceling the process.");

? ? ? ? return 
1;

? ? } else return 
SendClientMessage(playeridCOLOR_RED"ERROR: Authorization revoked.");





you should remove return statement in loop?because it stops the loop.



(2021-02-15, 11:07 PM)mems Wrote:

and i have one question, is it possible to make this
Code:
? ? ? ? ? ? format(string, sizeof(string), "[STAFF]: \"%s\" has issued the command: {FF0000}OSETALLGSF{00FFFF}.", pname);

? ? ? ? SendToRCON(COLOR_AQUA, string);
be sent only once even tho it's inside the loop ?



Put it outside the loop.


RE: how to load every user.ini in scriptfiles using YINI - Kwarde - 2021-02-16

Quote:you should remove return statement in loop because it stops the loop.
Not just the loop, though. Allow me to add this information for mems:
- "continue" stops the current iteration of the loop and goes to the next iteration (iteration is the right word, right?)
- "break" stops the current iteration and does not go to the next one: "break"ing the loop
- "return" stops the execution of the entire function (so everything after "return" would never run), and if something is specified (a return value) it returns that value to the calling function (if any).

Example using continue:
Code:
Foo()
{
    for (new i = 1; i <= 5; i)
    {
        if (i == 3) continue;
        printf("i=%i", i);
    }
    print("This must be printed!");
}
Output would be:
Quote:1
2
4
5
This must be printed!

Example using break:
Code:
Foo()
{
    for (new i = 1; i <= 5; i)
    {
        if (i == 3) break;
        printf("i=%i", i);
    }
    print("This must be printed!");
}
Output would be:
Quote:1
2
This must be printed!

Example using return:
Code:
Foo()
{
    for (new i = 1; i <= 5; i)
    {
        if (i == 3) return;
        printf("i=%i", i);
    }
    print("This must be printed!");
}
Output would be:
Quote:1
2


I've seen beginners misusing this quite some times, hence this information examples.


RE: how to load every user.ini in scriptfiles using YINI - mems - 2021-02-16

(2021-02-16, 06:01 AM)Kwarde Wrote:
Quote:you should remove return statement in loop because it stops the loop.
Not just the loop, though. Allow me to add this information for mems:
- "continue" stops the current iteration of the loop and goes to the next iteration (iteration is the right word, right?)
- "break" stops the current iteration and does not go to the next one: "break"ing the loop
- "return" stops the execution of the entire function (so everything after "return" would never run), and if something is specified (a return value) it returns that value to the calling function (if any).

Example using continue:
Code:
Foo()
{
    for (new i = 1; i <= 5; i)
    {
        if (i == 3) continue;
        printf("i=%i", i);
    }
    print("This must be printed!");
}
Output would be:
Quote:1
2
4
5
This must be printed!

Example using break:
Code:
Foo()
{
    for (new i = 1; i <= 5; i)
    {
        if (i == 3) break;
        printf("i=%i", i);
    }
    print("This must be printed!");
}
Output would be:
Quote:1
2
This must be printed!

Example using return:
Code:
Foo()
{
    for (new i = 1; i <= 5; i)
    {
        if (i == 3) return;
        printf("i=%i", i);
    }
    print("This must be printed!");
}
Output would be:
Quote:1
2


I've seen beginners misusing this quite some times, hence this information examples.

yep, i took care of them now and everything works good so far. now i know a bit more about loops than i did before.

edit: i ended up using a method which really helps with this situation which is counting how many players there are with gsf level. if that count was 0, then i sent the "no account has gsflevel" message. this is how it looks now:

Code:
CMD:osetallgsf(playerid, params[])
{
    new File: handle = fopen("allusers.txt", io_read), nick[MAX_PLAYER_NAME], INI: file;
    new string[192], fstring[46], pname[MAX_PLAYER_NAME], gsflevel, count;
    GetPlayerName(playerid, pname, sizeof(pname));
    if((IsPlayerAdmin(playerid)) || PlayerInfo[playerid][AdminLevel] == 3) {
        if(sscanf(params, "i", gsflevel)) return SendClientMessage(playerid, COLOR_RED, "Syntax: /osetallgsf <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)) {
                StripNewLine(nick);
                format(fstring, 46, "Users/%s.ini", nick);
                if(INI_ParseFile(fstring, "LoadGSFLevel", .bPassTag = true)) {
                    if(GSFLevelInfo > 0 && !onlineinfo) {
                        流⺞;
                        format(string, sizeof(string), "[{FF0000}GSF{FFFFFF}]: Successfully offline set {FF0000}%s's{FFFFFF} GSF level to: %i.", nick, gsflevel);
                        SendClientMessage(playerid, COLOR_WHITE, string);
                        file = INI_Open(fstring);
                        INI_SetTag(file, "=|PlayerData|=");
                        INI_WriteInt(file, "GSFLevel", gsflevel);
                        INI_Close(file);
                    }
                }
            }
              if(count == 0) {
                SendClientMessage(playerid, COLOR_RED, "ERROR: No account was found having a GSF level.");
                return 1;
            }
            format(string, sizeof(string), "[STAFF]: \"%s\" has issued the command: {FF0000}OSETALLGSF{00FFFF}.", pname);
            SendToRCON(COLOR_AQUA, string);
            fclose(handle);
        } else return SendClientMessage(playerid, COLOR_RED, "ERROR: The file \"allusers.txt\" does not exist, therefore canceling the process.");
        return 1;
    } else return SendClientMessage(playerid, COLOR_RED, "ERROR: Authorization revoked.");
}

not a problem or anything (so far), just for anyone who might have a problem like this. i just wish this
Code:
            format(string, sizeof(string), "[STAFF]: \"%s\" has issued the command: {FF0000}OSETALLGSF{00FFFF}.", pname);
            SendToRCON(COLOR_AQUA, string);
was above this:
Code:
        format(string, sizeof(string), "[{FF0000}GSF{FFFFFF}]: Successfully offline set {FF0000}%s's{FFFFFF} GSF level to: %i.", nick, gsflevel);
                        SendClientMessage(playerid, COLOR_WHITE, string);
which is possible but if the counter finds 0, it will still send the rcon msg with the error msg that it didn't find any player, idk but that looks so weird and wrong to me. but it's okay since only for rcon peeps lol