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
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
if flacko==nil then flacko={} end
flacko.admins={}
usersfiledir_="sys/lua/flacko/database/users.txt"
function toTable(t,match) --By leegao--
	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
function clearfile(filedir)
	local clear = assert(io.open(filedir,"w"))
	clear:write()
	clear:close()
end
function flacko.admins.message(color,txt,center)
	if(center==0) then
		parse("msg ©"..color..txt)
	elseif(center==1) then
		parse("msg ©"..color..txt.."@C")
	end
	--PARAMETERS: 1-RGB| 2-Text| 3-Centered?
end
function initArray(m,t)
	local array = {}
	for i = 1, m do
		array[i]=t
	end
	return array
end
function flacko.admins.savedata(filedir,id)
	if(flacko.admins.loggedin[id] and player(id,"usgn")>0) then
		local usgn = player(id,"usgn")
	
		local file = assert(io.open(filedir,"r"))
		database = file:read("*all")
		file:close()
		
		local linestable = {}
		local count = 0
		for line in database:lines() do
			linestable[count] = line
		end
			
		local wordsinline = toTable(linestable[flacko.admins.usernumber[id]])
	
		if(linestable[flacko.admins.usernumber[id]]~=nil) then
			clearfile(filedir)
	
			local appendrewrite = assert(io.open(filedir,"a"))
			for i=1,#linestable do
				if(i+1~=flacko.admins.usernumber[id]) then
					appendrewrite:write(linestable[i],"\n")
				elseif (i+1 == flacko.admins.usernumber[id]) then
					appendrewrite:write(usgn," ",flacko.admins.playerpower[id]," ",flacko.admins.colors[id]," ",flacko.admins.autosay[id]," ",flacko.admins.loggedin[id],"\n")
				end
			end
			appendrewrite:close()
			return 1
		else
		print("ERROR WHILE SAVING DATA!")
		return nil
		end
	end
end
function loginuser(filedir,id)
	local usgn = player(id,"usgn")
	counter = 1
	for line in io.lines(filedir) do
		local parses = toTable(line)
		counter = counter+1
		if (tonumber(parses[1])==usgn) then
			flacko.admins.playerpower[id] = tonumber(parses[2])
			flacko.admins.colors[id] = parses[3]
			flacko.admins.autosay[id] = tonumber(parses[4])
			parse("sv_msg2 "..id.." Logged in as "..parses[5])
			flacko.admins.loggedin[id]=parses[5]
			flacko.admins.usernumber[id] = counter
			break
		end
	end
end
function flacko.admins.help1menu(id)
	menu(id,"Help #1,War Machine,Ninja,Calibur,Bomber,Sniper,Engineer,Commander")
