The number of registered
#1

How to make a quantity registered in Y_INI?
Код:
Number_Of_Registered[MAX_PLAYERS];
Reply
#2

Wouldn't that basically reset if the server got Stopped/Restarted?

I believe the best solutions would be:
- Use MySQL and have it define the UID as unique/incremental, now you know that last UID is the amount of signed up players.
- For INI (obviously includes Y_INI), Create a file and have the count in it, After every registration done, Open the file, read that number, Increment it, wipe the file, write the new number, close the file.

Conclusion: Don't count on arrays/variables. Store the value somewhere. Cheers!
Reply
#3

Looks like a song name
Reply
#4

/del
Reply
#5

"I left alone my mind was blank"
Reply
#6

The simplest way of doing this would be creating a file that contains an integer which increases everytime a player registers, and to get the value of registered players then simply acquire it from the said file.
Reply
#7

Yes, you can do something like this.

Код:
new players; //First of all you must declare a global var to save the number of players

public OnGameModeInit()
{
      if(!fexist("/Server/RegisteredPlayers.ini")) //Using File Exist function to check weather that file is there or not (In this case "if not")
      {    
             new INI:FILE = INI_Open("/Server/RegisteredPlayers.ini") // so if not we are opening file for creating
             INI_WriteInt(FILE, "Registered_Players", 0); // now we are declaring the key as Registered_Players (like Registered_Players = 0)
             INI_Close(FILE); //Closing the file
      }
      else // opposite of the first explanation
      {
             new INI:FILE = INI_Open("/Server/RegisteredPlayers.ini") //Here we are opening the file for reading
             INI_ParseFile(FILE, "LoadingRegisteredPlayers");// Native for loading files in Y_INI (Here 'FILE' represents the filepath and and the 'LoadingRegisteredPlayers' is the public function that we are using to load)
      }
}

forward LoadUserData(name[], value[]);
public LoadUserData(name[], value[])
{
      INI_Int("Registered_Players", players); // loading the number from INI file to the variable
      return 1;
}

public OnPlayerConnect(playerid)
{
       if(!registered) // IDK how you are doing this  (according to your admin system)
       {
               //So don't put "players++" Now you may think why?, The reason is what happen if somebody connects(non registered) and disconnect without registering, That's why we are not increasing the number here 
               //Goto OnPlayerDialogResponse and put 'players++' if he got registered I'm not doing that part here(I'm lazy)
       }
       return 1;
}

//Now The important thing is we must save the Number of players regged to the file OnGameModeExit
public OnGameModeExit()
{
       new INI:FILE = INI_Open("/Server/RegisteredPlayers.ini") // we are opening file for writing
       INI_WriteInt(FILE, "Registered_Players", players); 
       INI_Close(FILE); //Closing the file
}
I wanna tell you something plus
Quote:
Originally Posted by KamilPolska
Посмотреть сообщение
How to make a quantity registered in Y_INI?
Код:
Number_Of_Registered[MAX_PLAYERS];
Why are you doing this?
I may ask a question
Actually does number of registered players differs according to players? Answer is NO
SO don't make the var like this, new Number_Of_Registered[MAX_PLAYERS];
Just do this, new Number_Of_Registered;
=========================================
If it was helpful...You also help me to increase my REPS...
Reply
#8

When a player registers, increment by doing NumberOfRegistred++; Don't use MAX_PLAYERS for it, it should be a global variable. And then after each register update the table in MySQL.
Reply
#9

Why doing it the hard way while it can be done easy with SQL?
So imagine having a table called USERS where all accounts are stored.


PHP код:
#define MAX_USER_ENTRYS 1000
new CountUsersFromDB
Now simply run a query inside a loop to extract the users from the database.

PHP код:
for(new isizeof(MAX_USER_ENTRYS); i++)
{
    
// Run a query here to check extract account from db. Everytime it finds an account e.g:
    
new DBResult:USER_RESULT;
    
format(szQuerysizeof(szQuery), "SELECT * FROM `USERS` WHERE `ID` = '%s'"i); // IF used auto increment primary key you can identify users using an ID.
    
USER_RESULT db_query(DATABASEszQuery); // Run the query for DATABASE 
    
if(db_num_rows(USER_RESULT)) // Check if there was a result for the query above
    
{
        
CountUsersFromDB += 1// Upcount user.
    
}

Now you can simply do:
PHP код:
format(strsizeof(str), "Registered users: %d"CountUsersFromDB);
SendClientMessage(playerid, -1str); 
Reply
#10

Quote:
Originally Posted by jasperschellekens
Посмотреть сообщение
Why doing it the hard way while it can be done easy with SQL?
So imagine having a table called USERS where all accounts are stored.


PHP код:
#define MAX_USER_ENTRYS 1000
new CountUsersFromDB
Now simply run a query inside a loop to extract the users from the database.

PHP код:
for(new isizeof(MAX_USER_ENTRYS); i++)
{
    
// Run a query here to check extract account from db. Everytime it finds an account e.g:
    
new DBResult:USER_RESULT;
    
format(szQuerysizeof(szQuery), "SELECT * FROM `USERS` WHERE `ID` = '%s'"i); // IF used auto increment primary key you can identify users using an ID.
    
USER_RESULT db_query(DATABASEszQuery); // Run the query for DATABASE 
    
if(db_num_rows(USER_RESULT)) // Check if there was a result for the query above
    
{
        
CountUsersFromDB += 1// Upcount user.
    
}

Now you can simply do:
PHP код:
format(strsizeof(str), "Registered users: %d"CountUsersFromDB);
SendClientMessage(playerid, -1str); 
That's actually worse than INI.
Assume you have 13,231 users in your DB. This will run 13,231 queries in a loop. Plus you just implemented a limit to the number of users you can have, or at least how many users can be counted.

Did you know that a query can select multiple rows? So basically you can just do this:

Код:
SELECT * FROM `mytable`
and the number of rows will tell you how many users there are.

But that's not even all you can do to make it better!

Код:
SELECT COUNT(*) FROM `mytable`
Will count all rows in "mytable" and add one field to the result, which holds the number of users.
Just retrieve the row and you have the number of users. The work is done by (My)SQL.

This can count 100 million rows easily, while your approach would hang the server for several minutes.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)