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
-- init the variables
rank_names = {[0]="Rookie", ..., "Master General"}
base_exp = 10
exp_mod = 1.5
player_ranks = {}
player_exp = {}
for i = 1, 32 do player_ranks[i] = 0; player_exp[i]=0 end
addhook("kill", "rank_kill")
function rank_kill(k,v)
	-- a player should not be rewarded for killing a teammate and should not advance if he is at the highest rank
	if ( player(k, "team") ~= player(v, "team") and player_ranks[k] < #rank_names ) then
		-- add the experience points
		player_exp[k] = player_exp[k] +1
		
		-- check for a rank advancement
		if ( player_exp[k] >= math.floor(base_exp + (player_ranks[k] * exp_mod * base_exp)) ) then
			-- advance the player
			player_ranks[k] = player_ranks[k] +1
			-- reset exp points
			player_exp[k] = 0
		end
	end
end