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

Annotation of /adminvote.sma

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1 - (view) (download)

1 : ian 1 /* AMX Mod X
2 :     * Admin Votes 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_Answer[128]
39 :     new g_optionName[4][32]
40 :     new g_voteCount[4]
41 :     new g_validMaps
42 :     new g_yesNoVote
43 :     new g_coloredMenus
44 :     new g_voteCaller
45 :     new g_Execute[256]
46 :     new g_execLen
47 :    
48 :     new bool:g_execResult
49 :     new Float:g_voteRatio
50 :    
51 :     public plugin_init()
52 :     {
53 :     register_plugin("Admin Votes", AMXX_VERSION_STR, "AMXX Dev Team")
54 :     register_dictionary("adminvote.txt")
55 :     register_dictionary("common.txt")
56 :     register_dictionary("mapsmenu.txt")
57 :     register_menucmd(register_menuid("Change map to "), MENU_KEY_1|MENU_KEY_2, "voteCount")
58 :     register_menucmd(register_menuid("Choose map: "), MENU_KEY_1|MENU_KEY_2|MENU_KEY_3|MENU_KEY_4, "voteCount")
59 :     register_menucmd(register_menuid("Kick "), MENU_KEY_1|MENU_KEY_2, "voteCount")
60 :     register_menucmd(register_menuid("Ban "), MENU_KEY_1|MENU_KEY_2, "voteCount")
61 :     register_menucmd(register_menuid("Vote: "), MENU_KEY_1|MENU_KEY_2, "voteCount")
62 :     register_menucmd(register_menuid("The result: "), MENU_KEY_1|MENU_KEY_2, "actionResult")
63 :     register_concmd("amx_votemap", "cmdVoteMap", ADMIN_VOTE, "<map> [map] [map] [map]")
64 :     register_concmd("amx_votekick", "cmdVoteKickBan", ADMIN_VOTE, "<name or #userid>")
65 :     register_concmd("amx_voteban", "cmdVoteKickBan", ADMIN_VOTE, "<name or #userid>")
66 :     register_concmd("amx_vote", "cmdVote", ADMIN_VOTE, "<question> <answer#1> <answer#2>")
67 :     register_concmd("amx_cancelvote", "cmdCancelVote", ADMIN_VOTE, "- cancels last vote")
68 :    
69 :     g_coloredMenus = colored_menus()
70 :     }
71 :    
72 :     public cmdCancelVote(id, level, cid)
73 :     {
74 :     if (!cmd_access(id, level, cid, 0))
75 :     return PLUGIN_HANDLED
76 :    
77 :     if (task_exists(99889988, 1))
78 :     {
79 :     new authid[32], name[32]
80 :    
81 :     get_user_authid(id, authid, 31)
82 :     get_user_name(id, name, 31)
83 :     log_amx("Vote: ^"%s<%d><%s><>^" cancel vote session", name, get_user_userid(id), authid)
84 :    
85 :     new players[32], pnum, lTag[16], activity = get_cvar_num("amx_show_activity")
86 :     get_players(players, pnum, "c")
87 :    
88 :     for (new i = 0; i < pnum;i ++)
89 :     {
90 :     format(lTag, 15, "%L", players[i], is_user_admin(id) ? "ADMIN" : "PLAYER")
91 :     switch (activity)
92 :     {
93 :     case 2: client_print(players[i], print_chat, "%L", LANG_PLAYER, "ADMIN_CANC_VOTE_2", lTag, name)
94 :     case 1: client_print(players[i], print_chat, "%L", LANG_PLAYER, "ADMIN_CANC_VOTE_1", lTag)
95 :     }
96 :     }
97 :    
98 :     console_print(id, "%L", id, "VOTING_CANC")
99 :     client_print(0,print_chat,"%L",LANG_PLAYER,"VOTING_CANC")
100 :     remove_task(99889988, 1)
101 :     set_cvar_float("amx_last_voting", get_gametime())
102 :     }
103 :     else
104 :     console_print(id, "%L", id, "NO_VOTE_CANC")
105 :    
106 :     return PLUGIN_HANDLED
107 :     }
108 :    
109 :     public delayedExec(cmd[])
110 :     server_cmd("%s", cmd)
111 :    
112 :     public autoRefuse()
113 :     {
114 :     log_amx("Vote: %L", "en", "RES_REF")
115 :     client_print(0, print_chat, "%L", LANG_PLAYER, "RES_REF")
116 :     }
117 :    
118 :     public actionResult(id, key)
119 :     {
120 :     remove_task(4545454)
121 :    
122 :     switch (key)
123 :     {
124 :     case 0:
125 :     {
126 :     set_task(2.0, "delayedExec", 0, g_Execute, g_execLen)
127 :     log_amx("Vote: %L", "en", "RES_ACCEPTED")
128 :     client_print(0, print_chat, "%L", LANG_PLAYER, "RES_ACCEPTED")
129 :     }
130 :     case 1: autoRefuse()
131 :     }
132 :    
133 :     return PLUGIN_HANDLED
134 :     }
135 :    
136 :     public checkVotes()
137 :     {
138 :     new best = 0
139 :    
140 :     if (!g_yesNoVote)
141 :     {
142 :     for (new a = 0; a < 4; ++a)
143 :     if (g_voteCount[a] > g_voteCount[best])
144 :    
145 :     best = a
146 :     }
147 :    
148 :     new votesNum = g_voteCount[0] + g_voteCount[1] + g_voteCount[2] + g_voteCount[3]
149 :     new iRatio = votesNum ? floatround(g_voteRatio * float(votesNum), floatround_ceil) : 1
150 :     new iResult = g_voteCount[best]
151 :     new players[32], pnum, i
152 :    
153 :     get_players(players, pnum, "c")
154 :    
155 :     if (iResult < iRatio)
156 :     {
157 :     new lVotingFailed[64]
158 :    
159 :     for (i = 0; i < pnum; i++)
160 :     {
161 :     format(lVotingFailed, 63, "%L", players[i], "VOTING_FAILED")
162 :     if (g_yesNoVote)
163 :     client_print(players[i], print_chat, "%L", players[i], "VOTING_RES_1", lVotingFailed, g_voteCount[0], g_voteCount[1], iRatio)
164 :     else
165 :     client_print(players[i], print_chat, "%L", players[i], "VOTING_RES_2", lVotingFailed, iResult, iRatio)
166 :     }
167 :    
168 :     format(lVotingFailed, 63, "%L", "en", "VOTING_FAILED")
169 :     log_amx("Vote: %s (got ^"%d^") (needed ^"%d^")", lVotingFailed, iResult, iRatio)
170 :    
171 :     return PLUGIN_CONTINUE
172 :     }
173 :    
174 :     g_execLen = format(g_Execute, 255, g_Answer, g_optionName[best]) + 1
175 :    
176 :     if (g_execResult)
177 :     {
178 :     g_execResult = false
179 :    
180 :     if (is_user_connected(g_voteCaller))
181 :     {
182 :     new menuBody[512], lTheResult[32], lYes[16], lNo[16]
183 :    
184 :     format(lTheResult, 31, "%L", g_voteCaller, "THE_RESULT")
185 :     format(lYes, 15, "%L", g_voteCaller, "YES")
186 :     format(lNo, 15, "%L", g_voteCaller, "NO")
187 :    
188 :     new len = format(menuBody, 511, g_coloredMenus ? "\y%s: \w%s^n^n" : "%s: %s^n^n", lTheResult, g_Execute)
189 :    
190 :     len += format(menuBody[len], 511 - len, g_coloredMenus ? "\y%L^n\w" : "%L^n", g_voteCaller, "WANT_CONTINUE")
191 :     format(menuBody[len], 511 - len, "^n1. %s^n2. %s", lYes, lNo)
192 :     show_menu(g_voteCaller, 0x03, menuBody, 10, "The result: ")
193 :     set_task(10.0, "autoRefuse", 4545454)
194 :     }
195 :     else
196 :     set_task(2.0, "delayedExec", 0, g_Execute, g_execLen)
197 :     }
198 :    
199 :     new lVotingSuccess[32]
200 :    
201 :     for (i = 0; i < pnum; i++)
202 :     {
203 :     format(lVotingSuccess, 31, "%L", players[i], "VOTING_SUCCESS")
204 :     client_print(players[i], print_chat, "%L", players[i], "VOTING_RES_3", lVotingSuccess, iResult, iRatio, g_Execute)
205 :     }
206 :    
207 :     format(lVotingSuccess, 31, "%L", "en", "VOTING_SUCCESS")
208 :     log_amx("Vote: %s (got ^"%d^") (needed ^"%d^") (result ^"%s^")", lVotingSuccess, iResult, iRatio, g_Execute)
209 :    
210 :     return PLUGIN_CONTINUE
211 :     }
212 :    
213 :     public voteCount(id, key)
214 :     {
215 :     if (get_cvar_num("amx_vote_answers"))
216 :     {
217 :     new name[32]
218 :     get_user_name(id, name, 31)
219 :    
220 :     if (g_yesNoVote)
221 :     client_print(0, print_chat, "%L", LANG_PLAYER, key ? "VOTED_AGAINST" : "VOTED_FOR", name)
222 :     else
223 :     client_print(0, print_chat, "%L", LANG_PLAYER, "VOTED_FOR_OPT", name, key + 1)
224 :     }
225 :     ++g_voteCount[key]
226 :    
227 :     return PLUGIN_HANDLED
228 :     }
229 :    
230 :     public cmdVoteMap(id, level, cid)
231 :     {
232 :     if (!cmd_access(id, level, cid, 2))
233 :     return PLUGIN_HANDLED
234 :    
235 :     new Float:voting = get_cvar_float("amx_last_voting")
236 :     if (voting > get_gametime())
237 :     {
238 :     console_print(id, "%L", id, "ALREADY_VOTING")
239 :     return PLUGIN_HANDLED
240 :     }
241 :    
242 :     if (voting && voting + get_cvar_float("amx_vote_delay") > get_gametime())
243 :     {
244 :     console_print(id, "%L", id, "VOTING_NOT_ALLOW")
245 :     return PLUGIN_HANDLED
246 :     }
247 :    
248 :     new argc = read_argc()
249 :     if (argc > 5) argc = 5
250 :    
251 :     g_validMaps = 0
252 :     g_optionName[0][0] = 0
253 :     g_optionName[1][0] = 0
254 :     g_optionName[2][0] = 0
255 :     g_optionName[3][0] = 0
256 :    
257 :     for (new i = 1; i < argc; ++i)
258 :     {
259 :     read_argv(i, g_optionName[g_validMaps], 31)
260 :    
261 :     if (is_map_valid(g_optionName[g_validMaps]))
262 :     g_validMaps++
263 :     }
264 :    
265 :     if (g_validMaps == 0)
266 :     {
267 :     new lMaps[16]
268 :    
269 :     format(lMaps, 15, "%L", id, (argc == 2) ? "MAP_IS" : "MAPS_ARE")
270 :     console_print(id, "%L", id, "GIVEN_NOT_VALID", lMaps)
271 :     return PLUGIN_HANDLED
272 :     }
273 :    
274 :     new menu_msg[256], len = 0
275 :     new keys = 0
276 :    
277 :     if (g_validMaps > 1)
278 :     {
279 :     keys = MENU_KEY_0
280 :     len = format(menu_msg, 255, g_coloredMenus ? "\y%L: \w^n^n" : "%L: ^n^n", LANG_SERVER, "CHOOSE_MAP")
281 :     new temp[128]
282 :    
283 :     for (new a = 0; a < g_validMaps; ++a)
284 :     {
285 :     format(temp, 127, "%d. %s^n", a+1, g_optionName[a])
286 :     len += copy(menu_msg[len], 255-len, temp)
287 :     keys |= (1<<a)
288 :     }
289 :    
290 :     format(menu_msg[len], 255-len, "^n0. %L", LANG_SERVER, "NONE")
291 :     g_yesNoVote = 0
292 :     } else {
293 :     new lChangeMap[32], lYes[16], lNo[16]
294 :    
295 :     format(lChangeMap, 31, "%L", LANG_SERVER, "CHANGE_MAP_TO")
296 :     format(lYes, 15, "%L", LANG_SERVER, "YES")
297 :     format(lNo, 15, "%L", LANG_SERVER, "NO")
298 :     format(menu_msg, 255, g_coloredMenus ? "\y%s %s?\w^n^n1. %s^n2. %s" : "%s %s?^n^n1. %s^n2. %s", lChangeMap, g_optionName[0], lYes, lNo)
299 :     keys = MENU_KEY_1|MENU_KEY_2
300 :     g_yesNoVote = 1
301 :     }
302 :    
303 :     new authid[32], name[32]
304 :    
305 :     get_user_authid(id, authid, 31)
306 :     get_user_name(id, name, 31)
307 :    
308 :     if (argc == 2)
309 :     log_amx("Vote: ^"%s<%d><%s><>^" vote map (map ^"%s^")", name, get_user_userid(id), authid, g_optionName[0])
310 :     else
311 :     log_amx("Vote: ^"%s<%d><%s><>^" vote maps (map#1 ^"%s^") (map#2 ^"%s^") (map#3 ^"%s^") (map#4 ^"%s^")", name, get_user_userid(id), authid, g_optionName[0], g_optionName[1], g_optionName[2], g_optionName[3])
312 :    
313 :     new lTag[16], activity = get_cvar_num("amx_show_activity")
314 :    
315 :     if (activity > 0)
316 :     {
317 :     new players[32], pnum
318 :    
319 :     get_players(players, pnum, "c")
320 :     for (new i = 0; i < pnum; i++)
321 :     {
322 :     format(lTag, 15, "%L", players[i], is_user_admin(id) ? "ADMIN" : "PLAYER")
323 :    
324 :     switch (activity)
325 :     {
326 :     case 2: client_print(players[i], print_chat, "%L", players[i], "ADMIN_VOTE_MAP_2", lTag, name)
327 :     case 1: client_print(players[i], print_chat, "%L", players[i], "ADMIN_VOTE_MAP_1", lTag)
328 :     }
329 :     }
330 :     }
331 :    
332 :     g_execResult = true
333 :     new Float:vote_time = get_cvar_float("amx_vote_time") + 2.0
334 :    
335 :     set_cvar_float("amx_last_voting", get_gametime() + vote_time)
336 :     g_voteRatio = get_cvar_float("amx_votemap_ratio")
337 :     g_Answer = "changelevel %s"
338 :     show_menu(0, keys, menu_msg, floatround(vote_time), (g_validMaps > 1) ? "Choose map: " : "Change map to ")
339 :     set_task(vote_time, "checkVotes", 99889988)
340 :     g_voteCaller = id
341 :     console_print(id, "%L", id, "VOTING_STARTED")
342 :     g_voteCount = {0, 0, 0, 0}
343 :    
344 :     return PLUGIN_HANDLED
345 :     }
346 :    
347 :     public cmdVote(id, level, cid)
348 :     {
349 :     if (!cmd_access(id, level, cid, 4))
350 :     return PLUGIN_HANDLED
351 :    
352 :     new Float:voting = get_cvar_float("amx_last_voting")
353 :     if (voting > get_gametime())
354 :     {
355 :     console_print(id, "%L", id, "ALREADY_VOTING")
356 :     return PLUGIN_HANDLED
357 :     }
358 :    
359 :     if (voting && voting + get_cvar_float("amx_vote_delay") > get_gametime())
360 :     {
361 :     console_print(id, "%L", id, "VOTING_NOT_ALLOW")
362 :     return PLUGIN_HANDLED
363 :     }
364 :    
365 :     new quest[48]
366 :     read_argv(1, quest, 47)
367 :    
368 :     if ((contain(quest, "sv_password") != -1) || (contain(quest, "rcon_password") != -1) || (contain(quest, "kick") != -1) ||
369 :     (contain(quest, "addip") != -1) || (contain(quest, "ban") != -1))
370 :     {
371 :     console_print(id, "%L", id, "VOTING_FORBIDDEN")
372 :     return PLUGIN_HANDLED
373 :     }
374 :    
375 :     read_argv(2, g_optionName[0], 31)
376 :     read_argv(3, g_optionName[1], 31)
377 :    
378 :     new authid[32], name[32]
379 :    
380 :     get_user_authid(id, authid, 31)
381 :     get_user_name(id, name, 31)
382 :     log_amx("Vote: ^"%s<%d><%s><>^" vote custom (question ^"%s^") (option#1 ^"%s^") (option#2 ^"%s^")", name, get_user_userid(id), authid, quest, g_optionName[0], g_optionName[1])
383 :    
384 :     new activity = get_cvar_num("amx_show_activity")
385 :    
386 :     if (activity > 0)
387 :     {
388 :     new players[32], pnum, lTag[16]
389 :    
390 :     get_players(players, pnum, "c")
391 :     for (new i = 0; i < pnum; i++)
392 :     {
393 :     format(lTag, 15, "%L", players[i], is_user_admin(id) ? "ADMIN" : "PLAYER")
394 :    
395 :     switch (activity)
396 :     {
397 :     case 2: client_print(players[i], print_chat, "%L", players[i], "ADMIN_VOTE_CUS_2", lTag, name)
398 :     case 1: client_print(players[i], print_chat, "%L", players[i], "ADMIN_VOTE_CUS_1", lTag)
399 :     }
400 :     }
401 :     }
402 :    
403 :     new menu_msg[256], lVote[16]
404 :    
405 :     format(lVote, 15, "%L", LANG_SERVER, "VOTE")
406 :     new keys = MENU_KEY_1|MENU_KEY_2
407 :    
408 :     format(menu_msg, 255, g_coloredMenus ? "\y%s: %s\w^n^n1. %s^n2. %s" : "%s: %s^n^n1. %s^n2. %s", lVote, quest, g_optionName[0], g_optionName[1])
409 :     g_execResult = false
410 :    
411 :     new Float:vote_time = get_cvar_float("amx_vote_time") + 2.0
412 :    
413 :     set_cvar_float("amx_last_voting", get_gametime() + vote_time)
414 :     g_voteRatio = get_cvar_float("amx_vote_ratio")
415 :     format(g_Answer, 127, "%s - %%s", quest)
416 :     show_menu(0, keys, menu_msg, floatround(vote_time), "Vote: ")
417 :     set_task(vote_time, "checkVotes", 99889988)
418 :     g_voteCaller = id
419 :     console_print(id, "%L", id, "VOTING_STARTED")
420 :     g_voteCount = {0, 0, 0, 0}
421 :     g_yesNoVote = 0
422 :    
423 :     return PLUGIN_HANDLED
424 :     }
425 :    
426 :     public cmdVoteKickBan(id, level, cid)
427 :     {
428 :     if (!cmd_access(id, level, cid, 2))
429 :     return PLUGIN_HANDLED
430 :    
431 :     new Float:voting = get_cvar_float("amx_last_voting")
432 :     if (voting > get_gametime())
433 :     {
434 :     console_print(id, "%L", id, "ALREADY_VOTING")
435 :     return PLUGIN_HANDLED
436 :     }
437 :    
438 :     if (voting && voting + get_cvar_float("amx_vote_delay") > get_gametime())
439 :     {
440 :     console_print(id, "%L", id, "VOTING_NOT_ALLOW")
441 :     return PLUGIN_HANDLED
442 :     }
443 :    
444 :     new cmd[32]
445 :    
446 :     read_argv(0, cmd, 31)
447 :    
448 :     new voteban = equal(cmd, "amx_voteban")
449 :     new arg[32]
450 :     read_argv(1, arg, 31)
451 :    
452 :     new player = cmd_target(id, arg, 1)
453 :    
454 :     if (!player)
455 :     return PLUGIN_HANDLED
456 :    
457 :     if (voteban && is_user_bot(player))
458 :     {
459 :     new imname[32]
460 :    
461 :     get_user_name(player, imname, 31)
462 :     console_print(id, "%L", id, "ACTION_PERFORMED", imname)
463 :     return PLUGIN_HANDLED
464 :     }
465 :    
466 :     new keys = MENU_KEY_1|MENU_KEY_2
467 :     new menu_msg[256], lYes[16], lNo[16], lKickBan[16]
468 :    
469 :     format(lYes, 15, "%L", LANG_SERVER, "YES")
470 :     format(lNo, 15, "%L", LANG_SERVER, "NO")
471 :     format(lKickBan, 15, "%L", LANG_SERVER, voteban ? "BAN" : "KICK")
472 :     ucfirst(lKickBan)
473 :     get_user_name(player, arg, 31)
474 :     format(menu_msg, 255, g_coloredMenus ? "\y%s %s?\w^n^n1. %s^n2. %s" : "%s %s?^n^n1. %s^n2. %s", lKickBan, arg, lYes, lNo)
475 :     g_yesNoVote = 1
476 :    
477 :     if (voteban)
478 :     get_user_authid(player, g_optionName[0], 31)
479 :     else
480 :     num_to_str(get_user_userid(player), g_optionName[0], 31)
481 :    
482 :     new authid[32], name[32]
483 :    
484 :     get_user_authid(id, authid, 31)
485 :     get_user_name(id, name, 31)
486 :     log_amx("Vote: ^"%s<%d><%s><>^" vote %s (target ^"%s^")", name, get_user_userid(id), authid, voteban ? "ban" : "kick", arg)
487 :    
488 :     new activity = get_cvar_num("amx_show_activity")
489 :     if (activity > 0)
490 :     {
491 :     new players[32], pnum, lTag[16]
492 :    
493 :     get_players(players, pnum, "c")
494 :     for (new i = 0; i < pnum; i++)
495 :     {
496 :     format(lTag, 15, "%L", players[i], is_user_admin(id) ? "ADMIN" : "USER")
497 :     format(lKickBan, 15, "%L", players[i], voteban ? "BAN" : "KICK")
498 :    
499 :     switch (activity)
500 :     {
501 :     case 2: client_print(players[i], print_chat, "%L", players[i], "ADMIN_VOTE_FOR_2", lTag, name, lKickBan, arg)
502 :     case 1: client_print(players[i], print_chat, "%L", players[i], "ADMIN_VOTE_FOR_1", lTag, lKickBan, arg)
503 :     }
504 :     }
505 :     }
506 :    
507 :     g_execResult = true
508 :    
509 :     new Float:vote_time = get_cvar_float("amx_vote_time") + 2.0
510 :    
511 :     set_cvar_float("amx_last_voting", get_gametime() + vote_time)
512 :     g_voteRatio = get_cvar_float(voteban ? "amx_voteban_ratio" : "amx_votekick_ratio")
513 :     g_Answer = voteban ? "banid 30.0 %s kick" : "kick #%s"
514 :     show_menu(0, keys, menu_msg, floatround(vote_time), voteban ? "Ban " : "Kick ")
515 :     set_task(vote_time, "checkVotes", 99889988)
516 :     g_voteCaller = id
517 :     console_print(id, "%L", id, "VOTING_STARTED")
518 :     g_voteCount = {0, 0, 0, 0}
519 :    
520 :     return PLUGIN_HANDLED
521 :     }

Contact
ViewVC Help
Powered by ViewVC 1.0.4