15.03.2018, 21:29
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...
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; } } }
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; } } } |
AccountsInfo[id][Level]>=AccountsInfo[id][Level]
But you aren't even opening the new file (so no info is loaded).
Furthermore this check Код:
AccountsInfo[id][Level]>=AccountsInfo[id][Level] 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. |