Highest Level Player
#1

Hello, I made server statistics command, and I would like to write the highest level of the player, how can I do it now? I tried the loop, but the last id of the loop size send...
Reply
#2

Can you be a bit more specific?

Do you only want to know the highest level of online players, or all players that are registered?

Also it would be nice if you could show us the code you already have.
Reply
#3

All players that are registered...
Код:
new highestlevelacc;
new filestr[64];
for(new id=1;id<250;id++){
format(filestr,sizeof(filestr),ACCOUNT_DIR,id);
if(fexist(filestr))
{
if(AccountsInfo[id][Level]>=AccountsInfo[id][Level]) { 
highestlevelacc=id; va_SendClientMessage(playerid,-1,"The highest level is %d acc,level:%d",highestlevelacc,AccountsInfo[highestlevelacc][Level]);break; 
} 
}
}
I tried it without a break but same come...
Reply
#4

Quote:
Originally Posted by Kenrque
Посмотреть сообщение
All players that are registered...
Код:
new highestlevelacc;
new filestr[64];
for(new id=1;id<250;id++){
format(filestr,sizeof(filestr),ACCOUNT_DIR,id);
if(fexist(filestr))
{
if(AccountsInfo[id][Level]>=AccountsInfo[id][Level]) { 
highestlevelacc=id; va_SendClientMessage(playerid,-1,"The highest level is %d acc,level:%d",highestlevelacc,AccountsInfo[highestlevelacc][Level]);break; 
} 
}
}
I tried it without a break but same come...
But you aren't even opening the new file (so no info is loaded).

Furthermore this check

Код:
AccountsInfo[id][Level]>=AccountsInfo[id][Level]
is pointless and will always be true (both values will always be the same).

But apart from any of the above issues, this is not a very good solution.
- The loop you did will only check for 250 accounts, what if there are more?
- At some point you'd have to make the loop have thousands of iterations, so it will be very very slow, not sure where you execute it but it will take up to several seconds to find out the highest level

You should think about another way to solve this. Best would be (My)SQL which is perfect for things like this (it would be one simple query to find out best score, highest level, most money, most kills or whatever).

But if you want to stick to User Files, you can solve this another way:

Keep track of the highest levels of online players and store this info, for example store Player Name and Level in an Array, whenever a Player gets a higher level than the top-player, make him the top-player. This will take some time to actually show the top-player since that player must come online for it to update, but this is the best and easiest way apart from actual Databases.
You can then save/load only this info to/from a file.
Reply
#5

Quote:
Originally Posted by NaS
Посмотреть сообщение
But you aren't even opening the new file (so no info is loaded).

Furthermore this check

Код:
AccountsInfo[id][Level]>=AccountsInfo[id][Level]
is pointless and will always be true (both values will always be the same).

But apart from any of the above issues, this is not a very good solution.
- The loop you did will only check for 250 accounts, what if there are more?
- At some point you'd have to make the loop have thousands of iterations, so it will be very very slow, not sure where you execute it but it will take up to several seconds to find out the highest level

You should think about another way to solve this. Best would be (My)SQL which is perfect for things like this (it would be one simple query to find out best score, highest level, most money, most kills or whatever).

But if you want to stick to User Files, you can solve this another way:

Keep track of the highest levels of online players and store this info, for example store Player Name and Level in an Array, whenever a Player gets a higher level than the top-player, make him the top-player. This will take some time to actually show the top-player since that player must come online for it to update, but this is the best and easiest way apart from actual Databases.
You can then save/load only this info to/from a file.
i have enum this AccountsInfo with Y_INI Load and save system and sets in array Level of Account of level player account id (info loaded)..and not work command,no mysql use currently, can with Y_INI ?, 250 is max accounts limit,i used fexist for work normal(created)AccountID..
Reply
#6

I see. I thought the info was supposed to be loaded right in the loop.

However, the check I mentioned is still not correct. You need to declare two variables before the loop, something like "highestid" and "highestlevel".

Inside the loop, you compare the Level of the current Account with the highestlevel variable.
If higher, set highestid to the current id and highestlevel to the level of that account.

When the loop finished, highestid and highestlevel will be filled with the data of the highest level account.


Still, you should think about SQL or MySQL. That will get rid of the Accounts limit and finding out data like this is a lot easier.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)