English Get amount of ranks

6 replies
Goto Page
To the start Previous 1 Next To the start
21.06.19 03:10:16 am
Up
AtomKuh
User
Offline Off
I know that there are lua commands like stats or steamstats to get the current rank of a playerˋs usgn or steamid.

Is it possible to get the amount of all registered ranks?

I would like to make a message like this one:
Player is on rank 23 of 1134.
21.06.19 05:02:15 am
Up
Goo
User
Offline Off
If that's not possible I would recommend to get the current count of players manually and save it into a file that can be modified by Lua.

Then add a check for when a player joins and check if it's his first time to know if you need to increase the count by 1.

The tricky part is how to know if it's his first time on the server, you could save an empty file with his login and then check if a player's file exists to know if it's his first time on the server.
Though that would conflict with the already existing players from when you added players manually, because you didn't create them a first join file.

So yeah it would be better to delete your stats file and use a "follower" lua file to save players who joined your server.

Of course if you already have a save system in your server you wouldn't need to care because you can just use those files!
21.06.19 07:29:41 am
Up
Boolean
GAME BANNED
Offline Off
Not sure if this works.

Edit: outdated
edited 2×, last 23.06.19 08:53:54 am
21.06.19 10:07:55 pm
Up
AtomKuh
User
Offline Off
@user Goo: I have already thought about that. I will do that if there is no other possibility

@user Boolean: I know that there are 4 ranks in my server but the script says the lowest rank is 2
22.06.19 08:47:28 pm
Up
Goo
User
Offline Off
Well, to me the amount of lines in userstats.dat is almost as much as the ones in "rank" (450~ lines with 410~ users)...
23.06.19 08:31:29 am
Up
Boolean
GAME BANNED
Offline Off
Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
function getlowestrank()
     local dir = "sys/stats/userstats.dat"
     local file = io.open(dir, "rb")
     local res, size = 0, file:seek("end")
     file:seek("set", 17)
     repeat
          file:read("*l")
          res = res + 1
          file:seek("cur", 34)
     until  file:seek("cur") >= size
     file:close()
     return res
end

--testing
print("Lowest rank is "..getlowestrank())

It works, now, hopefully. That one was outdated, my bad.

Edit: adding
file:close()
at the end of the function.
edited 2×, last 24.06.19 03:33:26 am
To the start Previous 1 Next To the start