How to show these without the player saying?
Forum




How to tell a players rank?
20 repliesHow to show these without the player saying?
1
bind "n" "say rank"
If you press N you say rank!
Attention:
It goes only clientsided
or you make it with serveraction!
I want to be like
if adm say !info 1
And it displays his statics.
Try this!
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
BTW his script only shows people who are admins.

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.
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.
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
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.
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
As you can see, the stats values (table keys) are the following:






Where ptime is the time played on the server in seconds.
Edit: Btw, Banaan, I understood there was a limit of kills/deaths, it's 65k though.
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
Re: How to tell a players rank?
Deleted UserOr no?
Or, if you want to get your rank file decoded into another file, use this little Python script:
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.")
Which will create a new file (sys/stats/userstats_processed.txt) containing the ranks in a nicely formatted, human-readable fashion.
Re: How to tell a players rank?
Deleted UserIt displays 1 ,why?

Because you have 1 kill? lol
No I was using Banaan's script
Not only 1,some time 6 ,some times nil value