07.10.2018, 17:39
How to make a quantity registered in Y_INI?
Код:
Number_Of_Registered[MAX_PLAYERS];
Number_Of_Registered[MAX_PLAYERS];
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 }
How to make a quantity registered in Y_INI?
Код:
Number_Of_Registered[MAX_PLAYERS]; |
#define MAX_USER_ENTRYS 1000
new CountUsersFromDB;
for(new i; i < sizeof(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(szQuery, sizeof(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(DATABASE, szQuery); // 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.
}
}
format(str, sizeof(str), "Registered users: %d", CountUsersFromDB);
SendClientMessage(playerid, -1, str);
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 код:
PHP код:
PHP код:
|
SELECT * FROM `mytable`
SELECT COUNT(*) FROM `mytable`