Advertisement
Guest User

Untitled

a guest
May 24th, 2013
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 15.48 KB | None | 0 0
  1. /*
  2. * _______ _ _ __ __
  3. * | _____/ | | | | \ \ __ / /
  4. * | | | | | | | | / \ | |
  5. * | | | |____| | | |/ __ \| |
  6. * | | ___ | ______ | | / \ |
  7. * | | |_ | | | | | | / \ |
  8. * | | | | | | | | | | | |
  9. * | |____| | | | | | | | | |
  10. * |_______/ |_| |_| \_/ \_/
  11. *
  12. *
  13. *
  14. * Last Edited: 05-16-08
  15. *
  16. * ============
  17. * Changelog:
  18. * ============
  19. *
  20. * v1.4e
  21. * -is_map_valid() broken, hardcoded a bug fix.
  22. *
  23. * v1.4d
  24. * -Bug Fixes
  25. *
  26. * v1.4c
  27. * -nominate command changed
  28. *
  29. * v1.4b
  30. * -GG Compadability Beta
  31. *
  32. * v1.4
  33. * -Added Nominating
  34. *
  35. * v1.1 - 1.3
  36. * -Bug Fixes
  37. * -Added RTV
  38. *
  39. * v1.0
  40. * -Initial Release
  41. *
  42. */
  43.  
  44. #define VERSION "1.4d"
  45.  
  46. #include <amxmodx>
  47. #include <amxmisc>
  48.  
  49. #define MAX_NOMINATED 20
  50. #define MAX_TRIES 50
  51.  
  52. new configfile[200]
  53.  
  54. new menu[2000]
  55. new keys
  56.  
  57. new g_teamScore[2]
  58.  
  59. new bool:voting
  60. new votes[10]
  61. new maps[9][32]
  62.  
  63. new num_nominated = 0
  64. new nominated[MAX_NOMINATED][32]
  65. new bool:has_nominated[33]
  66.  
  67. new mp_winlimit
  68. new mp_maxrounds
  69. new mp_timelimit
  70.  
  71. new extended_pcvar
  72. new extendtime_pcvar
  73. new lastmap_pcvar
  74. new lastmap_was_pcvar
  75. new lastlastmap_pcvar
  76. new lastlastmap_was_pcvar
  77. new showvotes_pcvar
  78. new rtv_percent_pcvar
  79. new rtv_wait_pcvar
  80. new delay_time_pcvar
  81. new delay_tally_time_pcvar
  82.  
  83. new extended
  84.  
  85. new cur_nextmap[32]
  86.  
  87. new cstrike
  88. new bool:rtv[33]
  89. new rtvtotal
  90.  
  91. new Float:voterocked
  92. new bool:voterocked2
  93.  
  94. new num
  95.  
  96. new say_commands[][32] =
  97. {
  98. "rockthevote",
  99. "rock the vote",
  100. "rtv",
  101. "/rockthevote",
  102. "/rock the vote",
  103. "/rtv"
  104. }
  105.  
  106. new say_commands2[][32] =
  107. {
  108. "nominate",
  109. "/nominate"
  110. }
  111.  
  112. new lastmap[32]
  113. new lastlastmap[32]
  114. new currentmap[32]
  115.  
  116. new g_iMaxPlayers;
  117.  
  118. public plugin_init()
  119. {
  120.  
  121. get_configsdir(configfile,199)
  122. format(configfile,199,"%s/custom_nextmaps.ini",configfile)
  123.  
  124. register_cvar("map_enabled","1")
  125.  
  126. if(file_exists(configfile) && get_cvar_num("map_enabled"))
  127. {
  128. register_concmd("amx_nextmap_vote","cmd_nextmap",ADMIN_MAP,"Starts a vote for nextmap [1=allow extend(Default) | 0=Don't allow extend] [1=Change Now(Default) | 0=Change at End")
  129.  
  130. register_clcmd("say nextmap","saynextmap")
  131. register_clcmd("say_team nextmap","saynextmap")
  132.  
  133. register_clcmd("say","say_hook")
  134. register_clcmd("say_team","say_hook")
  135.  
  136. g_iMaxPlayers = get_maxplayers( );
  137.  
  138. cstrike = cstrike_running()
  139. if(cstrike) register_event("TeamScore", "team_score", "a")
  140.  
  141. register_menucmd(register_menuid("CustomNextMap"),(1<<0)|(1<<1)|(1<<2)|(1<<3)|(1<<4)|(1<<5)|(1<<6)|(1<<7)|(1<<8)|(1<<9),"VoteCount")
  142.  
  143. set_task(15.0,"Check_Endround",1337,"",0,"b")
  144.  
  145. if(cstrike)
  146. {
  147. mp_winlimit = get_cvar_pointer("mp_winlimit")
  148. mp_maxrounds = get_cvar_pointer("mp_maxrounds")
  149. }
  150. mp_timelimit = get_cvar_pointer("mp_timelimit")
  151.  
  152. extended_pcvar = register_cvar("map_extend_max","3")
  153. extendtime_pcvar = register_cvar("map_extend_time","5")
  154. lastmap_pcvar = register_cvar("map_lastmap_show","1")
  155. lastlastmap_pcvar = register_cvar("map_lastlastmap_show","1")
  156. showvotes_pcvar = register_cvar("map_show_votes","1")
  157. rtv_percent_pcvar = register_cvar("map_rtv_percent","50")
  158. rtv_wait_pcvar = register_cvar("map_rtv_wait","180")
  159. lastmap_was_pcvar = register_cvar("qq_lastmap","")
  160. lastlastmap_was_pcvar = register_cvar("qq_lastlastmap","")
  161. delay_time_pcvar = register_cvar("map_delay_time","6")
  162. delay_tally_time_pcvar = register_cvar("map_tally_delay_time","15")
  163.  
  164. if(is_plugin_loaded("Nextmap Chooser")!=-1) pause("acd","mapchooser.amxx")
  165. if(!cvar_exists("amx_nextmap")) register_cvar("amx_nextmap","")
  166.  
  167. get_pcvar_string(lastmap_was_pcvar,lastmap,31)
  168. get_pcvar_string(lastlastmap_was_pcvar,lastlastmap,31)
  169. get_mapname(currentmap,31)
  170. }
  171. }
  172.  
  173. public client_disconnect(id)
  174. {
  175. if(rtv[id])
  176. {
  177. rtv[id]=false
  178. has_nominated[id]=false
  179. rtvtotal--
  180. }
  181. }
  182.  
  183. public cmd_nextmap(id,level,cid)
  184. {
  185. if(!cmd_access(id,level,cid,1))
  186. {
  187. return PLUGIN_HANDLED
  188. }
  189.  
  190. if(!voting)
  191. {
  192. num = get_pcvar_num(delay_time_pcvar)
  193. if(num<1) num=1
  194.  
  195. new arg1[8] = "1"
  196. new arg2[8] = "1"
  197. if(read_argc()>=2)
  198. {
  199. read_argv(1,arg1,7)
  200. if(read_argc()>=3)
  201. {
  202. read_argv(2,arg2,7)
  203. }
  204. }
  205.  
  206. client_print(0,print_chat,"[AMXX] An admin has started a nextmap vote! Vote starting in %d seconds.",num)
  207.  
  208. if(str_to_num(arg2)) voterocked2=true
  209. else voterocked2=false
  210. make_menu(str_to_num(arg1))
  211.  
  212. }
  213. else
  214. {
  215. client_print(id,print_chat,"[AMXX] There is already a nextmap vote in progress.")
  216. }
  217. return PLUGIN_HANDLED
  218. }
  219.  
  220. public make_menu(add_extend)
  221. {
  222. num = get_pcvar_num(delay_time_pcvar)
  223. if(num<1) num=1
  224.  
  225. for(new i=0;i<10;i++) votes[i]=0
  226. for(new i=0;i<9;i++) format(maps[i],31,"")
  227.  
  228. format(menu,1999,"^n")
  229.  
  230. new Fsize = file_size(configfile,1)
  231. new read[32], trash, string[8]
  232. new numbers[17]
  233.  
  234. for(new i=1;i<9;i++)
  235. {
  236. numbers[i]=0
  237. numbers[17-i]=0
  238. for(new i2=0;i2<Fsize;i2++)
  239. {
  240. read_file(configfile,i2,read,31,trash)
  241. format(string,7,"[%d]",i)
  242. if(equali(read,string)) numbers[i]=i2+1
  243.  
  244. format(string,7,"[/%d]",i)
  245. if(equali(read,string)) numbers[17-i]=i2-1
  246. }
  247. }
  248.  
  249. new tries
  250. keys = (1<<9)
  251. new j
  252. for(new i=1;i<9;i++)
  253. {
  254. format(maps[i],31,"")
  255. if(numbers[i] && numbers[17-i] && numbers[17-i]-numbers[i]>=0)
  256. {
  257. tries=0
  258. while(tries<MAX_TRIES)
  259. {
  260. read_file(configfile,random_num(numbers[i],numbers[17-i]),read,31,trash)
  261. if(containi(read,"%nominated%")==0 && num_nominated>0) format(read,31,"%s",nominated[random_num(0,num_nominated - 1)])
  262. if(is_map_valid(read) && !equali(read,currentmap) && (get_pcvar_num(lastmap_pcvar) || !equali(read,lastmap)) && (get_pcvar_num(lastlastmap_pcvar) || !equali(read,lastlastmap)))
  263. {
  264. for(j=1;j<i;j++)
  265. {
  266. if(equali(read,maps[j]))
  267. {
  268. j = 0
  269. break;
  270. }
  271. }
  272. if(!j) break;
  273. format(maps[i],31,"%s",read)
  274. format(menu,1999,"%s^n%d. %s",menu,i,read)
  275. switch(i)
  276. {
  277. case 1: keys |= (1<<0)
  278. case 2: keys |= (1<<1)
  279. case 3: keys |= (1<<2)
  280. case 4: keys |= (1<<3)
  281. case 5: keys |= (1<<4)
  282. case 6: keys |= (1<<5)
  283. case 7: keys |= (1<<6)
  284. case 8: keys |= (1<<7)
  285. }
  286. break;
  287. }
  288. tries++
  289. }
  290. }
  291. }
  292.  
  293. if(add_extend)
  294. {
  295. new mapname[32]
  296. get_mapname(mapname,31)
  297. if(extended<get_pcvar_num(extended_pcvar))
  298. {
  299. format(menu,1999,"%s^n. Extend %s^n",menu,mapname)
  300. keys |= (1<<8)
  301. }
  302. }
  303. format(menu,1999,"%s^n0. I don't care",menu)
  304.  
  305. set_hudmessage(255,0,0,0.03,0.40,0,6.0,1.0,0.0,0.0,3)
  306. show_hudmessage(0,"Vote for Next Map in ^n%d seconds:",num)
  307.  
  308. set_hudmessage(255,255,255,0.03,0.40,0,6.0,1.0,0.0,0.0,4)
  309. show_hudmessage(0,menu)
  310.  
  311. set_task(1.0,"Send_Menu",0,"",0,"a",num)
  312. set_task(get_pcvar_float(delay_tally_time_pcvar) + float(num),"VoteTally",0)
  313.  
  314. voting=true
  315. voterocked=-1.0
  316. }
  317.  
  318. public Send_Menu()
  319. {
  320. if(num!=1)
  321. {
  322. set_hudmessage(255,0,0,0.03,0.40,0,6.0,1.0,0.0,0.0,3)
  323. show_hudmessage(0,"Vote for Next Map in ^n%d seconds:",num-1)
  324.  
  325. set_hudmessage(255,0,200,0.03,0.40,0,6.0,1.0,0.0,0.0,4)
  326. show_hudmessage(0,menu)
  327. num--
  328. }
  329. else
  330. {
  331. client_cmd(0,"spk Gman/Gman_Choose2")
  332. format(menu,1999,"[AMXX] Vote for -->^nNext Map:%s",menu)
  333. show_menu(0,keys,menu,get_pcvar_num(delay_tally_time_pcvar),"CustomNextMap")
  334. }
  335. }
  336.  
  337. public saynextmap(id)
  338. {
  339. if(strlen(cur_nextmap)) ColorChat(0, "[AMXX] ^1Nextmap: ^4%s",cur_nextmap)
  340. else ColorChat( 0, "^1[^4AMXX^1] ^4Nextmap^1 not chosen yet.")
  341. }
  342.  
  343. public say_hook(id)
  344. {
  345. new text[64]
  346. read_args(text,63)
  347. remove_quotes(text)
  348.  
  349. new string[32]
  350. for(new i=0;i<sizeof(say_commands);i++)
  351. {
  352. format(string,31,"%s",say_commands[i])
  353. if(containi(text,string)==0) return sayrockthevote(id);
  354. }
  355.  
  356. for(new i=0;i<sizeof(say_commands2);i++)
  357. {
  358. format(string,31,"%s ",say_commands2[i])
  359. if(containi(text,string)==0)
  360. {
  361. replace(text,63,string,"")
  362. return saynominate(id,text);
  363. }
  364. }
  365.  
  366. if(is_map_valid2(text)) return saynominate(id,text);
  367.  
  368. return PLUGIN_CONTINUE
  369. }
  370.  
  371. public sayrockthevote(id)
  372. {
  373. if(voterocked==-1.0)
  374. {
  375. ColorChat( 0, "[AMXX] ^1Voting Currently in Process.")
  376. }
  377. else if((!voterocked && get_gametime()>get_pcvar_num(rtv_wait_pcvar)) || (get_gametime() - voterocked) > get_pcvar_num(rtv_wait_pcvar))
  378. {
  379. if(get_pcvar_num(rtv_percent_pcvar)>0 && get_pcvar_num(rtv_percent_pcvar)<=100)
  380. {
  381. if(rtv[id])
  382. {
  383. ColorChat( 0, "[AMXX] ^1You have already ^4voted^1 to Rock the Vote.")
  384. }
  385. else
  386. {
  387. rtv[id]=true
  388. rtvtotal++
  389.  
  390. new num2, players[32]
  391. get_players(players,num2,"ch")
  392.  
  393. new name[32]
  394. get_user_name(id,name,31)
  395.  
  396. new num3 = floatround((num2 * get_pcvar_float(rtv_percent_pcvar) / 100.0) - rtvtotal,floatround_ceil)
  397.  
  398. if(num3<=0)
  399. {
  400. ColorChat( 0, "[AMXX] %s ^1has ^4voted^1 to Rock the Vote.",name)
  401. ColorChat( 0, "[AMXX] ^1The ^4Vote ^1has been Rocked!")
  402.  
  403. make_menu(1)
  404.  
  405. voterocked2=true
  406. }
  407. else
  408. {
  409. if(num3!=1) ColorChat( 0, "^1[^4AMXX^1] ^4%s ^1has ^4voted^1 to Rock the Vote. Need ^3%d^1 more players.",name,num3)
  410. else ColorChat( 0, "^1[^4AMXX^1] ^4 ^1has voted to Rock the Vote. Need 1 more player.",name)
  411. }
  412. }
  413. }
  414. else
  415. {
  416. ColorChat( 0, "[AMXX] ^1Rock the ^4Vote^1 is disabled.")
  417. }
  418. }
  419. else if(voterocked>0.0)
  420. {
  421. ColorChat( 0, "[AMXX] ^1Cannot Rock the ^4Vote^1 again for another ^4%d^1 seconds.",get_pcvar_num(rtv_wait_pcvar) - (floatround(get_gametime()) - floatround(voterocked)))
  422. }
  423. else
  424. {
  425. ColorChat( 0, "[AMXX] ^1Cannot Rock the ^4Vote^1 till ^3%d^1 seconds after map start. (^4%d ^1more seconds)",get_pcvar_num(rtv_wait_pcvar),get_pcvar_num(rtv_wait_pcvar) - floatround(get_gametime()))
  426. }
  427.  
  428. return PLUGIN_CONTINUE
  429. }
  430.  
  431. public saynominate(id,nom_map[64])
  432. {
  433. if(has_nominated[id])
  434. {
  435. ColorChat( 0, "[AMXX] ^1You have already ^3nominated^1 a map.")
  436. }
  437. else if(is_map_valid2(nom_map))
  438. {
  439. if(equali(nom_map,currentmap))
  440. {
  441. ColorChat( 0, "[AMXX] ^1Cannot nominated the ^4current^1-^3map^1.")
  442. return PLUGIN_CONTINUE
  443. }
  444. else if(!get_pcvar_num(lastmap_pcvar) && equali(nom_map,lastmap))
  445. {
  446. ColorChat( 0, "[AMXX] ^1Cannot ^3nominated^1 the previous ^3map^1.")
  447. return PLUGIN_CONTINUE
  448. }
  449. else if(!get_pcvar_num(lastlastmap_pcvar) && equali(nom_map,lastlastmap))
  450. {
  451. ColorChat( 0, "[AMXX] ^1Cannot ^4nominated^1 the previous to previous map.")
  452. return PLUGIN_CONTINUE
  453. }
  454.  
  455. for(new i=0;i<num_nominated;i++)
  456. {
  457. if(equali(nominated[i],nom_map))
  458. {
  459. ColorChat( 0, "[AMXX] ^1That ^4map^1 has already been ^1nominated.")
  460. return PLUGIN_CONTINUE
  461. }
  462. }
  463.  
  464. format(nominated[num_nominated],31,"%s",nom_map)
  465. num_nominated++
  466.  
  467. new name[32]
  468. get_user_name(id,name,31)
  469. ColorChat( id, "[AMXX] %s ^1nominated ^3%s.",name,nom_map)
  470. has_nominated[id] = true
  471. }
  472. else
  473. {
  474. ColorChat( id, "[AMXX] ^1That map does not exist on this server.")
  475. }
  476.  
  477. return PLUGIN_CONTINUE
  478. }
  479.  
  480. public is_map_valid2(map[])
  481. {
  482. if(is_map_valid(map) &&
  483. containi(map,"<")==-1 &&
  484. containi(map,"\")==-1 &&
  485. containi(map,"/")==-1 &&
  486. containi(map,">")==-1 &&
  487. containi(map,"?")==-1 &&
  488. containi(map,"|")==-1 &&
  489. containi(map,"*")==-1 &&
  490. containi(map,":")==-1 &&
  491. containi(map,"^"")==-1
  492. )
  493. return 1;
  494.  
  495. return 0;
  496. }
  497.  
  498. public Check_Endround()
  499. {
  500. if(voterocked==-1.0)
  501. return ;
  502.  
  503. new bool:continuea=false
  504.  
  505. if(cstrike)
  506. {
  507. new winlimit = get_pcvar_num(mp_winlimit)
  508. if(winlimit)
  509. {
  510. new c = winlimit - 2
  511. if(!((c> g_teamScore[0]) && (c>g_teamScore[1]) ))
  512. {
  513. continuea=true
  514. }
  515. }
  516.  
  517. new maxrounds = get_pcvar_num(mp_maxrounds)
  518.  
  519. if(maxrounds)
  520. {
  521. if(!((maxrounds - 2) > (g_teamScore[0] + g_teamScore[1])))
  522. {
  523. continuea=true
  524. }
  525. }
  526. }
  527.  
  528. new timeleft = get_timeleft()
  529. if(!(timeleft < 1 || timeleft > 129))
  530. {
  531. continuea=true
  532. }
  533.  
  534. if(!continuea)
  535. return ;
  536.  
  537. remove_task(1337)
  538.  
  539. make_menu(1)
  540.  
  541. return ;
  542. }
  543.  
  544. public VoteCount(id,key)
  545. {
  546. if(voting)
  547. {
  548. new name[32]
  549. get_user_name(id,name,31)
  550. if(key==8)
  551. {
  552. if(get_pcvar_num(showvotes_pcvar)) ColorChat( 0, "^1[^4AMXX^1] ^4%s ^1voted for map extension.",name)
  553. votes[9]++
  554. }
  555. else if(key==9)
  556. {
  557. if(get_pcvar_num(showvotes_pcvar)) ColorChat( 0, "^1[^4AMXX^1] ^4%s ^1didn't vote.",name)
  558. }
  559. else if(strlen(maps[key+1]))
  560. {
  561. if(get_pcvar_num(showvotes_pcvar)) ColorChat( 0, "^1[^4AMXX^1] ^4%s ^1voted for ^3%s.",name,maps[key+1])
  562. votes[key+1]++
  563. }
  564. else
  565. {
  566. show_menu(id,keys,menu,-1,"CustomNextMap")
  567. }
  568. }
  569. return PLUGIN_HANDLED
  570. }
  571.  
  572. public VoteTally(num)
  573. {
  574. voting=false
  575. new winner[2]
  576. for(new i=1;i<10;i++)
  577. {
  578. if(votes[i]>winner[1])
  579. {
  580. winner[0]=i
  581. winner[1]=votes[i]
  582. }
  583. votes[i]=0
  584. }
  585. if(!winner[1])
  586. {
  587. if(!voterocked2)
  588. {
  589. new mapname[32]
  590. get_cvar_string("qq_lastmap",mapname,31)
  591. set_cvar_string("qq_lastlastmap",mapname)
  592. get_mapname(mapname,31)
  593. set_cvar_string("qq_lastmap",mapname)
  594. ColorChat( 0, "[AMXX] ^1No one ^4voted^1. Random Map coming.")
  595. }
  596. else
  597. {
  598. ColorChat( 0, "[AMXX] ^1No one ^4voted.")
  599. voterocked=get_gametime()
  600. }
  601. }
  602. else if(winner[0]==9)
  603. {
  604. if(!voterocked2)
  605. {
  606. ColorChat( 0, "[AMXX] ^3Map^1 extending ^4Won.^1 Extending map for ^3%d^1 minutes.",get_pcvar_num(extendtime_pcvar))
  607. set_pcvar_float(mp_timelimit,get_pcvar_float(mp_timelimit) + get_pcvar_num(extendtime_pcvar))
  608. set_task(15.0,"Check_Endround",1337,"",0,"b")
  609. extended++
  610. }
  611. else
  612. {
  613. ColorChat( 0, "[AMXX] ^3Map ^1extending ^4Won.^1 No new map.")
  614. }
  615. voterocked=get_gametime()
  616. }
  617. else
  618. {
  619. new mapname[32]
  620. get_cvar_string("qq_lastmap",mapname,31)
  621. set_cvar_string("qq_lastlastmap",mapname)
  622. get_mapname(mapname,31)
  623. set_cvar_string("qq_lastmap",mapname)
  624. ColorChat( 0, "[AMXX] Voting ^1Over. ^3Nextmap^1 will be ^4%s ^1!",maps[winner[0]])
  625. if(!voterocked2)
  626. {
  627. set_cvar_string("amx_nextmap",maps[winner[0]])
  628. set_task(1.0,"change_level",winner[0],"",0,"d")
  629. }
  630. else
  631. {
  632. set_task(5.0,"change_level",winner[0])
  633. }
  634. format(cur_nextmap,31,"%s",maps[winner[0]])
  635. }
  636. for(new i=0;i<=32;i++) rtv[i]=false
  637.  
  638. voterocked2=false
  639. }
  640.  
  641. public change_level(map)
  642. {
  643. server_cmd("amx_map %s",maps[map])
  644. }
  645.  
  646. //From the AMXX nextmap base file
  647. public team_score()
  648. {
  649. new team[2]
  650. read_data(1,team,1)
  651. g_teamScore[(team[0]=='C') ? 0 : 1] = read_data(2)
  652. }
  653.  
  654. stock ColorChat( index, message[], any:... )
  655. {
  656. if( index && !is_user_connected( index ) )
  657. return 0;
  658.  
  659. static szMessage[ 242 ], len;
  660.  
  661. len = formatex( szMessage, charsmax( szMessage ), "^4" );
  662. len += vformat( szMessage[ len ], charsmax( szMessage ) - len, message, 3 );
  663.  
  664. static st_msgid;
  665. if( !st_msgid )
  666. st_msgid = get_user_msgid( "SayText" );
  667.  
  668. if( index )
  669. {
  670. message_begin( MSG_ONE_UNRELIABLE, st_msgid, _, index );
  671. write_byte( index );
  672. write_string( szMessage );
  673. message_end( );
  674. }
  675. else
  676. {
  677. for( index = 1 ; index <= g_iMaxPlayers ; index ++ )
  678. {
  679. if( !is_user_connected( index ) )
  680. continue;
  681.  
  682. message_begin( MSG_ONE_UNRELIABLE, st_msgid, _, index );
  683. write_byte( index );
  684. write_string( szMessage );
  685. message_end( );
  686. }
  687. }
  688. return 1;
  689. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement