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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
function initArray(m)
local array = {}
for i = 1, m do
array[i]=0
end
return array
end
level=initArray(32)
exp=initArray(32)
function string.split(text,b)
local cmd = {}
if b then
b = b
else
b = "%s"
end
b = "[^"..b.."]+"
for o in string.gmatch(text,b) do
table.insert(cmd,o)
end
return cmd
end
function totable(t,match)
local cmd = {}
if not match then match = "[^%s]+" end
for word in string.gmatch(t, match) do
table.insert(cmd, word)
end
return cmd
end
addhook("ms100","save_hud")
function save_hud()
for id = 1,32 do
if (player(id,"exists")) then
parse('hudtxt2 '..id..' 48 "\169255255128[..]-\169255255255 LEVEL : \169255255000'..level[id]..' " 13 190')
parse('hudtxt2 '..id..' 49 "\169255255128[..]-\169255255255 EXP : \169255255000'..exp[id]..'/30 " 13 210')
end
end
end
addhook("kill","save_kill")
function save_kill(id)
exp[id] = exp[id] + 1
if exp[id] == 30 then
exp[id]=0
level[id]=level[id]+1
parse("sv_sound2 "..id.." levelup.wav")
msg("\169000255000[LEVEL-UP]:\169255255255 "..player(id,"name").." Reached "..level[id].." level!")
end
end
addhook("leave","save_leave") -- When you leave it saves
function save_leave(id)
if (player(id,"usgn")>0) then
io.output(io.open("sys/lua/saves/"..player(id,"usgn")..".txt","w+"))
io.write(exp[id].." "..level[id])
io.close()
end
end
addhook("die","save_die") -- When you die it saves
function save_die(id)
if (player(id,"usgn")>0) then
io.output(io.open("sys/lua/saves/"..player(id,"usgn")..".txt","w+"))
io.write(exp[id].." "..level[id])
io.close()
elseif (player(id,"steam")>"0") then
io.output(io.open("sys/lua/saves/steam/"..player(id,"usgn")..".txt","w+"))
io.write(exp[id].." "..level[id])
io.close()
end
end
addhook("join","save_join") -- When join load
function save_join(id)
if (player(id,"usgn")>0) then
local filename = "sys/lua/saves/%s.txt"
local file = io.open(filename:format(player(id,"usgn"), "r"))
local line
if not file then
line = {0, 1}
msg2(id,"\169255255000[SERVER]\169255255255: \169255000000Failed to save!")
else
line = file:read("*a"):split()
end
elseif (player(id,"steam")>"0") then
local filename = "sys/lua/saves/steam/%s.txt"
local file = io.open(filename:format(player(id,"steam"), "r"))
local line
if not file then
line = {0, 1}
msg2(id,"\169255255000[SERVER]\169255255255: \169255000000Failed to save!")
else
line = file:read("*a"):split()
end
exp[id] = tonumber(line[1]) or 0 -- If line[1] is not a number, level[id] becomes 1
level[id] = tonumber(line[2]) or 1 -- Same as above reasoning (prevents errors)
else
msg2(id,"\169255255000[SERVER]: \169255000000Please make sure that you are logged in USGN / Steam!")
level[id]=1
end
end