Forum

> > CS2D > Scripts > Get amount of ranks
Forums overviewCS2D overview Scripts overviewLog in to reply

English Get amount of ranks

6 replies
To the start Previous 1 Next To the start

old Get amount of ranks

AtomKuh
User Off Offline

Quote
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.

old Re: Get amount of ranks

Mami Tomoe
User Off Offline

Quote
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!

old Re: Get amount of ranks

AtomKuh
User Off Offline

Quote
@user Mami Tomoe: I have already thought about that. I will do that if there is no other possibility

@user Baloon: I know that there are 4 ranks in my server but the script says the lowest rank is 2

old Re: Get amount of ranks

Mami Tomoe
User Off Offline

Quote
Well, to me the amount of lines in userstats.dat is almost as much as the ones in "rank" (450~ lines with 410~ users)...

old Re: Get amount of ranks

Baloon
GAME BANNED Off Offline

Quote
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
Log in to reply Scripts overviewCS2D overviewForums overview