Get player rank from userstats.dat by MikuAuahDark
Description
This lua allows you to get player stats from userstats.dat file located at "sys/stats" folder
It include Kills, Frags, Deaths, and Time on Server
Features
Get player rank from userstats.dat(it include kills, frags, deaths, and time on server)
How to Install
Put files at desired folder and edit server.lua to execute rank.txt.
Reserved Global Variable
GetUserStatsRank
Information
Hooks: 0
Lines: 35(with description 53 lines)
Size: 881 Bytes(with description 1539 Bytes)
Functions
GetUserStatsRank(usgn(number))
Parameters:
- usgn, ID of the USGN to see the rank information from userstats.dat
Returns: A information from userstats.dat(table)
Table Index
Table returned by GetUserStatsRank function have this index:
isexists - Is the rank exists(boolean)
score - USGN Score(number)
frags - USGN frags(number)
deaths - USGN deaths(number)
time - Time on server(in seconds)(number)
Special Thanks to
DC: For the userstats.dat file format(at Server rank issue(score is altered)(Here))
Rules
You can use it for your server
You can edit it
You can upload at another website, say MikuAuahDark made it
You can't say this is yours
You can't upload on another website without put me on credits
Notes
1. it doesn't use any library function(for stream files) for lua. it uses default io.open file:read function
2. if you want to learn how the code works, take a look at rank_desc.txt
3. there's a addional index which retrieves very first used player name on the server. Check rank.txt for more info
PHP Implementation
Here's the PHP implementation of v1.4(tested in PHP 5.5.0)
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
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
<?php function GetUserStatsRank($usgn) { 	$Int=function($f) { 		return ord(fread($f,1))+ord(fread($f,1))*256+ord(fread($f,1))*65536+ord(fread($f,1))*16777216; 	}; 	$f=fopen("sys/stats/userstats.dat","rb"); 	fseek($f,0,SEEK_END); 	$size=ftell($f); 	fseek($f,17,SEEK_SET); 	$temp=[ 		"isexists"=>FALSE, 		"score"=>0, 		"frags"=>0, 		"deaths"=>0, 		"time"=>0, 	]; 	while(ftell($f)!=$size) { 		fgets($f);		// skip player name 		$temp_usgn=$Int($f); 		if($usgn==$temp_usgn) { 			$temp["isexists"]=TRUE; 			$temp["score"]=$Int($f); 			$temp["frags"]=$Int($f); 			$temp["deaths"]=$Int($f); 			$temp["time"]=$Int($f); 			break; 		} else fseek($f,16,SEEK_CUR); 	} 	fclose($f); 	return $temp; } ?>
Version History
V1.4
Int function isn't global variable anymore
Rewrite code from stratch. It now ~10x faster than V1.3
V1.3
You can't read the first USGN that enter your server
V1.2
The file now is opened with binary mode which would solve a error that would not read the file correctly
V1.1
Player rank on server. I just accidently put "step" variable as rank number
V1.0
Initial Release
Another MikuAuahDark Scripts
Timer Extra function(timerEx) v4.0 (12)
Env_Laser v1.0 (7)
Weapon Hudtxt v1.0 (7)
Improved Badwords v2.0 (5)
edited 10×, last 21.06.15 11:04:20 pm
Approved by Starkkz
Download
2 kb, 692 Downloads