Forum

> > CS2D > Scripts > How to tell a players rank?
ForenübersichtCS2D-Übersicht Scripts-ÜbersichtEinloggen, um zu antworten

Englisch How to tell a players rank?

20 Antworten
Seite
Zum Anfang Vorherige 1 2 Nächste Zum Anfang

alt Re: How to tell a players rank?

Bowlinghead
User Off Offline

Zitieren
that you mean!

Try this!
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

alt Re: How to tell a players rank?

DC
Admin Off Offline

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

alt Re: How to tell a players rank?

Banaan
User Off Offline

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

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.

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.

alt Re: How to tell a players rank?

Starkkz
Moderator Off Offline

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

alt Re: How to tell a players rank?

if
User Off Offline

Zitieren
Thanks,
i have a question ,
When I open userstats, I couldn't not read any of it.How can I read it?
1× editiert, zuletzt 26.09.11 18:57:49

alt Re: How to tell a players rank?

Banaan
User Off Offline

Zitieren
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:
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.
Zum Anfang Vorherige 1 2 Nächste Zum Anfang
Einloggen, um zu antworten Scripts-ÜbersichtCS2D-ÜbersichtForenübersicht