end
flacko.admins.playerpower = initArray(32,0)
flacko.admins.colors = initArray(32,"050150255")
flacko.admins.autosay = initArray(32,0)
flacko.admins.usernumber = initArray(32,0)
flacko.admins.loggedin = initArray(32,nil)
addhook("say","flacko.admins.say")
function flacko.admins.say(id,txt)
	if(string.sub(txt,0,1)=="!") then
		local text = toTable(txt)
		
		if(text[1]=="!login") then --Logs in with user
			if(player(id,"usgn")>0) then
				loginuser(usersfiledir_,id)
				return 1
			end
		end
		
		if(text[1]=="!changecolor") then --Changecolor(Vip,Mod,Admin)
			if(flacko.admins.playerpower[id]>0) then
				flacko.admins.colors[id]= text[2]
				if(string.len(flacko.admins.colors[id])~=9) then
					flacko.admins.colors[id]=000255000
				end
				if(flacko.admins.colors[id]==nil) then
					flacko.admins.colors[id] = 000255000
				end
				return 1
			end
		end
		
		if(text[1]=="!restart") then --Restart(Mod,Admin)
			if(flacko.admins.playerpower[id]>1) then
				parse("restart")
				return 1
			end
		end
		if(text[1]=="!register") then --Register a new user
			if(player(id,"usgn")>0 and text[2]) then
				local usgnid = player(id,"usgn")
				local fid = assert(io.open("sys/lua/flacko/database/users.txt","a"))
				if(fid~=nil) then
					fid:write(usgnid," 1 128128128 1 ",text[2],"\n")
					fid:close()
					parse("sv_msg2 "..id.." User '"..text[2].."' created!")
				end
				return 1
			end
		end			
			
		if(text[1]== "!say") then --Toggle autosay(VIP,MOD and ADMIN)
			if(flacko.admins.playerpower[id]>0) then
				if(flacko.admins.autosay[id]==0) then
					flacko.admins.autosay[id] = 1
				elseif(flacko.admins.autosay[id]==1) then
					flacko.admins.autosay[id] = 0
				end
				return 1
			end
		end
		
		if(text[1]=="!byteam") then
			if(flacko.admins.playerpower[id]>1) then
				for i=1,32 do
					if(player(i,"exists")) then
						local name = player(i,"name")
						local nlength1 = string.len(text[2])
						
						if text[3] then
							local nlength2 = string.len(text[3])
						end
						
						if(string.sub(name,0,nlength1) == text[2]) then
							parse("maket "..i)
						
						elseif(string.sub(name,0,nlength2) == text[3]) then
							parse("makect "..i)
						end
					end
				end
				return 1
			end
		end		
		
		if(text[1]=="!swapteams") then --Invert teams (Mods & Admins)
			if(flacko.admins.playerpower[id]>1) then
				for i=1,32 do
					if(player(i,"team")==1) then
						parse("makect "..i)
				
					elseif(player(i,"team")==2) then
						parse("maket "..i)
					end
				end
				return 1
			end
		end
		
		if(text[1]=="!ban") then
			if(flacko.admins.playerpower[id]==3) then -- Banname (Admin)
				flacko.admins.message("000255255",player(id,"name").." has banned "..player(text[2],"name"),0)
				parse("banname "..text[2])
				return 1
			end
		end
			
		if(text[1]=="!changeteam") then --Change team (Mod & Admin)
			if(flacko.admins.playerpower[id]>1) then
				if(text[3]=="1") then
					parse("maket "..text[2])
				elseif(text[3]=="2") then
					parse("makect "..text[2])
				elseif(text[3]=="3") then
					parse("makespec "..text[2])
				end
				return 1
			end
		end
		
		if(text[1]=="!kick") then --Kick (Mods and Admins)
			if(flacko.admins.playerpower[id]>1) then
				flacko.admins.message("000255255",player(id,"name").." has kicked "..player(text[2],"name"),0)
				parse("kick "..text[2])
			end
			return 1
		end
		
		if(text[1]=="!save") then --Saves data
			flacko.admins.savedata(usersfiledir_,id)
			if(flacko.admins.savedata(usersfiledir_,id)==1) then
				parse("sv_msg2 "..id.." Saved!")
				return 1
			end
		end
		
		if(text[1]=="!map") then --Change map (Admins only)
			if(flacko.admins.playerpower[id]==3) then
				message = string.gsub(txt,"!map ","")
				parse("sv_map "..message)
			end
		end
	end
	
	if(flacko.admins.autosay[id]==1) then
		if(flacko.admins.playerpower[id]==2) then
			flacko.admins.message(flacko.admins.colors[id],player(id,"name").."(MOD): "..txt,0)
			return 1
		elseif(flacko.admins.playerpower[id]==3) then
			flacko.admins.message(flacko.admins.colors[id],player(id,"name").."(ADMIN): "..txt,0)
			return 1
		elseif(flacko.admins.playerpower[id]==1) then
			flacko.admins.message(flacko.admins.colors[id],player(id,"name").."(VIP): "..txt,0)
			return 1
		end
	end
end
addhook("leave","flacko.admins.leave")
function flacko.admins.leave(id)
	flacko.admins.savedata(usersfiledir_,id)
	flacko.admins.playerpower[id] = 0
	flacko.admins.colors[id]= "050150255"
	flacko.admins.autosay[id] = 0
	flacko.admins.usernumber[id] = 0
	flacko.admins.loggedin[id]=nil
end
addhook("join","flacko.admins.join")
function flacko.admins.join(id)
	if(player(id,"usgn")>0) then
		loginuser(usersfiledir_,id)
	end
end