jtrent238

VoteMap

Jul 19th, 2016
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.74 KB | None | 0 0
  1. /* Includes */
  2. #include <amxmodx>
  3. #include <amxmisc>
  4.  
  5. /* Defines */
  6. #define MAX_MAPS 4
  7. #define DMAP_TASKID_COUNTDOWN 1100 //
  8.  
  9. /* Bool */
  10. new bool:g_Vote[ 33 ]
  11. new bool:Voted[ 33 ]
  12. new bool:g_Voted[ 33 ]
  13. new bool:g_Status[ 33 ]
  14. new bool:changeMap
  15. new bool:g_AdminStart // Vote Menu On
  16. new bool:g_VoteOff // Vote Menu Off
  17. new bool:g_HasVote // The vote map will start in Next Map
  18. new bool:g_Started // The VoteMap has already started
  19. new bool:g_DontVote // the next map: ^"^4%s^1^"
  20. new bool:g_WaitVote // Wait voting ends
  21. new bool:g_AutoVote // Currently active voting
  22. new bool:g_VoteStarted // public MTimer()
  23. new bool:g_AdminVote // You can not turn on the ^4VoteMap^1 will try to map
  24.  
  25. /* New */
  26. new g_ModIndex[4]
  27. new g_szKind[ 4 ]
  28. new Spk[10]
  29. new g_Map[ 32 ]
  30. new TimeVote[ 33 ]
  31. new g_TotalVotes
  32. new Timers
  33. new Sum
  34. new g_szRoundMap
  35. new g_MTimer
  36. new g_STimer
  37. new countnum
  38. new time_s
  39. new id
  40.  
  41. new const szPrefix[] = "AMXX";
  42.  
  43. /* Maps */
  44. new const g_MapNames[][] =
  45. {
  46. // "Map"
  47. ""
  48. }
  49.  
  50. /* Start Mod */
  51. public plugin_init()
  52. {
  53. register_plugin("VoteMap", "v1.0", "Edited By Michael")
  54.  
  55. g_AdminStart = true
  56. g_VoteOff = false
  57. g_HasVote = false
  58. g_Started = false
  59. g_DontVote = false
  60. g_WaitVote = false
  61. g_VoteStarted = true
  62. g_AutoVote = false
  63. g_AdminVote = false
  64. register_clcmd( "say /startvote", "admin");
  65. register_clcmd( "say !startvote", "admin");
  66. register_clcmd( "say /nextmap", "NextMap" );
  67. register_clcmd( "say /nextvote", "ShowTime" );
  68. register_clcmd( "say /map", "ShowTime" );
  69. register_clcmd( "say /nm", "NextMap" );
  70. register_clcmd( "say nextmap", "NextMap" );
  71. register_clcmd( "say nextvote", "ShowTime" );
  72. register_clcmd( "say map", "ShowTime" );
  73. register_clcmd( "say nm", "NextMap" );
  74. register_clcmd( "say /Status", "cmdGetInfo" );
  75. register_event( "HLTV", "NewRound", "a", "1=0", "2=0" );
  76. get_mapname( g_Map, 31 );
  77. set_task( 0.5, "reset");
  78. }
  79.  
  80. /* Shot Time In Hud */
  81. public cmdGetInfo(client)
  82. {
  83. if(TimeVote[client])
  84. TimeVote[client] = false;
  85. else {
  86. TimeVote[client] = true;
  87. TimeInHud(client);
  88. }
  89. }
  90.  
  91. public TimeInHud(client)
  92. {
  93. remove_task(client);
  94.  
  95. if(TimeVote[client])
  96. {
  97. set_hudmessage(255, 85, 0, 0.0, 0.93, 0, 6.0, 1.5)
  98.  
  99. if( g_HasVote )
  100. {
  101. show_hudmessage(client, "The vote map will start in Next Map");
  102. }
  103. if( g_Started )
  104. {
  105. return show_hudmessage(client, "The VoteMap has already started.");
  106. }
  107. else
  108. {
  109. show_hudmessage(client, "VoteMap Will Be Start In More: %i.%i minutes.",g_MTimer,g_STimer);
  110. }
  111. set_task(1.0, "TimeInHud", client)
  112. }
  113. return PLUGIN_CONTINUE;
  114. }
  115.  
  116. /* New Round */
  117. public NewRound()
  118. if( changeMap )
  119. {
  120. new Winner = 0;
  121. for( new i = 0; i < sizeof g_ModIndex; i++ )
  122. {
  123. if( g_szKind[ Winner ] < g_szKind[ i ])
  124.  
  125. Winner = i;
  126. }
  127. set_task( 6.0, "changemap_", _, g_MapNames[ g_ModIndex[ Winner ] ], 30 )
  128. ColorChat( 0, "The next map will be ^4%s^1.", g_MapNames[ g_ModIndex[ Winner ] ] );
  129. set_task(1.0, "countdown", DMAP_TASKID_COUNTDOWN, "", 0, "a", 6);
  130. client_cmd(0, "speak ^"loading environment on to your computer^"");
  131. changeMap = false;
  132. }
  133.  
  134.  
  135. public countdown() {
  136. new Winner = 0;
  137. for( new i = 0; i < sizeof g_ModIndex; i++ )
  138. {
  139. if( g_szKind[ Winner ] < g_szKind[ i ])
  140. Winner = i;
  141. }
  142.  
  143. new players[32], inum, i;
  144. get_players(players, inum, "c");
  145. for (i = 0; i < inum; ++i) {
  146. if(is_user_connected(players[i]))
  147. {
  148. message_begin(MSG_ONE, get_user_msgid("ScreenFade"), {0,0,0}, players[i])
  149. write_short(1<<10)
  150. write_short(1<<10)
  151. write_short(0x0000)
  152. write_byte(0)
  153. write_byte(0)
  154. write_byte(0)
  155. write_byte(255)
  156. message_end()
  157. }
  158. }
  159. countnum++;
  160. set_hudmessage(150, 120, 0, -1.0, 0.3, 0, 0.5, 1.1, 0.1, 0.1);
  161. show_hudmessage(0, "Next Map: %s ^nTime To Change The Map: %i", g_MapNames[ g_ModIndex[ Winner ] ], 5 - countnum);
  162. return PLUGIN_HANDLED;
  163. }
  164.  
  165. /* Admin Start Vote */
  166. public admin( iPlayer )
  167. {
  168. if( !( get_user_flags( iPlayer ) & ADMIN_IMMUNITY ) )
  169. {
  170. ColorChat( iPlayer, "You have no access to this ^4command^1." );
  171. }
  172. if(g_AdminStart)
  173. {
  174. ColorChat(0, "ADMIN: ^3%s^1 Started ^4VoteMap", GetName(iPlayer))
  175. set_task(0.0, "Admin_TimeLeft")
  176. set_task(10.0, "RandomItem")
  177. set_task(10.0, "Sound")
  178. time_s = 10
  179. g_VoteStarted = false
  180. TimeVote[iPlayer] = false
  181. }
  182. if(g_VoteOff)
  183. ColorChat( iPlayer, "The^3 VoteMap^1 has already^4 started^1.")
  184.  
  185. if(g_AutoVote) {
  186. ColorChat( iPlayer, "Currently active voting")
  187. }
  188. if(g_AdminVote)
  189. ColorChat( iPlayer, "You can not turn on the ^4VoteMap^1 will try to map")
  190.  
  191. return PLUGIN_HANDLED;
  192. return PLUGIN_CONTINUE
  193. }
  194.  
  195. public Admin_TimeLeft()
  196. {
  197. num_to_word(time_s, Spk, charsmax(Spk));
  198. client_cmd(0, "spk vox/%s", Spk);
  199.  
  200. set_hudmessage(255, 255, 255, -1.0, 0.12, 0, 0.02, 1.0, 0.01, 0.1, 10);
  201. show_hudmessage(0, "Admin Started^nVoteMap Will be Start In More ^"%i^" Seconds", time_s);
  202. if(time_s >= 1)
  203. {
  204. set_task(1.0, "Admin_TimeLeft")
  205. }
  206. --time_s;
  207. g_Started = true
  208. g_VoteOff = true
  209. g_AdminStart = false
  210. g_WaitVote = true
  211. }
  212.  
  213. /* Timers */
  214. public reset()
  215. {
  216. g_MTimer = 0;
  217. g_STimer = 60;
  218. set_task( 60.0, "MTimer");
  219. set_task( 1.0, "STimer" );
  220. TimeVote[id] = false
  221. }
  222.  
  223. public MTimer()
  224. {
  225. if(g_VoteStarted)
  226. {
  227. if(g_MTimer <= 0)
  228. {
  229. set_task(1.0, "TimeLeft")
  230. g_MTimer = 0
  231. }
  232. time_s = 10
  233. set_task( 60.0, "MTimer");
  234. set_task(10.0, "RandomItem")
  235. set_task(10.0, "Sound")
  236. }
  237. }
  238.  
  239. public STimer(id)
  240. {
  241. g_STimer--
  242.  
  243. if(g_STimer <= 0)
  244. {
  245. g_MTimer--
  246. g_STimer = 60
  247.  
  248. }
  249. set_task( 1.0, "STimer", id );
  250. }
  251.  
  252. public TimeLeft()
  253. {
  254. num_to_word(time_s, Spk, charsmax(Spk));
  255. client_cmd(0, "spk vox/%s", Spk);
  256.  
  257. set_hudmessage(255, 255, 255, -1.0, 0.12, 0, 0.02, 1.0, 0.01, 0.1, 10);
  258. show_hudmessage(0, "VoteMap Will be Start In More ^"%i^" Seconds", time_s);
  259. if(time_s >= 1)
  260. {
  261. set_task(1.0, "TimeLeft")
  262. }
  263. --time_s;
  264. g_VoteOff = false
  265. g_AutoVote = true
  266. g_Started = true
  267. g_AdminStart = false
  268. g_WaitVote = true
  269. }
  270.  
  271. public Sound()
  272. {
  273. client_cmd(0, "spk Gman/Gman_Choose2");
  274. }
  275.  
  276. public ShowTime( id )
  277. {
  278. if( g_Started )
  279. return ColorChat(id, "The^3 VoteMap^1 has already^4 started^1.")
  280. if( g_HasVote )
  281. {
  282. ColorChat( id, "The vote map will start in ^4Next Map");
  283. }
  284. else
  285. {
  286. ColorChat( id, "The vote map will start in^4 %i.%i^1 minutes.",g_MTimer,g_STimer);
  287. }
  288. }
  289.  
  290. public NextMap( id )
  291. {
  292. new Winner = 0;
  293. for( new i = 0; i < sizeof g_ModIndex; i++ )
  294. {
  295. if( g_szKind[ Winner ] < g_szKind[ i ])
  296. Winner = i;
  297. }
  298. if( g_DontVote )
  299. {
  300. ColorChat( id, "the next map: ^"^4%s^1^"", g_MapNames[ g_ModIndex[ Winner ] ]);
  301. }
  302. if( g_WaitVote )
  303. {
  304. ColorChat( id, "Wait voting ends");
  305. }
  306. else
  307. {
  308. ColorChat( id, "the next map: ^"^4Dont Selected^1^"");
  309. }
  310. }
  311.  
  312. public Time()
  313. {
  314. g_szRoundMap == 9 ? set_task( 0.1, "RandomItem" ) : set_task( 0.6, "ShowTime" );
  315. }
  316.  
  317. public RandomItem()
  318. {
  319. new count, bitsum;
  320. while ( count < sizeof g_ModIndex ) {
  321.  
  322. new randomnum = random(sizeof g_MapNames);
  323.  
  324. if ( ! ( bitsum & (1 << randomnum) ) ) {
  325. g_ModIndex[count++] = randomnum;
  326. bitsum |= (1 << randomnum);
  327. }
  328. }
  329. Timers = 21
  330. Timer()
  331. for (new i = 1; i <= get_maxplayers(); i++)
  332. {
  333. dddVote(i)
  334. g_Voted[i] = false
  335. }
  336. g_VoteStarted = false
  337. g_VoteOff = true
  338. g_AutoVote = false
  339. g_TotalVotes = 0;
  340. }
  341.  
  342. public Timer()
  343. {
  344. if(Timers == 0)
  345. {
  346. checkvotesd( )
  347. return PLUGIN_HANDLED;
  348. }
  349. Timers--;
  350. set_task( 1.0, "Timer" );
  351. for (new i = 1; i <= get_maxplayers(); i++)
  352. {
  353. dddVote(i)
  354.  
  355. Voted[id] = false;
  356. g_Status[id] = false;
  357.  
  358. }
  359. return PLUGIN_CONTINUE
  360. }
  361.  
  362. /* Vote Menu */
  363. public dddVote( client )
  364. {
  365. new strFunc[ 3 ]
  366. static szMap[ 200 ]
  367.  
  368. formatex( szMap, charsmax( szMap ), "\r// \wStatus: %s \w| \w| Players Voted: \r%d|%d^n\r// \wTime to choose: \y%i Sec \w| Status Vote Now: %s",
  369. Voted[client] ? "\yVoted" : "\rNot Voted", // Status
  370. g_TotalVotes, get_playersnum(), // Players Voted
  371. Timers,// Timers
  372. g_Status[client] ? "\rOff" : "\yOn") // Status Vote
  373.  
  374. new szMenu = menu_create( szMap, "handlerdddd")
  375.  
  376. for( new k = 0; k < MAX_MAPS; k++ ) // show selected maps + votes
  377. {
  378. num_to_str( k, strFunc, 2 )
  379. formatex(szMap, charsmax( szMap ), "%s\r -\d (\y%i Votes\d)", g_MapNames[g_ModIndex[ k ]], g_szKind[ k ])
  380. menu_additem( szMenu, szMap, strFunc )
  381. }
  382. menu_setprop( szMenu, MPROP_EXIT, MEXIT_NEVER )
  383. menu_display( client, szMenu )
  384. }
  385.  
  386. public handlerdddd( client, menu, item )
  387. {
  388. if( Voted[ client ] == true )
  389. {
  390. dddVote( client );
  391. return
  392. }
  393. ColorChat( 0, "^3%s^1 has voted for^4 %s^1", GetName(client), g_MapNames[g_ModIndex[ item ]])
  394.  
  395. if( !g_Vote[ client ] )
  396. {
  397. g_Vote[ client ] = true;
  398. g_szKind[item]++;
  399. Sum++;
  400. }
  401. client_cmd (0, "spk sound/buttons/lightswitch2.wav" )
  402. g_Voted[ client ] = true
  403. Voted[client] = true
  404. g_Status[client] = true
  405. g_WaitVote = true
  406. g_TotalVotes += 1
  407. dddVote( client );
  408. return;
  409. }
  410.  
  411. /* Check Vote */
  412. public checkvotesd( )
  413. {
  414. new players[ 32 ], num, iPlayer;
  415. get_players( players, num, "ach" );
  416.  
  417. for( new i; i < num; i++ )
  418. {
  419. iPlayer = players[ i ];
  420.  
  421. remove_task( iPlayer );
  422. show_menu( iPlayer, 0, "^n", 1 );
  423. show_menu( iPlayer, 0, "^n", 1 );
  424. set_task( 0.1, "DestroyMenu", iPlayer );
  425. }
  426.  
  427. new Winner = 0;
  428. for( new i = 0; i < sizeof g_ModIndex; i++ )
  429. {
  430. if( g_szKind[ Winner ] < g_szKind[ i ])
  431. Winner = i;
  432. }
  433. set_hudmessage(random(255), random(255), random(255), -1.0, 0.26, 2, 6.0, 12.0)
  434. show_hudmessage(0, "The map %s Won^nLast Round", g_MapNames[ g_ModIndex[ Winner ] ])
  435. ColorChat( 0, "The map ^4%s ^1won, the map will be changed in the next round.", g_MapNames[ g_ModIndex[ Winner ] ] );
  436. changeMap = true;
  437. g_HasVote = true
  438. g_DontVote = true
  439. g_AdminStart = false
  440. g_Started = false
  441. g_VoteOff = false
  442. g_WaitVote = false
  443. g_AdminVote = true
  444. }
  445.  
  446. /* ChangeLevel */
  447. public changemap_( param[] )
  448. {
  449. server_cmd("changelevel %s", param)
  450. }
  451.  
  452. /* Destroy Menu */
  453. public DestroyMenu( client )
  454. {
  455. show_menu( client, 0, "^n", 1 );
  456. }
  457.  
  458. /* Name */
  459. public GetName(id)
  460. {
  461. new szName[ 32 ];
  462. get_user_name( id, szName, 31 )
  463. return szName;
  464. }
  465.  
  466. /* Color Chat */
  467. stock ColorChat( const client, const string[ ], { Float, Sql, Resul, _ } :... )
  468. {
  469. new msg[ 191 ], players[ 32 ], count = 1;
  470.  
  471. static len; len = formatex( msg, charsmax(msg), "^4[^1%s^4]^1 ", szPrefix );
  472. vformat( msg[ len ], charsmax( msg ) - len, string, 3 );
  473.  
  474. if( client ) players[ 0 ] = client;
  475. else get_players( players,count, "ch" );
  476.  
  477. for( new i = 0; i < count; i++ )
  478. {
  479. if( is_user_connected( players[ i ] ) )
  480. {
  481. message_begin( MSG_ONE_UNRELIABLE, get_user_msgid( "SayText" ),_, players[ i ] );
  482. write_byte( players[ i ] );
  483. write_string( msg );
  484. message_end( );
  485. }
  486. }
  487. }
Add Comment
Please, Sign In to add comment