mysql server stats -
KinderClans - 20.09.2018
I wanted to make some server stats such as joins, quits kills etc. So i made in this way:
pawn Код:
enum serverStats
{
TotalJoins,
TotalQuits,
TotalAccounts,
TotalKills,
TotalDeaths
};
pawn Код:
new ServerStats[serverStats];
To load them (Placed on OnGameModeInit):
pawn Код:
mysql_tquery(g_SQL, "SELECT * FROM `serverstats`", "Server_Stats_Load");
pawn Код:
function Server_Stats_Load()
{
cache_get_value_int(0, "TotalJoins", ServerStats[TotalJoins]);
cache_get_value_int(0, "TotalQuits", ServerStats[TotalQuits]);
cache_get_value_int(0, "TotalAccounts", ServerStats[TotalAccounts]);
cache_get_value_int(0, "TotalKills", ServerStats[TotalKills]);
cache_get_value_int(0, "TotalDeaths", ServerStats[TotalDeaths]);
print("* Server stats loaded successfully.");
return 1;
}
NB: Function is just a macro of forward public.
But in mysql log i'm getting this when loading them:
Quote:
[09/20/18 09:18:48] [INFO] Executing callback 'Server_Stats_Load' with 0 parameter...
[09/20/18 09:18:48] [DEBUG] executing AMX callback with index '113'
[09/20/18 09:18:48] [DEBUG] cache_get_value_name_int(0, "TotalJoins", 0xB314FAF4) 4689)
[09/20/18 09:18:48] [ERROR] cache_get_value_name_int: invalid row index '0' (number of rows: '0') 4689)
[09/20/18 09:18:48] [DEBUG] cache_get_value_name_int(0, "TotalQuits", 0xB314FAF 4690)
[09/20/18 09:18:48] [ERROR] cache_get_value_name_int: invalid row index '0' (number of rows: '0') 4690)
[09/20/18 09:18:48] [DEBUG] cache_get_value_name_int(0, "TotalAccounts", 0xB314FAFC) 4691)
[09/20/18 09:18:48] [ERROR] cache_get_value_name_int: invalid row index '0' (number of rows: '0') 4691)
[09/20/18 09:18:48] [DEBUG] cache_get_value_name_int(0, "TotalKills", 0xB314FB00) 4692)
[09/20/18 09:18:48] [ERROR] cache_get_value_name_int: invalid row index '0' (number of rows: '0') 4692)
[09/20/18 09:18:48] [DEBUG] cache_get_value_name_int(0, "TotalDeaths", 0xB314FB04) 4693)
[09/20/18 09:18:48] [ERROR] cache_get_value_name_int: invalid row index '0' (number of rows: '0') 4693)
|
This is the serverstats table:
https://image.ibb.co/kmTBuz/Immagine.jpg
But if i save them (I have Server_Stats_Save on OnGameModeExit), it works:
Quote:
[09/20/18 09:22:08] [INFO] query "UPDATE `serverstats` SET `TotalJoins` = '0', `TotalQuits` = '0', `TotalAccounts` = '0', `TotalKills` = '0', `TotalDeaths` = '0'" successfully executed within 27.745 milliseconds
[09/20/18 09:22:08] [DEBUG] CResultSet::Create(connection=0x92fa258, query_str='UPDATE `serverstats` SET `TotalJoins` = '0', `TotalQuits` = '0', `TotalAccounts` = '0', `TotalKills` = '0', `TotalDeaths` = '0'')
|
I created a table called "serverstats" and i placed 5 column in it.
What's wrong?
Re: mysql server stats -
iLearner - 20.09.2018
The whole concept is wrong here, you can't just make a table that is supposed to contain only 1 row. To get those stats, you can query the tables and get your results, for example total users:
PHP код:
mysql_tquery(g_SQL, "SELECT count(*) AS taccounts FROM `users`", "Server_Stats_Load");
Now `taccounts` contains the number of users.
Re: mysql server stats -
KinderClans - 20.09.2018
Ok, but what about other stats such as kills, deaths etc?
Re: mysql server stats -
NaS - 20.09.2018
Quote:
Originally Posted by KinderClans
Ok, but what about other stats such as kills, deaths etc?
|
You can use SUM to get the total number of (eg) kills:
Код:
SELECT SUM(`Kills`) AS `TotalKills` FROM `users`
Re: mysql server stats -
KinderClans - 20.09.2018
Ok thanks. But how i should edit that server_stats_save/load to make stats save and load?
Re: mysql server stats -
NaS - 20.09.2018
Quote:
Originally Posted by KinderClans
Ok thanks. But how i should edit that server_stats_save/load to make stats save and load?
|
You don't need to, the stats can be calculated from the users table any time. This also fixes any possible inconsitencies, like number of accounts when deleting one.
Re: mysql server stats -
KinderClans - 20.09.2018
Ok but what if i want to save/log admin actions and i dont have the AdminActions column in my users table?
Re: mysql server stats -
ReD_HunTeR - 20.09.2018
For logs and admin action you have to create a separate table
Re: mysql server stats -
KinderClans - 20.09.2018
That's how i wanna make it. I don't wanna use my accounts table for showing server stats.
That's why i made a separate serverstats table. I just need to fix that. Code is in the first post, any help is accepted.
Re: mysql server stats -
NaS - 20.09.2018
Quote:
Originally Posted by KinderClans
That's how i wanna make it. I don't wanna use my accounts table for showing server stats.
That's why i made a separate serverstats table. I just need to fix that. Code is in the first post, any help is accepted.
|
Actual Server Stats are still better to do with SUM or COUNT wherever you can. Especially kills/deaths/connects/num. of accounts.
Not only is it much easier than creating a seperate table and keep the data in sync, it's also consistent and just a query. You can extend this system as you add new columns or saved data to the users table and just extend the query for retrieving them, instead of having a seperate system just for stats.
Admin Logs or Actions are a different thing.
But if you really want the server stats to be seperated for whatever reason, the error you have in your first post is caused by an empty table, or at least zero retrieved rows.
Make sure the table isn't empty and test the query you try to execute in phpmyadmin.