Advertisement
Hartmann

adminvote

May 29th, 2015
275
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.05 KB | None | 0 0
  1. #include <amxmodx>
  2. #include <amxmisc>
  3.  
  4. new g_Answer[128]
  5. new g_optionName[4][64]
  6. new g_voteCount[4]
  7. new g_validMaps
  8. new g_yesNoVote
  9. new g_coloredMenus
  10. new g_voteCaller
  11. new g_Execute[256]
  12. new g_execLen
  13.  
  14. new bool:g_execResult
  15. new Float:g_voteRatio
  16.  
  17. public plugin_init()
  18. {
  19. register_plugin("Admin Votes", AMXX_VERSION_STR, "AMXX Dev Team")
  20. register_dictionary("adminvote.txt")
  21. register_dictionary("common.txt")
  22. register_dictionary("mapsmenu.txt")
  23. register_menucmd(register_menuid("Change map to "), MENU_KEY_1|MENU_KEY_2, "voteCount")
  24. register_menucmd(register_menuid("Choose map: "), MENU_KEY_1|MENU_KEY_2|MENU_KEY_3|MENU_KEY_4, "voteCount")
  25. register_menucmd(register_menuid("Kick "), MENU_KEY_1|MENU_KEY_2, "voteCount")
  26. register_menucmd(register_menuid("Ban "), MENU_KEY_1|MENU_KEY_2, "voteCount")
  27. register_menucmd(register_menuid("Vote: "), MENU_KEY_1|MENU_KEY_2|MENU_KEY_3|MENU_KEY_4, "voteCount")
  28. register_menucmd(register_menuid("The result: "), MENU_KEY_1|MENU_KEY_2, "actionResult")
  29. register_concmd("amx_votemap", "cmdVoteMap", ADMIN_VOTE, "[map] [map]")
  30. g_coloredMenus = colored_menus()
  31. }
  32.  
  33. public cmdCancelVote(id, level, cid)
  34. {
  35. if (!cmd_access(id, level, cid, 0))
  36. return PLUGIN_HANDLED
  37.  
  38. if (task_exists(99889988, 1))
  39. {
  40. new authid[32], name[32]
  41.  
  42. get_user_authid(id, authid, 31)
  43. get_user_name(id, name, 31)
  44. log_amx("Vote: ^"%s<%d><%s><>^" cancel vote session", name, get_user_userid(id), authid)
  45.  
  46.  
  47. new maxpl=get_maxplayers();
  48. new msg[256];
  49. for (new i = 1; i <= maxpl; i++)
  50. {
  51. if (is_user_connected(i) && !is_user_bot(i))
  52. {
  53. // HACK: ADMIN_CANC_VOTE_{1,2} keys were designed very poorly. Remove all : and %s in it.
  54. LookupLangKey(msg, charsmax(msg), "ADMIN_CANC_VOTE_1", i);
  55. replace_all(msg, charsmax(msg), "%s", "");
  56. replace_all(msg, charsmax(msg), ":", "");
  57. trim(msg);
  58. show_activity_id(i, id, name, msg);
  59. }
  60. }
  61.  
  62. console_print(id, "%L", id, "VOTING_CANC")
  63. ClientPrintColor(0,"%L",LANG_PLAYER,"VOTING_CANC")
  64. remove_task(99889988, 1)
  65. set_cvar_float("amx_last_voting", get_gametime())
  66. }
  67. else
  68. console_print(id, "%L", id, "NO_VOTE_CANC")
  69.  
  70. return PLUGIN_HANDLED
  71. }
  72.  
  73. public delayedExec(cmd[])
  74. server_cmd("%s", cmd)
  75.  
  76. public autoRefuse()
  77. {
  78. log_amx("Vote: %L", "en", "RES_REF")
  79. ClientPrintColor(0, "%L", LANG_PLAYER, "RES_REF")
  80. }
  81.  
  82. public actionResult(id, key)
  83. {
  84. remove_task(4545454)
  85.  
  86. switch (key)
  87. {
  88. case 0:
  89. {
  90. set_task(2.0, "delayedExec", 0, g_Execute, g_execLen)
  91. log_amx("Vote: %L", "en", "RES_ACCEPTED")
  92. ClientPrintColor(0, "%L", LANG_PLAYER, "RES_ACCEPTED")
  93. }
  94. case 1: autoRefuse()
  95. }
  96.  
  97. return PLUGIN_HANDLED
  98. }
  99.  
  100. public checkVotes()
  101. {
  102. new best = 0
  103.  
  104. if (!g_yesNoVote)
  105. {
  106. for (new a = 0; a < 4; ++a)
  107. if (g_voteCount[a] > g_voteCount[best])
  108.  
  109. best = a
  110. }
  111.  
  112. new votesNum = g_voteCount[0] + g_voteCount[1] + g_voteCount[2] + g_voteCount[3]
  113. new iRatio = votesNum ? floatround(g_voteRatio * float(votesNum), floatround_ceil) : 1
  114. new iResult = g_voteCount[best]
  115. new players[32], pnum, i
  116.  
  117. get_players(players, pnum, "c")
  118.  
  119. if (iResult < iRatio)
  120. {
  121. new lVotingFailed[64]
  122.  
  123. for (i = 0; i < pnum; i++)
  124. {
  125. format(lVotingFailed, 63, "%L", players[i], "VOTING_FAILED")
  126. if (g_yesNoVote)
  127. ClientPrintColor(players[i], "%L", players[i], "VOTING_RES_1", lVotingFailed, g_voteCount[0], g_voteCount[1], iRatio)
  128. else
  129. ClientPrintColor(players[i], "%L", players[i], "VOTING_RES_2", lVotingFailed, iResult, iRatio)
  130. }
  131.  
  132. format(lVotingFailed, 63, "%L", "en", "VOTING_FAILED")
  133. log_amx("Vote: %s (got ^"%d^") (needed ^"%d^")", lVotingFailed, iResult, iRatio)
  134.  
  135. return PLUGIN_CONTINUE
  136. }
  137.  
  138. g_execLen = format(g_Execute, 255, g_Answer, g_optionName[best]) + 1
  139.  
  140. if (g_execResult)
  141. {
  142. g_execResult = false
  143.  
  144. if (is_user_connected(g_voteCaller))
  145. {
  146. new menuBody[512], lTheResult[32], lYes[16], lNo[16]
  147.  
  148. format(lTheResult, 31, "%L", g_voteCaller, "THE_RESULT")
  149. format(lYes, 15, "%L", g_voteCaller, "YES")
  150. format(lNo, 15, "%L", g_voteCaller, "NO")
  151.  
  152. new len = format(menuBody, 511, g_coloredMenus ? "\y%s: \w%s^n^n" : "%s: %s^n^n", lTheResult, g_Execute)
  153.  
  154. len += format(menuBody[len], 511 - len, g_coloredMenus ? "\y%L^n\w" : "%L^n", g_voteCaller, "WANT_CONTINUE")
  155. format(menuBody[len], 511 - len, "^n1. %s^n2. %s", lYes, lNo)
  156. show_menu(g_voteCaller, 0x03, menuBody, 10, "The result: ")
  157. set_task(10.0, "autoRefuse", 4545454)
  158. }
  159. else
  160. set_task(2.0, "delayedExec", 0, g_Execute, g_execLen)
  161. }
  162.  
  163. new lVotingSuccess[32]
  164.  
  165. for (i = 0; i < pnum; i++)
  166. {
  167. format(lVotingSuccess, 31, "%L", players[i], "VOTING_SUCCESS")
  168. ClientPrintColor(players[i], "%L", players[i], "VOTING_RES_3", lVotingSuccess, iResult, iRatio, g_Execute)
  169. }
  170.  
  171. format(lVotingSuccess, 31, "%L", "en", "VOTING_SUCCESS")
  172. log_amx("Vote: %s (got ^"%d^") (needed ^"%d^") (result ^"%s^")", lVotingSuccess, iResult, iRatio, g_Execute)
  173.  
  174. return PLUGIN_CONTINUE
  175. }
  176.  
  177. public voteCount(id, key)
  178. {
  179. if (get_cvar_num("amx_vote_answers"))
  180. {
  181. new name[32]
  182. get_user_name(id, name, 31)
  183.  
  184. if (g_yesNoVote)
  185. ClientPrintColor(0, "%L", LANG_PLAYER, key ? "VOTED_AGAINST" : "VOTED_FOR", name)
  186. else
  187. ClientPrintColor(0, "%L", LANG_PLAYER, "VOTED_FOR_OPT", name, key + 1)
  188. ClientPrintColor(0, "^4%s^1 vote^4%s", name, key + 1)
  189. ClientPrintColor(0, "^4%s^1 vote^4%s", name, g_optionName[g_validMaps])
  190. ClientPrintColor(0, "^4%s^1 vote^4%d", name, lChangeMap)
  191. }
  192. ++g_voteCount[key]
  193.  
  194. return PLUGIN_HANDLED
  195. }
  196.  
  197. public cmdVoteMap(id, level, cid)
  198. {
  199. if (!cmd_access(id, level, cid, 2))
  200. return PLUGIN_HANDLED
  201.  
  202. new Float:voting = get_cvar_float("amx_last_voting")
  203. if (voting > get_gametime())
  204. {
  205. console_print(id, "%L", id, "ALREADY_VOTING")
  206. return PLUGIN_HANDLED
  207. }
  208.  
  209. if (voting && voting + get_cvar_float("amx_vote_delay") > get_gametime())
  210. {
  211. console_print(id, "%L", id, "VOTING_NOT_ALLOW")
  212. return PLUGIN_HANDLED
  213. }
  214.  
  215. new argc = read_argc()
  216. if (argc > 5) argc = 5
  217.  
  218. g_validMaps = 0
  219. g_optionName[0][0] = 0
  220. g_optionName[1][0] = 0
  221. g_optionName[2][0] = 0
  222. g_optionName[3][0] = 0
  223.  
  224. for (new i = 1; i < argc; ++i)
  225. {
  226. read_argv(i, g_optionName[g_validMaps], 31)
  227.  
  228. if (is_map_valid(g_optionName[g_validMaps]))
  229. g_validMaps++
  230. }
  231.  
  232. if (g_validMaps == 0)
  233. {
  234. new lMaps[16]
  235.  
  236. format(lMaps, 15, "%L", id, (argc == 2) ? "MAP_IS" : "MAPS_ARE")
  237. console_print(id, "%L", id, "GIVEN_NOT_VALID", lMaps)
  238. return PLUGIN_HANDLED
  239. }
  240.  
  241. new menu_msg[256], len = 0
  242. new keys = 0
  243.  
  244. if (g_validMaps > 1)
  245. {
  246. keys = MENU_KEY_0
  247. len = format(menu_msg, 255, g_coloredMenus ? "\y%L: \w^n^n" : "%L: ^n^n", LANG_SERVER, "CHOOSE_MAP")
  248. new temp[128]
  249.  
  250. for (new a = 0; a < g_validMaps; ++a)
  251. {
  252. format(temp, 127, "%d. %s^n", a+1, g_optionName[a])
  253. len += copy(menu_msg[len], 255-len, temp)
  254. keys |= (1<<a)
  255. }
  256.  
  257. format(menu_msg[len], 255-len, "^n0. %L", LANG_SERVER, "NONE")
  258. g_yesNoVote = 0
  259. } else {
  260. new lChangeMap[32], lYes[16], lNo[16]
  261.  
  262. format(lChangeMap, 31, "%L", LANG_SERVER, "CHANGE_MAP_TO")
  263. format(lYes, 15, "%L", LANG_SERVER, "YES")
  264. format(lNo, 15, "%L", LANG_SERVER, "NO")
  265. 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)
  266. keys = MENU_KEY_1|MENU_KEY_2
  267. g_yesNoVote = 1
  268. }
  269.  
  270. new authid[32], name[32]
  271.  
  272. get_user_authid(id, authid, 31)
  273. get_user_name(id, name, 31)
  274.  
  275. if (argc == 2)
  276. log_amx("Vote: ^"%s<%d><%s><>^" vote map (map ^"%s^")", name, get_user_userid(id), authid, g_optionName[0])
  277. else
  278. 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])
  279.  
  280. new maxpl=get_maxplayers();
  281. new msg[256];
  282. for (new i = 1; i <= maxpl; i++)
  283. {
  284. if (is_user_connected(i) && !is_user_bot(i))
  285. {
  286. // HACK: ADMIN_VOTE_MAP_{1,2} keys were designed very poorly. Remove all : and %s in it.
  287. LookupLangKey(msg, charsmax(msg), "ADMIN_VOTE_MAP_1", i);
  288. replace_all(msg, charsmax(msg), "%s", "");
  289. replace_all(msg, charsmax(msg), ":", "");
  290. trim(msg);
  291. show_activity_id(i, id, name, msg);
  292. }
  293. }
  294.  
  295. g_execResult = true
  296. new Float:vote_time = get_cvar_float("amx_vote_time") + 2.0
  297.  
  298. set_cvar_float("amx_last_voting", get_gametime() + vote_time)
  299. g_voteRatio = get_cvar_float("amx_votemap_ratio")
  300. g_Answer = "changelevel %s"
  301. show_menu(0, keys, menu_msg, floatround(vote_time), (g_validMaps > 1) ? "Choose map: " : "Change map to ")
  302. set_task(vote_time, "checkVotes", 99889988)
  303. g_voteCaller = id
  304. console_print(id, "%L", id, "VOTING_STARTED")
  305. g_voteCount = {0, 0, 0, 0}
  306.  
  307. return PLUGIN_HANDLED
  308. }
  309.  
  310. public cmdVote(id, level, cid)
  311. {
  312. if (!cmd_access(id, level, cid, 4))
  313. return PLUGIN_HANDLED
  314.  
  315. new Float:voting = get_cvar_float("amx_last_voting")
  316. if (voting > get_gametime())
  317. {
  318. console_print(id, "%L", id, "ALREADY_VOTING")
  319. return PLUGIN_HANDLED
  320. }
  321.  
  322. if (voting && voting + get_cvar_float("amx_vote_delay") > get_gametime())
  323. {
  324. console_print(id, "%L", id, "VOTING_NOT_ALLOW")
  325. return PLUGIN_HANDLED
  326. }
  327.  
  328. new quest[48]
  329. read_argv(1, quest, 47)
  330.  
  331. if ((contain(quest, "sv_password") != -1) || (contain(quest, "rcon_password") != -1) || (contain(quest, "kick") != -1) ||
  332. (contain(quest, "addip") != -1) || (contain(quest, "ban") != -1))
  333. {
  334. console_print(id, "%L", id, "VOTING_FORBIDDEN")
  335. return PLUGIN_HANDLED
  336. }
  337.  
  338. new count=read_argc();
  339.  
  340. for (new i=0;i<4 && (i+2)<count;i++)
  341. {
  342. read_argv(i+2, g_optionName[i], sizeof(g_optionName[])-1);
  343. }
  344.  
  345. new authid[32], name[32]
  346.  
  347. get_user_authid(id, authid, 31)
  348. get_user_name(id, name, 31)
  349. 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])
  350.  
  351. new maxpl=get_maxplayers();
  352. new msg[256];
  353. for (new i = 1; i <= maxpl; i++)
  354. {
  355. if (is_user_connected(i) && !is_user_bot(i))
  356. {
  357. // HACK: ADMIN_VOTE_CUS_{1,2} keys were designed very poorly. Remove all : and %s in it.
  358. LookupLangKey(msg, charsmax(msg), "ADMIN_VOTE_CUS_1", i);
  359. replace_all(msg, charsmax(msg), "%s", "");
  360. replace_all(msg, charsmax(msg), ":", "");
  361. trim(msg);
  362. show_activity_id(i, id, name, msg);
  363. }
  364. }
  365.  
  366. new menu_msg[512], lVote[16]
  367.  
  368. format(lVote, 15, "%L", LANG_SERVER, "VOTE")
  369.  
  370. count-=2;
  371. if (count>4)
  372. {
  373. count=4;
  374. }
  375. // count now shows how many options were listed
  376. new keys=0;
  377. for (new i=0;i<count;i++)
  378. {
  379. keys |= (1<<i);
  380. }
  381.  
  382. new len=formatex(menu_msg, sizeof(menu_msg)-1, g_coloredMenus ? "\y%s: %s\w^n^n" : "%s: %s^n^n", lVote, quest);
  383.  
  384. for (new i=0;i<count;i++)
  385. {
  386. len+=formatex(menu_msg[len], sizeof(menu_msg) - 1 - len ,"%d. %s^n",i+1,g_optionName[i]);
  387. }
  388. g_execResult = false
  389.  
  390. new Float:vote_time = get_cvar_float("amx_vote_time") + 2.0
  391.  
  392. set_cvar_float("amx_last_voting", get_gametime() + vote_time)
  393. g_voteRatio = get_cvar_float("amx_vote_ratio")
  394. replace_all(quest,sizeof(quest)-1,"%","");
  395. format(g_Answer, 127, "%s - %%s", quest)
  396. show_menu(0, keys, menu_msg, floatround(vote_time), "Vote: ")
  397. set_task(vote_time, "checkVotes", 99889988)
  398. g_voteCaller = id
  399. console_print(id, "%L", id, "VOTING_STARTED")
  400. g_voteCount = {0, 0, 0, 0}
  401. g_yesNoVote = 0
  402.  
  403. return PLUGIN_HANDLED
  404. }
  405. ClientPrintColor( id, String[ ], any:... )
  406. {
  407. new szMsg[ 190 ]
  408. vformat( szMsg, charsmax( szMsg ), String, 3 )
  409.  
  410. replace_all( szMsg, charsmax( szMsg ), "!n", "^1" )
  411. replace_all( szMsg, charsmax( szMsg ), "!t", "^3" )
  412. replace_all( szMsg, charsmax( szMsg ), "!g", "^4" )
  413.  
  414. static msgSayText = 0
  415. static fake_user
  416.  
  417. if( !msgSayText )
  418. {
  419. msgSayText = get_user_msgid( "SayText" )
  420. fake_user = get_maxplayers( ) + 1
  421. }
  422.  
  423. message_begin( id ? MSG_ONE_UNRELIABLE : MSG_BROADCAST, msgSayText, _, id )
  424. write_byte( id ? id : fake_user )
  425. write_string( szMsg )
  426. message_end( )
  427. }
  428. /* AMXX-Studio Notes - DO NOT MODIFY BELOW HERE
  429. *{\\ rtf1\\ ansi\\ deff0{\\ fonttbl{\\ f0\\ fnil Tahoma;}}\n\\ viewkind4\\ uc1\\ pard\\ lang1033\\ f0\\ fs16 \n\\ par }
  430. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement