Forum

> > CS2D > General > Allow for Top 10
Forums overviewCS2D overviewGeneral overviewLog in to reply

English Allow for Top 10

9 replies
To the start Previous 1 Next To the start

old Allow for Top 10

mrc
User Off Offline

Quote
I want to allow players under Top 10 to use serveraction1 function, is it possible? For example, if player's rank <= 10 then allow to use serveraction1, else return 1.

old Re: Allow for Top 10

Gaios
Reviewer Off Offline

Quote
cs2d lua cmd stats
usgnid
rank

From what can I see in the docs, it works only for us users.. I'm not sure about Steam users.

old Re: Allow for Top 10

TrialAndError
User Off Offline

Quote
If you're talking about the "rank" top 10. Then this is it.
You can use cs2d lua cmd stats and cs2d lua cmd steamstats

1
2
3
4
5
6
function isTop10(id)
    if stats(player(id,"usgn"), "rank") <= 10 or steamstats(player(id,"steamid"), "rank") <= 10 then
        return true
    end
    return false
end

old Re: Allow for Top 10

Cure Pikachu
User Off Offline

Quote
There's just a tiny problem though.
cs2d lua cmd stats & cs2d lua cmd steamstats has written
• rank: gets the current rank of the player on the server 1 for the best (0 if unranked)

This means the current check at the moment not only considers the top 10 players valid, but also considers unranked players valid.
cs2d lua cmd stats & cs2d lua cmd steamstats has written
The command returns the boolean value false if stats are not available for the specified U.S.G.N. / Steam ID or if wrong parameters are specified.

If you have players that don't actually use both USGN and Steam, then the code kinda bugs out because one or all of the checks is comparing a number to a boolean.

So I'd do something like:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
function isTop10(id)
	local uid, sid = player(id,"usgn"), player(id,"steamid")
	if stats(uid,"exists") then
		local u = stats(uid,"rank")
		if u > 0 and u <= 10 then
			return true
		end
	end
	if steamstats(sid,"exists") then
		local s = steamstats(sid,"rank")
		if s > 0 and s <= 10 then
			return true
		end
	end
	return false
end
edited 2×, last 25.09.19 06:55:49 am

old Re: Allow for Top 10

mrc
User Off Offline

Quote
Thanks, it works @user Cure Pikachu.

Top 20? So it's like Top 10 for USGN + Top 10 for Steam? Who can fix it?
edited 1×, last 13.05.19 11:28:28 pm

old Re: Allow for Top 10

Cure Pikachu
User Off Offline

Quote
I wouldn't trust this to work TBH
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
rankTab = {}

function initRankTable()
	rankTab = {}
	-- combine the USGN and Steam ranking charts while accounting for duplicates (if any)
	local i = 1
	for _, id in pairs(player(0,"table")) do
		local ukdr, skdr = 0, 0
		local uid, sid = player(id,"usgn"), player(id,"steamid")
		if stats(uid,"exists") then
			local ur = stats(uid,"rank")
			if ur > 0 and ur <= 10 then
				ukdr = stats(uid,"killsperdeath")
			end
		end
		if steamstats(sid,"exists") then
			local sr = steamstats(sid,"rank")
			if sr > 0 and sr <= 10 then
				skdr = steamstats(sid,"killsperdeath")
			end
		end
		if ukdr > 0 or skdr > 0 then
			if ukdr > skdr then
				rankTab[i].id = uid
				rankTab[i].kdr = ukdr
			else
				rankTab[i].id = sid
				rankTab[i].kdr = skdr
			end
			i = i + 1
		end
	end
	-- sorting it out
	if #rankTab > 0 then
		table.sort(rankTab,function(k1,k2) return k1.kdr > k2.kdr end)
	end
end

function isTop10(id)
	initRankTable()
	if #rankTab > 0 then
		for x = 1, math.min(#rankTab,10) do
			local t = type(rankTab[x].id)
			if t == "number" then
				if rankTab[x].id == player(id,"usgn") then
					return true
				end
			elseif t == "string" then
				if rankTab[x].id == player(id,"steamid") then
					return true
				end
			end
		end
	end
	return false
end
edited 2×, last 14.05.19 12:50:20 pm
To the start Previous 1 Next To the start
Log in to replyGeneral overviewCS2D overviewForums overview