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
58
59
60
61
62
63
64
65
66
67
68
Player = {}
function MB2D_join(id)
	Player[id] = {} 		-- done
	Player[id].load = 0		-- Does the player have save file loaded ?
	Player[id].exp = 0 		-- How much experience points does the player have ?
	Player[id].level = 0 	-- What's the level of player ?
	Player[id].credits = 0 	-- How many credits does the player have (for buying items,powers, etc.) ?
	Player[id].gold = 5		-- How many ancient gold does the player have (for buying artefacts) ?
	Player[id].energy = 0	-- Some artifacts may require energy to be used, how much energy does the player have ?
end
function MB2D_leave(id)
	if Player[id].load == 1 then
		_savestats(id)
	end
end
function MB2D_team(id)
	if Player[id].load == 0 then
		_loadstats(id)
		Player[id].load = 1
	end
end
function _loadstats(id)
	local usgn = player(id,"usgn")
	if usgn > 0 then
		local file = io.open("sys/lua/saves/"..usgn.."MB.txt","r")
		if file then
			local lvl,xp,cre,gold,energy = file:read("*n","*n","*n","*n","*n")
			Player[id].level = lvl or 1
			Player[id].exp = xp or 0
			Player[id].credits = cre or 0
			Player[id].gold = gold or 0
			Player[id].energy = energy or 0
			msg2(id,"©000255000Your save has been loaded correctly.@C")
			file:close()
		else
			msg2(id,"©255000000Failed to load your save.@C")
			Player[id].level = 1
			Player[id].exp = 0
			Player[id].credits = 0
			Player[id].gold = 0
			Player[id].energy = 0
		end
	else
		msg2(id,"©255000000You are not logged in. Please register an account at UnrealSoftware.de@C")
		Player[id].level = 1
		Player[id].exp = 0
		Player[id].credits = 0
		Player[id].gold = 0
		Player[id].energy = 0
	end
end
function _savestats(id)
	local usgn = player(id,"usgn")
	if usgn > 0 then
		local file = io.open("sys/lua/saves/"..usgn.."MB.txt","w")
		local lvl = Player[id].level
		local xp = Player[id].exp
		local cre = Player[id].credits
		local gold = Player[id].gold
		local energy = Player[id].energy
		file:write(lvl.."\n"..xp.."\n"..cre.."\n"..gold.."\n"..energy)
		file:close()
	end
end