English Allow for Top 10

9 replies
Goto Page
To the start Previous 1 Next To the start
13.05.19 05:45:17 pm
Up
mrc
User
Offline Off
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.
CS2D Global - cs2dglobal.tk
13.05.19 06:01:46 pm
Up
Gaios
Security Supporter
Offline Off
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.
13.05.19 06:02:38 pm
Up
TrialAndError
User
Offline Off
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

Code:
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
13.05.19 06:52:42 pm
Up
mrc
User
Offline Off
Ty I will test it later but this might work.
CS2D Global - cs2dglobal.tk
13.05.19 08:12:47 pm
Up
Cure Pikachu
User
Offline Off
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:
Code:
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 1×, last 13.05.19 08:29:38 pm
IMG:https://i.imgur.com/uUrye71.png
IMG:https://i.imgur.com/xpsyQRX.png
13.05.19 09:54:11 pm
Up
M3_Quick
User
Offline Off
nice work @user Cure Pikachu:
13.05.19 11:05:16 pm
Up
Gaios
Security Supporter
Offline Off
@user TrialAndError, @user Cure Pikachu: You have made Top20. You might scale the arraries into 1 and then look up for Top10.
13.05.19 11:13:48 pm
Up
mrc
User
Offline Off
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
CS2D Global - cs2dglobal.tk
14.05.19 09:10:50 am
Up
Cure Pikachu
User
Offline Off
I wouldn't trust this to work TBH
Code:
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
IMG:https://i.imgur.com/uUrye71.png
IMG:https://i.imgur.com/xpsyQRX.png
14.05.19 05:46:17 pm
Up
mrc
User
Offline Off
Same result as the script before.
CS2D Global - cs2dglobal.tk
To the start Previous 1 Next To the start