English How to tell a players rank?

22 replies
Goto Page
To the start Previous 1 2 Next To the start
24.09.11 10:29:30 pm
Up
if
User
Offline Off
When a pl say rank,it displays their statics.
How to show these without the player saying?
I'm a signature bar.Thank you for your support.
24.09.11 10:30:22 pm
Up
Bowlinghead
User
Offline Off
Code:
1
bind "n" "say rank"


If you press N you say rank!

Attention:
It goes only clientsided

or you make it with serveraction!
Metzelbude Jail - Mein ehemaliges Leben
24.09.11 10:33:18 pm
Up
if
User
Offline Off
I don't want it to go client side,
I want to be like
if adm say !info 1
And it displays his statics.
I'm a signature bar.Thank you for your support.
24.09.11 10:39:02 pm
Up
Bowlinghead
User
Offline Off
that you mean!

Try this!
Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
admin = {USGNIDHERE}
addhook("say","roflsay")
function roflsay(id,"txt")
     for _, admin in ipairs(admin) do
          if player(id,"usgn")==admin then
               if txt=="!info" then
                    local pid=tonumber(string.sub(txt,7,string.len(txt)))
                    msg2(id,"Player name:"..player(pid,"name")
                    msg2(id,"Player Kills:"..player(pid,"score")
                    msg("If you see this: It works :)")
               end
          end
     end
end

Untestet
Metzelbude Jail - Mein ehemaliges Leben
24.09.11 10:40:14 pm
Up
if
User
Offline Off
doesn't work,
I'm a signature bar.Thank you for your support.
24.09.11 10:53:03 pm
Up
Starkkz
Moderator
Offline Off
There are other stats that are in files of CS2D, the others are used for the moment. BTW

Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
AdminList = {} -- put the usgn(s) of the admin(s) separed by comma

addhook("say","onSay")
function onSay(id,txt)
     for _, u in pairs(AdminList) do
          if u == player(id,"usgn") then
               if txt == "!info" then
                    local f = string.find(txt," ")
                    local p; if f then p = tonumber(string.sub(txt,f+1)) end
                    if p then
                         msg2(id,"Player Name: "..player(p,"name"))
                         msg2(id,"Player Score: "..player(p,"score"))
                    end
               end
          end
     end
end
24.09.11 10:59:05 pm
Up
if
User
Offline Off
The score just says 0,
I'm a signature bar.Thank you for your support.
24.09.11 11:00:45 pm
Up
Rumine
User
Offline Off
Because you didn't kill anyone?

BTW his script only shows people who are admins.
24.09.11 11:06:05 pm
Up
Starkkz
Moderator
Offline Off
Right..

Spoiler >


There's it. I've also added the deaths
25.09.11 01:00:40 am
Up
DC
Admin
Offline Off
user if is talking about the (long-term) stats saved in the stats file. not about the current scoreboard stats.

it's not possible to access these values via Lua directly/easily but you could use Lua's io commands to read the contents of that file.
25.09.11 11:14:47 am
Up
if
User
Offline Off
Thanks
I'm a signature bar.Thank you for your support.
25.09.11 12:22:53 pm
Up
Banaan
User
Offline Off
Reading player stats from sys/stats/userstats.dat

Quite simple, really. All you really have to take care with is the endianness of your system. (If your server is hosted on Windows just skip this part, you don't have to do anything). If you get really strange results (4294967266 kills instead of 30) just change BIG_ENDIAN to true.

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
local BIG_ENDIAN = false

local function ReadInt(str)
     if #str ~= 4 then return 0 end
     if BIG_ENDIAN then str = str:reverse() end
     return str:byte(1) + 256 * str:byte(2) + (256 ^ 2) * str:byte(3) + (256 ^ 3) * str:byte(4)     
end

local function PlayerStats(usgn)
     if not usgn then return false end
     local n, u, s, k, d, t
     local f = io.open("sys/stats/userstats.dat", "rb")
     f:read()
     while true do
          n  = f:read()
          if n == nil then break end
          u  = ReadInt(f:read(4))
          if u == usgn then
               s  = ReadInt(f:read(4))
               k  = ReadInt(f:read(4))
               d  = ReadInt(f:read(4))
               t  = ReadInt(f:read(4))
               break
          end
     end
     f:close()
     if n == nil then return false end
     return { name = n, usgn = u, score = s, frags = k, deaths = d, ptime = t }
end


So how to use it?
The function PlayerStats takes one argument, being the USGN ID of the player you want to get the stats of. It returns either false on failure (user could not be found) or a table containing the stats on success.

Code:
1
2
3
4
5
6
7
8
9
10
11
12
local stats = PlayerStats(player(id, "usgn"))
if stats then
     print(string.format([[
Userstats for %s (USGN ID %u):
Score: %u
Frags: %u
Deaths: %u
Time on server: %u seconds 
]], stats.name, stats.usgn, stats.score, stats.frags, stats.deaths, stats.ptime))
else
     print("Could not find stats for " .. player(id, "usgn"))
end


As you can see, the stats values (table keys) are the following:
• name
• usgn
• score
• frags
• deaths
• ptime

Where ptime is the time played on the server in seconds.
26.09.11 05:31:34 pm
Up
Starkkz
Moderator
Offline Off
That was what I was talking about!. But I didn't know what reading format was used to read the stats files, now I understand it was 4 bytes (integer).

Edit: Btw, Banaan, I understood there was a limit of kills/deaths, it's 65k though.
26.09.11 06:52:30 pm
Up
if
User
Offline Off
Thanks,
i have a question ,
When I open userstats, I couldn't not read any of it.How can I read it?
edited 1×, last 26.09.11 06:57:49 pm
I'm a signature bar.Thank you for your support.
26.09.11 06:56:37 pm
Up
DannyDeth
User
Offline Off
Because userstats is byte code, not human-readable text AFAICR.
"Morning, boys. Time to drop your cocks and put on your socks, we have a raft to build."
26.09.11 07:58:17 pm
Up
Crystal Rain
User
Offline Off
You can convert it to human lang right?
Or no?
A thousand may fall at your side, ten thousand at your right hand, but it will not come near you. You will only look with your eyes and see the recompense of the wicked. - Psalm 91:7-8 ESV
26.09.11 08:03:45 pm
Up
Brilliant
User
Offline Off
My pc just pops up an error.
26.09.11 08:33:35 pm
Up
Banaan
User
Offline Off
Use the script 5 posts up to get it into human readable format during runtime using Lua.

Or, if you want to get your rank file decoded into another file, use this little Python script:
Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
from struct import unpack

if __name__ == "__main__":
     sf = open("sys/stats/userstats.dat", "rb")
     df = open("sys/stats/userstats_processed.txt", "w")
     df.write("// Processed userstats alpha\r\n")
     df.write("%s | %s | %s | %s | %s | %s | %s\r\n" % ('Rank:', 'Name:'.ljust(30), 'USGN:'.ljust(7), 'Score:'.ljust(7), 'Frags:'.ljust(7), 'Deaths:'.ljust(7), 'Time:'))
     sf.readline()
     rank = 0
     while True:
          rank = rank + 1
          n = sf.readline().strip().ljust(30)
          if len(n) == 0:
               break
          r = sf.read(20)
          if len(r) == 0:
               break
          res = unpack("5L", r)
          df.write("%s | %s | %s | %s | %s | %s | %d\r\n" % (str(rank).ljust(5), n, str(res[0]).ljust(7), str(res[1]).ljust(7), str(res[2]).ljust(7), str(res[3]).ljust(7), res[4]))
     sf.close()
     df.close()
     
     print("Userstats decoded.")


Which will create a new file (sys/stats/userstats_processed.txt) containing the ranks in a nicely formatted, human-readable fashion.
26.09.11 08:36:22 pm
Up
Crystal Rain
User
Offline Off
o.O You are genius! Banaan.
A thousand may fall at your side, ten thousand at your right hand, but it will not come near you. You will only look with your eyes and see the recompense of the wicked. - Psalm 91:7-8 ESV
28.09.11 08:13:25 pm
Up
if
User
Offline Off
A problem here,
It displays 1 ,why?
I'm a signature bar.Thank you for your support.
To the start Previous 1 2 Next To the start