Forum

> > CS2D > Scripts > LUA show rank ?
Forums overviewCS2D overview Scripts overviewLog in to reply

English LUA show rank ?

8 replies
To the start Previous 1 Next To the start

old LUA show rank ?

-DIE Wolf-
User Off Offline

Quote
Hey all. I want a LUA scripts that make it show rank as the way i like.
Example :
If player say !RANK (not rank, it is !rank)
then msg : YOUR RANK IS XXX
Can you help me ?

old Re: LUA show rank ?

Rainoth
Moderator Off Offline

Quote
You'll have to create a ranking system for that. Showing rank in that way is really easy. Creating your own ranking system however takes a bit of time and work. If you provide us your ranking system, I'm sure we'll write you the thing you're asking for

old Re: LUA show rank ?

M0BSTAZ
User Off Offline

Quote
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
if RANK_LUA ~= nil then return end
RANK_LUA = 1

local INTERVAL = 60
local rank_players = {}
local rank_nextrefresh = 0
local rank_refreshedrows = 0

function rank_get(usgn, maxrows)
	if maxrows == nil then maxrows = math.huge end
	if os.clock() > rank_nextrefresh or maxrows > rank_refreshedrows then rank_refreshtable(maxrows) end
	local stats = rank_players[usgn]
	return stats ~= nil and rank_players[usgn][1] or math.huge
end

function rank_refreshtable(maxrows)
	local buff
	
	rank_players = {}
	
	local f = io.open(CS2D_ROOT .. "sys/stats/userstats.dat", "rb")
	if f == nil then return end
	
	f:read("*l")
	for i = 1, maxrows do
		local stats = {}
		
		stats[1] = i
		
		buff = f:read("*l")
		if buff == nil then break end
		stats[2] = buff
		
		buff = f:read(20)
		if buff == nil then break end
		for i = 1, 20, 4 do
			table.insert(stats, binstr2num(string.sub(buff, i, i+4)))
		end
		rank_players[stats[3]] = stats
		rank_refreshedrows = i
	end
	
	f:close()
	
	rank_nextrefresh = os.time() + INTERVAL
	if maxrows == math.huge then rank_refreshedrows = math.huge end
end


function binstr2num(str)
	local b1, b2, b3, b4 = string.byte(str, 1, 4)
	return b4 * 0x100000 + b3 * 0x10000 + b2 * 0x100 + b1
end


rank_refreshtable(math.huge)

old Re: LUA show rank ?

Marcell
Super User Off Offline

Quote
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
if RANK_LUA ~= nil then return end
RANK_LUA = 1

local INTERVAL = 60
local rank_players = {} -- PUT USGN IDs HERE
local rank_nextrefresh = 0
local rank_refreshedrows = 0


function rank_get(usgn, maxrows)
     if maxrows == nil then maxrows = math.huge end
     if os.clock() > rank_nextrefresh or maxrows > rank_refreshedrows then rank_refreshtable(maxrows) end
     local stats = rank_players[usgn]
     return stats ~= nil and rank_players[usgn][1] or math.huge
end

function rank_refreshtable(maxrows)
     local buff
     
     rank_players = {}
     
     local f = io.open("sys/stats/userstats.dat", "rb")
     if f == nil then return end
     
     f:read("*l")
     for i = 1, maxrows do
          local stats = {}
          
          stats[1] = i
          
          buff = f:read("*l")
          if buff == nil then break end
          stats[2] = buff
          
          buff = f:read(20)
          if buff == nil then break end
          for i = 1, 20, 4 do
               table.insert(stats, binstr2num(string.sub(buff, i, i+4)))
          end
          rank_players[stats[3]] = stats
          rank_refreshedrows = i
     end
     
     f:close()
     
     rank_nextrefresh = os.time() + INTERVAL
     if maxrows == math.huge then rank_refreshedrows = math.huge end
end


function binstr2num(str)
     local b1, b2, b3, b4 = string.byte(str, 1, 4)
     return b4 * 0x100000 + b3 * 0x10000 + b2 * 0x100 + b1
end


rank_refreshtable(math.huge)

old Re: LUA show rank ?

-DIE Wolf-
User Off Offline

Quote
lol. Just dont know how to use it. I Put files at desired folder and edit server.lua to execute rank.txt. But nothing happened when i start the game.

old Re: LUA show rank ?

MikuAuahDark
User Off Offline

Quote
That's because you need to call GetUserStatRank with the first argument is the USGN ID, then it return a table which contains information about that player rank.

So, how to check if specified usgn doesn't exist in userstat rank?

1
2
3
4
5
6
huh=GetUserStatRank(53360)
if huh.isexists then
	-- Get necessary information, like time on server
else
	-- The usgn doesn't exist(or never enter the server)
end

old Re: LUA show rank ?

M0BSTAZ
User Off Offline

Quote
It's so Hard.. LOL

1
2
3
4
5
6
7
8
9
10
11
addhook("say","Potato")
function Potato(id,txt)
if (txt == "!myrank") then
      local name = player(id, "name") 
      local usgn = player(id, "usgn")
      local ip = player(id, "ip")
      parse("sv_msg2 " .. id .. " Stats for ©000255255" .. name .. "")
      parse("sv_msg2 " .. id .. " ©000255000USGN: ©000255255" .. usgn)
      return 1
	end
end

or try to find to file archieve
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview