[Half-Life AMXX] / adminchat.sma Repository:
ViewVC logotype

Annotation of /adminchat.sma

Parent Directory Parent Directory | Revision Log Revision Log


Revision 17 - (view) (download)

1 : ian 1 /* AMX Mod X
2 :     * Admin Chat Plugin
3 :     *
4 :     * by the AMX Mod X Development Team
5 :     * originally developed by OLO
6 :     *
7 :     * This file is part of AMX Mod X.
8 :     *
9 :     *
10 :     * This program is free software; you can redistribute it and/or modify it
11 :     * under the terms of the GNU General Public License as published by the
12 :     * Free Software Foundation; either version 2 of the License, or (at
13 :     * your option) any later version.
14 :     *
15 :     * This program is distributed in the hope that it will be useful, but
16 :     * WITHOUT ANY WARRANTY; without even the implied warranty of
17 :     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 :     * General Public License for more details.
19 :     *
20 :     * You should have received a copy of the GNU General Public License
21 :     * along with this program; if not, write to the Free Software Foundation,
22 :     * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 :     *
24 :     * In addition, as a special exception, the author gives permission to
25 :     * link the code of this program with the Half-Life Game Engine ("HL
26 :     * Engine") and Modified Game Libraries ("MODs") developed by Valve,
27 :     * L.L.C ("Valve"). You must obey the GNU General Public License in all
28 :     * respects for all of the code used other than the HL Engine and MODs
29 :     * from Valve. If you modify this file, you may extend this exception
30 :     * to your version of the file, but you are not obligated to do so. If
31 :     * you do not wish to do so, delete this exception statement from your
32 :     * version.
33 :     */
34 :    
35 :     #include <amxmodx>
36 :     #include <amxmisc>
37 :    
38 :     new g_msgChannel
39 :    
40 :     #define MAX_CLR 10
41 :    
42 :     new g_Colors[MAX_CLR][] = {"COL_WHITE", "COL_RED", "COL_GREEN", "COL_BLUE", "COL_YELLOW", "COL_MAGENTA", "COL_CYAN", "COL_ORANGE", "COL_OCEAN", "COL_MAROON"}
43 :     new g_Values[MAX_CLR][] = {{255, 255, 255}, {255, 0, 0}, {0, 255, 0}, {0, 0, 255}, {255, 255, 0}, {255, 0, 255}, {0, 255, 255}, {227, 96, 8}, {45, 89, 116}, {103, 44, 38}}
44 :     new Float:g_Pos[4][] = {{0.0, 0.0}, {0.05, 0.55}, {-1.0, 0.2}, {-1.0, 0.7}}
45 :    
46 : ian 17 new amx_show_activity;
47 : ian 1 public plugin_init()
48 :     {
49 :     register_plugin("Admin Chat", AMXX_VERSION_STR, "AMXX Dev Team")
50 :     register_dictionary("adminchat.txt")
51 :     register_dictionary("common.txt")
52 :     register_clcmd("say", "cmdSayChat", ADMIN_CHAT, "@[@|@|@][w|r|g|b|y|m|c]<text> - displays hud message")
53 :     register_clcmd("say_team", "cmdSayAdmin", 0, "@<text> - displays message to admins")
54 :     register_concmd("amx_say", "cmdSay", ADMIN_CHAT, "<message> - sends message to all players")
55 :     register_concmd("amx_chat", "cmdChat", ADMIN_CHAT, "<message> - sends message to admins")
56 :     register_concmd("amx_psay", "cmdPsay", ADMIN_CHAT, "<name or #userid> <message> - sends private message")
57 :     register_concmd("amx_tsay", "cmdTsay", ADMIN_CHAT, "<color> <message> - sends left side hud message to all players")
58 :     register_concmd("amx_csay", "cmdTsay", ADMIN_CHAT, "<color> <message> - sends center hud message to all players")
59 : ian 17
60 :     amx_show_activity = get_cvar_pointer("amx_show_activity");
61 :    
62 :     if (amx_show_activity == 0)
63 :     {
64 :     amx_show_activity = register_cvar("amx_show_activity", "2");
65 :     }
66 : ian 1 }
67 :    
68 :     public cmdSayChat(id)
69 :     {
70 :     if (!access(id, ADMIN_CHAT))
71 :     {
72 :     return PLUGIN_CONTINUE
73 :     }
74 :    
75 :     new said[6], i = 0
76 :     read_argv(1, said, 5)
77 :    
78 :     while (said[i] == '@')
79 :     {
80 :     i++
81 :     }
82 :    
83 :     if (!i || i > 3)
84 :     {
85 :     return PLUGIN_CONTINUE
86 :     }
87 :    
88 :     new message[192], a = 0
89 :     read_args(message, 191)
90 :     remove_quotes(message)
91 :    
92 :     switch (said[i])
93 :     {
94 :     case 'r': a = 1
95 :     case 'g': a = 2
96 :     case 'b': a = 3
97 :     case 'y': a = 4
98 :     case 'm': a = 5
99 :     case 'c': a = 6
100 :     case 'o': a = 7
101 :     }
102 :    
103 :     new n, s = i
104 :     if (a)
105 :     {
106 :     n++
107 :     s++
108 :     }
109 :     while (said[s] && isspace(said[s]))
110 :     {
111 :     n++
112 :     s++
113 :     }
114 :    
115 :    
116 :     new name[32], authid[32], userid
117 :    
118 :     get_user_authid(id, authid, 31)
119 :     get_user_name(id, name, 31)
120 :     userid = get_user_userid(id)
121 :    
122 :     log_amx("Chat: ^"%s<%d><%s><>^" tsay ^"%s^"", name, userid, authid, message[i + n])
123 :     log_message("^"%s<%d><%s><>^" triggered ^"amx_tsay^" (text ^"%s^") (color ^"%L^")", name, userid, authid, message[i + n], "en", g_Colors[a])
124 :    
125 :     if (++g_msgChannel > 6 || g_msgChannel < 3)
126 :     {
127 :     g_msgChannel = 3
128 :     }
129 :    
130 :     new Float:verpos = g_Pos[i][1] + float(g_msgChannel) / 35.0
131 :    
132 :     set_hudmessage(g_Values[a][0], g_Values[a][1], g_Values[a][2], g_Pos[i][0], verpos, 0, 6.0, 6.0, 0.5, 0.15, -1)
133 :    
134 : ian 17 switch ( get_pcvar_num(amx_show_activity) )
135 : ian 1 {
136 : ian 17 case 3, 4:
137 :     {
138 :     new maxpl = get_maxplayers();
139 :     for (new pl = 1; pl <= maxpl; pl++)
140 :     {
141 :     if (is_user_connected(pl) && !is_user_bot(pl))
142 :     {
143 :     if (is_user_admin(pl))
144 :     {
145 :     show_hudmessage(pl, "%s : %s", name, message[i + n])
146 :     client_print(pl, print_notify, "%s : %s", name, message[i + n])
147 :     }
148 :     else
149 :     {
150 :     show_hudmessage(pl, "%s", message[i + n])
151 :     client_print(pl, print_notify, "%s", message[i + n])
152 :     }
153 :     }
154 :     }
155 :     }
156 :     case 2:
157 :     {
158 :     show_hudmessage(0, "%s : %s", name, message[i + n])
159 :     client_print(0, print_notify, "%s : %s", name, message[i + n])
160 :     }
161 :     default:
162 :     {
163 :     show_hudmessage(0, "%s", message[i + n])
164 :     client_print(0, print_notify, "%s", message[i + n])
165 :     }
166 : ian 1 }
167 :    
168 :     return PLUGIN_HANDLED
169 :     }
170 :    
171 :     public cmdSayAdmin(id)
172 :     {
173 :     new said[2]
174 :     read_argv(1, said, 1)
175 :    
176 :     if (said[0] != '@')
177 :     return PLUGIN_CONTINUE
178 :    
179 :     new message[192], name[32], authid[32], userid
180 :     new players[32], inum
181 :    
182 :     read_args(message, 191)
183 :     remove_quotes(message)
184 :     get_user_authid(id, authid, 31)
185 :     get_user_name(id, name, 31)
186 :     userid = get_user_userid(id)
187 :    
188 :     log_amx("Chat: ^"%s<%d><%s><>^" chat ^"%s^"", name, userid, authid, message[1])
189 :     log_message("^"%s<%d><%s><>^" triggered ^"amx_chat^" (text ^"%s^")", name, userid, authid, message[1])
190 :    
191 :     if (is_user_admin(id))
192 :     format(message, 191, "(%L) %s : %s", id, "ADMIN", name, message[1])
193 :     else
194 :     format(message, 191, "(%L) %s : %s", id, "PLAYER", name, message[1])
195 :    
196 :     get_players(players, inum)
197 :    
198 :     for (new i = 0; i < inum; ++i)
199 :     {
200 :     // dont print the message to the client that used the cmd if he has ADMIN_CHAT to avoid double printing
201 :     if (players[i] != id && get_user_flags(players[i]) & ADMIN_CHAT)
202 :     client_print(players[i], print_chat, "%s", message)
203 :     }
204 :    
205 :     client_print(id, print_chat, "%s", message)
206 :    
207 :     return PLUGIN_HANDLED
208 :     }
209 :    
210 :     public cmdChat(id, level, cid)
211 :     {
212 :     if (!cmd_access(id, level, cid, 2))
213 :     return PLUGIN_HANDLED
214 :    
215 :     new message[192], name[32], players[32], inum, authid[32], userid
216 :    
217 :     read_args(message, 191)
218 :     remove_quotes(message)
219 :     get_user_authid(id, authid, 31)
220 :     get_user_name(id, name, 31)
221 :     userid = get_user_userid(id)
222 :     get_players(players, inum)
223 :    
224 :     log_amx("Chat: ^"%s<%d><%s><>^" chat ^"%s^"", name, userid, authid, message)
225 :     log_message("^"%s<%d><%s><>^" triggered ^"amx_chat^" (text ^"%s^")", name, userid, authid, message)
226 :    
227 :     format(message, 191, "(ADMINS) %s : %s", name, message)
228 :     console_print(id, "%s", message)
229 :    
230 :     for (new i = 0; i < inum; ++i)
231 :     {
232 :     if (access(players[i], ADMIN_CHAT))
233 :     client_print(players[i], print_chat, "%s", message)
234 :     }
235 :    
236 :     return PLUGIN_HANDLED
237 :     }
238 :    
239 :     public cmdSay(id, level, cid)
240 :     {
241 :     if (!cmd_access(id, level, cid, 2))
242 :     return PLUGIN_HANDLED
243 :    
244 :     new message[192], name[32], authid[32], userid
245 :    
246 :     read_args(message, 191)
247 :     remove_quotes(message)
248 :     get_user_authid(id, authid, 31)
249 :     get_user_name(id, name, 31)
250 :     userid = get_user_userid(id)
251 :     client_print(0, print_chat, "%L", LANG_PLAYER, "PRINT_ALL", name, message)
252 :     console_print(id, "%L", LANG_PLAYER, "PRINT_ALL", name, message)
253 :    
254 :     log_amx("Chat: ^"%s<%d><%s><>^" say ^"%s^"", name, userid, authid, message)
255 :     log_message("^"%s<%d><%s><>^" triggered ^"amx_say^" (text ^"%s^")", name, userid, authid, message)
256 :    
257 :     return PLUGIN_HANDLED
258 :     }
259 :    
260 :     public cmdPsay(id, level, cid)
261 :     {
262 :     if (!cmd_access(id, level, cid, 3))
263 :     return PLUGIN_HANDLED
264 :    
265 :     new name[32]
266 :     read_argv(1, name, 31)
267 :     new priv = cmd_target(id, name, 0)
268 :    
269 :     if (!priv)
270 :     return PLUGIN_HANDLED
271 :    
272 : ian 17 new length = strlen(name) + 1
273 :    
274 : ian 1 get_user_name(priv, name, 31);
275 :    
276 :     new message[192], name2[32], authid[32], authid2[32], userid, userid2
277 :    
278 :     get_user_authid(id, authid, 31)
279 :     get_user_name(id, name2, 31)
280 :     userid = get_user_userid(id)
281 :     read_args(message, 191)
282 :    
283 :     if (message[0] == '"' && message[length] == '"') // HLSW fix
284 :     {
285 :     message[0] = ' '
286 :     message[length] = ' '
287 :     length += 2
288 :     }
289 :    
290 :     remove_quotes(message[length])
291 :     get_user_name(priv, name, 31)
292 :    
293 :     if (id && id != priv)
294 :     client_print(id, print_chat, "(%s) %s : %s", name, name2, message[length])
295 :    
296 :     client_print(priv, print_chat, "(%s) %s : %s", name, name2, message[length])
297 :     console_print(id, "(%s) %s : %s", name, name2, message[length])
298 :     get_user_authid(priv, authid2, 31)
299 :     userid2 = get_user_userid(priv)
300 :    
301 :     log_amx("Chat: ^"%s<%d><%s><>^" psay ^"%s<%d><%s><>^" ^"%s^"", name2, userid, authid, name, userid2, authid2, message[length])
302 :     log_message("^"%s<%d><%s><>^" triggered ^"amx_psay^" against ^"%s<%d><%s><>^" (text ^"%s^")", name2, userid, authid, name, userid2, authid2, message[length])
303 :    
304 :     return PLUGIN_HANDLED
305 :     }
306 :    
307 :     public cmdTsay(id, level, cid)
308 :     {
309 :     if (!cmd_access(id, level, cid, 3))
310 :     return PLUGIN_HANDLED
311 :    
312 :     new cmd[16], color[16], color2[16], message[192], name[32], authid[32], userid = 0
313 :    
314 :     read_argv(0, cmd, 15)
315 :     new bool:tsay = (tolower(cmd[4]) == 't')
316 :    
317 :     read_args(message, 191)
318 :     remove_quotes(message)
319 :     parse(message, color, 15)
320 :    
321 :     new found = 0, a = 0
322 :     new lang[3], langnum = get_langsnum()
323 :    
324 :     for (new i = 0; i < MAX_CLR; ++i)
325 :     {
326 :     for (new j = 0; j < langnum; j++)
327 :     {
328 :     get_lang(j, lang)
329 :     format(color2, 15, "%L", lang, g_Colors[i])
330 :    
331 :     if (equali(color, color2))
332 :     {
333 :     a = i
334 :     found = 1
335 :     break
336 :     }
337 :     }
338 :     if (found == 1)
339 :     break
340 :     }
341 :    
342 :     new length = found ? (strlen(color) + 1) : 0
343 :    
344 :     if (++g_msgChannel > 6 || g_msgChannel < 3)
345 :     g_msgChannel = 3
346 :    
347 :     new Float:verpos = (tsay ? 0.55 : 0.1) + float(g_msgChannel) / 35.0
348 :    
349 :     get_user_authid(id, authid, 31)
350 :     get_user_name(id, name, 31)
351 :     userid = get_user_userid(id)
352 :     set_hudmessage(g_Values[a][0], g_Values[a][1], g_Values[a][2], tsay ? 0.05 : -1.0, verpos, 0, 6.0, 6.0, 0.5, 0.15, -1)
353 :    
354 : ian 17 switch ( get_pcvar_num(amx_show_activity) )
355 : ian 1 {
356 : ian 17 case 3, 4:
357 :     {
358 :     new maxpl = get_maxplayers();
359 :     for (new pl = 1; pl <= maxpl; pl++)
360 :     {
361 :     if (is_user_connected(pl) && !is_user_bot(pl))
362 :     {
363 :     if (is_user_admin(pl))
364 :     {
365 :     show_hudmessage(pl, "%s : %s", name, message[length])
366 :     client_print(pl, print_notify, "%s : %s", name, message[length])
367 :     }
368 :     else
369 :     {
370 :     show_hudmessage(pl, "%s", message[length])
371 :     client_print(pl, print_notify, "%s", message[length])
372 :     }
373 :     }
374 :     }
375 :     console_print(id, "%s : %s", name, message[length])
376 :     }
377 :     case 2:
378 :     {
379 :     show_hudmessage(0, "%s : %s", name, message[length])
380 :     client_print(0, print_notify, "%s : %s", name, message[length])
381 :     console_print(id, "%s : %s", name, message[length])
382 :     }
383 :     default:
384 :     {
385 :     show_hudmessage(0, "%s", message[length])
386 :     client_print(0, print_notify, "%s", message[length])
387 :     console_print(id, "%s", message[length])
388 :     }
389 : ian 1 }
390 :    
391 :     log_amx("Chat: ^"%s<%d><%s><>^" %s ^"%s^"", name, userid, authid, cmd[4], message[length])
392 :     log_message("^"%s<%d><%s><>^" triggered ^"%s^" (text ^"%s^") (color ^"%s^")", name, userid, authid, cmd, message[length], color2)
393 :    
394 :     return PLUGIN_HANDLED
395 :     }

Contact
ViewVC Help
Powered by ViewVC 1.0.4