How to tell a players rank?
22 replies24.09.11 10:29:30 pm
When a pl say rank,it displays their statics.
How to show these without the player saying?
How to show these without the player saying?
I'm a signature bar.Thank you for your support.
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
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 want to be like
if adm say !info 1
And it displays his statics.
I'm a signature bar.Thank you for your support.
that you mean!
Try this!
Untestet
Try this!
Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
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
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
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
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
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
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.
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.
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.
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.
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
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
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
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
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
ptimeWhere ptime is the time played on the server in seconds.
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.
Edit: Btw, Banaan, I understood there was a limit of kills/deaths, it's 65k though.
Thanks,
i have a question ,
When I open userstats, I couldn't not read any of it.How can I read it?
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.
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."
You can convert it to human lang right?
Or no?
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
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:
Which will create a new file (sys/stats/userstats_processed.txt) containing the ranks in a nicely formatted, human-readable fashion.
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
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.")
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.
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







1 
How to tell a players rank?

