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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
-- Modified by BCG2000
function initArray(length,mode)
local array = {}
for i = 1,length do
array[i] = mode
end
return array
end
function string_split(str,pattern)
local entry = {}
for str in string.gmatch(str,pattern) do
if str ~= "" then
table.insert(entry,str)
end
end
return entry
end
function is_file(filename)
local file = io.open(filename)
if file then
io.close(file)
return true
end
return false
end
function create_user(uid)
local usgn = get_usgn(uid)
local steamid = get_steamid(uid)
	 local pid = 0
	if steamid ~= 0 then
pid = steamid
else
pid = usgn
end
	
	 local path = saves_folder..pid..".txt"
if not is_file(path) then
file = io.open(path,"w")
file : write("maxexp="..p_maxexp[uid].."\n".."level="..p_level[uid].."\n".."rank="..p_rank[uid].."\n".."exp="..p_exp[uid].."\n")
file : close()
print("The user "..pid.." was created successfully.")
else
print("The user "..pid.." already exists in the database.")
end
end
function refresh_user(uid)
local usgn = get_usgn(uid)
local steamid = get_steamid(uid)
	 local pid = 0
	if steamid ~= 0 then
pid = steamid
else
pid = usgn
end
	
	 local path = saves_folder..pid..".txt"
if is_file(path) then
file = io.open(path,"w")
file : write("maxexp="..p_maxexp[uid].."\n".."level="..p_level[uid].."\n".."rank="..p_rank[uid].."\n".."exp="..p_exp[uid].."\n")
file : close()
print("The user "..pid.." successfully updated.")
else
print("The user "..pid.." does not exist in the database.")
end
end
function isPlayer(uid)
return player(uid,"exists")
end
function playerInScreen(uid,player)
x,y = get_pos(uid)
px,py = get_pos(player)
if px - x > 320 or py - y > 240 then
return false
else
return true
end
end
function get_pos(uid)
return player(uid,"x"),player(uid,"y")
end
function get_name(uid)
return player(uid,"name")
end
function get_usgn(uid)
return player(uid,"usgn")
end
function get_steamid(uid)
	if player(uid,"steamid") ~= "0" then
		return tonumber(player(uid,"steamid"))
	end
	return 0
end
function get_ip(uid)
return player(uid,"ip")
end
function reset_flags(uid)
p_maxexp[uid] = 1500
p_level[uid] = 1
p_rank[uid] = "S1"
p_exp[uid] = 0
end
function set_flags(uid)
local usgn = get_usgn(uid)
local steamid = get_steamid(uid)
local name = get_name(uid)
	 local pid = 0
if steamid ~= 0 then
pid = steamid
else
pid = usgn
end
	 local path = saves_folder..pid..".txt"
p_usgn[uid] = pid -- Incorrect global variable name, ignore to avoid changing the rest of the script.
if is_file(path) then
local file = io.open(path,"r")
local temp = {}
for line in file:lines() do
local temp = string_split(line,"[^=]*")
if temp[1] == "maxexp" then p_maxexp[uid] = tonumber(temp[2]) end
if temp[1] == "level" then p_level[uid] = tonumber(temp[2]) end
if temp[1] == "rank" then p_rank[uid] = tostring(temp[2]) end
if temp[1] == "exp" then p_exp[uid] = tonumber(temp[2]) end
end
file : close()
msg2(uid,"©210235255Welcome back! Your save file has been loaded successfully!")
elseif usgn ~= 0 or steamid ~= 0 then
create_user(uid)
msg2(uid,"©210235255Welcome! Your save file has been created successfully!")
else
msg2(uid,"©210235255You are not logged in on USGN or Steam. Your progress will not be saved.")
end
end
function refresh_hud(uid)
hud_txt2(uid,1,"©210235255 Points: "..p_exp[uid].."/"..p_maxexp[uid],2,223,0)
--hud_txt2(uid,2,"©255255255 Usgn: "..player(uid,"usgn"),2,130,0)
--hud_txt2(uid,3,"©255255255 Level: "..p_level[uid],2,145,0)
hud_txt2(uid,4,"©210235255 Rank: "..p_rank[uid],2,208,0)
end
function get_max_xp(level)
max_xp=(level*1000*1.5)
return max_xp
end
function check_level(uid)
if p_exp[uid] >= p_maxexp[uid] then
p_level[uid]=p_level[uid]+1
p_exp[uid]=0
local x,y = get_pos(uid)
local level = p_level[uid]
if levelname[level] then
p_rank[uid] = levelname[level]
msg2(uid,"©210235255Congratulations! "..name.." was promoted to "..p_rank[uid]..".")
end
p_maxexp[uid]=get_max_xp(level)
effect("flare",x,y,48,48,210,235,255)
--msg2(uid,"©210235255You just passed the level "..(level-1).." to level "..level..".")
end
end
function hud_txt2(uid,id,text,x,y,align)
parse("hudtxt2 "..uid.." "..id.." \""..text.."\" "..x.." "..y.." "..align)
end
function effect(name,x,y,radius,amount,r,g,b)
parse("effect \""..name.."\" "..x.." "..y.." "..radius.." "..amount.." "..r.." "..g.." "..b)
end
edited 3×, last 16.03.18 04:27:01 am
Save USGN/Steam rank script
1 
Offline
SQ