Forum

> > CS2D > General > Allow for Top 10
ForenübersichtCS2D-ÜbersichtGeneral-ÜbersichtEinloggen, um zu antworten

Englisch Allow for Top 10

9 Antworten
Zum Anfang Vorherige 1 Nächste Zum Anfang

alt Allow for Top 10

mrc
User Off Offline

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

alt Re: Allow for Top 10

Gaios
Reviewer Off Offline

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

alt Re: Allow for Top 10

TrialAndError
User Off Offline

Zitieren
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

alt Re: Allow for Top 10

Cure Pikachu
User Off Offline

Zitieren
There's just a tiny problem though.
cs2d lua cmd stats & cs2d lua cmd steamstats hat geschrieben
• 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 hat geschrieben
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
2× editiert, zuletzt 25.09.19 06:55:49

alt Re: Allow for Top 10

mrc
User Off Offline

Zitieren
Thanks, it works @user Cure Pikachu.

Top 20? So it's like Top 10 for USGN + Top 10 for Steam? Who can fix it?
1× editiert, zuletzt 13.05.19 23:28:28

alt Re: Allow for Top 10

Cure Pikachu
User Off Offline

Zitieren
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
2× editiert, zuletzt 14.05.19 12:50:20
Zum Anfang Vorherige 1 Nächste Zum Anfang
Einloggen, um zu antwortenGeneral-ÜbersichtCS2D-ÜbersichtForenübersicht