HLMOD.HU Forrás Megtekintés - www.hlmod.hu
  1. /*
  2. Fordította: BBk
  3. */
  4.  
  5. #include < amxmodx >
  6. #include < cstrike >
  7. #include < fakemeta >
  8. #include < hamsandwich >
  9.  
  10. const m_toggle_state = 41;
  11.  
  12. #define TASK_VOTE 237439
  13.  
  14. enum _:VOTES {
  15. VOTE_YES,
  16. VOTE_NO
  17. };
  18.  
  19. new g_iVotes[ VOTES ];
  20. new bool:g_bVoted[ 33 ];
  21. new bool:g_bFreeRound;
  22. new bool:g_bWillFree;
  23. new bool:g_bVoting;
  24. new g_iCountdown;
  25. new g_iRounds;
  26. new g_iPrinted;
  27. new g_iMenuID;
  28. new g_iMaxplayers;
  29. new g_iMsgSayText;
  30. new g_pWaitRounds;
  31.  
  32. public plugin_init( ) {
  33. new const VERSION[ ] = "1.0";
  34.  
  35. register_plugin( "Halalfutam: Szabad-Kor", VERSION, "xPaw" );
  36.  
  37. new p = register_cvar( "deathrun_freeround", VERSION, FCVAR_SERVER | FCVAR_SPONLY );
  38. set_pcvar_string( p, VERSION );
  39.  
  40. g_pWaitRounds = register_cvar( "freerun_wait_rounds", "5" );
  41. g_iMaxplayers = get_maxplayers( );
  42. g_iMsgSayText = get_user_msgid( "SayText" );
  43. g_iMenuID = register_menuid( "DrunFreeRoundVote" );
  44.  
  45. register_menucmd( g_iMenuID, ( MENU_KEY_1 | MENU_KEY_2 | MENU_KEY_0 ), "HandleVote" );
  46.  
  47. register_clcmd( "say /free", "CmdFreeRound" );
  48. register_clcmd( "say /freeround", "CmdFreeRound" );
  49.  
  50. RegisterHam( Ham_Use, "func_rot_button", "FwdHamUse_Button" );
  51. RegisterHam( Ham_Use, "func_button", "FwdHamUse_Button" );
  52. RegisterHam( Ham_Use, "button_target", "FwdHamUse_Button" );
  53.  
  54. register_event( "CurWeapon", "EventCurWeapon", "be", "1=1", "2!29" );
  55. register_event( "HLTV", "EventNewRound", "a", "1=0", "2=0" );
  56. register_event( "TextMsg", "EventRestart", "a", "2&#Game_C", "2&#Game_w" );
  57. }
  58.  
  59. public EventNewRound( ) {
  60. if( g_bFreeRound ) {
  61. g_bFreeRound = false;
  62. g_iRounds = 0;
  63. g_iPrinted = 0;
  64.  
  65. return;
  66. }
  67. else if( g_bWillFree ) {
  68. g_iRounds = 0;
  69. g_iPrinted = 0;
  70. g_bWillFree = false;
  71. g_bFreeRound = true;
  72.  
  73. set_task( 2.0, "PrintMessage" );
  74.  
  75. return;
  76. }
  77.  
  78. g_iRounds++;
  79.  
  80. if( g_iPrinted < 4 && g_iRounds >= get_pcvar_num( g_pWaitRounds ) ) {
  81. GreenPrint( 0, "Ez a szerver^3 a Deathrun Szabad-Kor Rendszert hasznalja^1 Keszitette:^4 xPaw^1, ird be^4 /free^1 a szavazas megkezdesehez!" );
  82.  
  83. g_iPrinted++;
  84. }
  85. }
  86.  
  87. public EventRestart( ) {
  88. g_bFreeRound = false;
  89. g_bWillFree = false;
  90. g_bVoting = false;
  91. g_iPrinted = 0;
  92. g_iRounds = 0;
  93.  
  94. remove_task( TASK_VOTE );
  95. }
  96.  
  97. public EventCurWeapon( id )
  98. if( g_bFreeRound )
  99. engclient_cmd( id, "weapon_knife" );
  100.  
  101. public CmdFreeRound( id ) {
  102. if( cs_get_user_team( id ) != CS_TEAM_T ) {
  103. GreenPrint( id, "Ez a parancs csak a terroristak szamara elerheto!" );
  104.  
  105. return PLUGIN_CONTINUE;
  106. }
  107. else if( g_bFreeRound ) {
  108. GreenPrint( id, "Mar szabad-kor van!" );
  109.  
  110. return PLUGIN_CONTINUE;
  111. }
  112. else if( g_bVoting ) {
  113. GreenPrint( id, "A szavazas mar folyamatban van!" );
  114.  
  115. return PLUGIN_CONTINUE;
  116. }
  117. else if( g_bWillFree ) {
  118. GreenPrint( id, "A Kovetkezo kor szabad lesz!" );
  119.  
  120. return PLUGIN_CONTINUE;
  121. }
  122.  
  123. new iWaitRounds = get_pcvar_num( g_pWaitRounds ) - g_iRounds;
  124.  
  125. if( iWaitRounds > 0 ) {
  126. GreenPrint( id, "Varnod kell meg^3 %i^1 kort a szavazas elinditasahoz!", iWaitRounds );
  127.  
  128. return PLUGIN_CONTINUE;
  129. }
  130.  
  131. new szName[ 32 ];
  132. get_user_name( id, szName, 31 );
  133.  
  134. GreenPrint( 0, "A Szavazas elkezdodott:^3 %s^1.", szName );
  135.  
  136. set_hudmessage( 222, 70, 0, -1.0, 0.3, 1, 3.0, 3.0, 2.0, 1.0, -1 );
  137. show_hudmessage( 0, "A Szabad-kor szavazasa elkezdodott: %s^nA szavazas hamarosan megkezdodik.", szName );
  138.  
  139. g_iVotes[ VOTE_YES ] = 0;
  140. g_iVotes[ VOTE_NO ] = 0;
  141. g_iRounds = 0;
  142. g_bVoting = true;
  143. g_iPrinted = 0;
  144. g_bWillFree = false;
  145.  
  146. arrayset( g_bVoted, false, 32 );
  147.  
  148. remove_task( TASK_VOTE );
  149. g_iCountdown = 15;
  150.  
  151. set_task( 3.5, "PreTask", TASK_VOTE );
  152.  
  153. return PLUGIN_CONTINUE;
  154. }
  155.  
  156. public PrintMessage( ) {
  157. GreenPrint( 0, "Ez egy^4 Szabad kor^1, nincsenek fegyverek es csapdak!" );
  158.  
  159. set_hudmessage( 0, 90, 0, -1.0, 0.35, 1, 3.0, 3.0, 2.0, 1.0, -1 );
  160. show_hudmessage( 0, "SZABAD-KOR!" );
  161. }
  162.  
  163. public PreTask( ) {
  164. remove_task( TASK_VOTE );
  165.  
  166. set_task( 1.0, "TaskVoteTimer", TASK_VOTE, _, _, "b" );
  167. }
  168.  
  169. public TaskVoteTimer( ) {
  170. g_iCountdown--;
  171.  
  172. if ( !g_iCountdown ) {
  173. remove_task( TASK_VOTE );
  174.  
  175. g_bVoting = false;
  176.  
  177. new iVotes, iHighVotes, iHighVotesID;
  178.  
  179. for( new i; i < VOTES; i++ ) {
  180. iVotes = g_iVotes[ i ];
  181.  
  182. if( iVotes >= iHighVotes ) {
  183. iHighVotes = iVotes;
  184. iHighVotesID = i;
  185. }
  186. }
  187.  
  188. if( iHighVotes > 0 ) {
  189. if( iHighVotesID == VOTE_YES )
  190. g_bWillFree = true;
  191.  
  192. GreenPrint( 0, "A szavazas veget ert. %s^1 [^3 %i^1 szavazata (^4%i%%) ^1]", g_bWillFree ? "A Kovetkezo kor szabad!" : "A Kovetkezo kor nem szabad!", iHighVotes, GetPercent( g_iVotes[ iHighVotesID ], g_iVotes[ VOTE_YES ] + g_iVotes[ VOTE_NO ] ) );
  193. } else
  194. GreenPrint( 0, "A szavazasnak vege. Nincs szavazat." );
  195.  
  196. for( new i = 1; i <= g_iMaxplayers; i++ )
  197. if( is_user_connected( i ) )
  198. ShowVoteMenu( i, 1 );
  199. } else {
  200. for( new i = 1; i <= g_iMaxplayers; i++ )
  201. if( is_user_connected( i ) )
  202. ShowVoteMenu( i, 0 );
  203. }
  204. }
  205.  
  206. ShowVoteMenu( id, bResults = 0 ) {
  207. new iMenu = GetUserMenu( id );
  208.  
  209. if( ( iMenu && iMenu != g_iMenuID ) && g_iCountdown <= 14 )
  210. return;
  211.  
  212. menu_cancel( id ); // Radios and other piece of shit bug fix :D
  213.  
  214. new szMenu[ 196 ], iLen;
  215.  
  216. if( bResults )
  217. iLen = formatex( szMenu, charsmax( szMenu ), "\rA szavazas eredmenyei:^n^n" );
  218. else
  219. iLen = formatex( szMenu, charsmax( szMenu ), "\rSzeretnel egy szabad kort?^n^n" );
  220.  
  221. new iVotesTotal = g_iVotes[ VOTE_YES ] + g_iVotes[ VOTE_NO ];
  222.  
  223. iLen += formatex( szMenu[ iLen ], charsmax( szMenu ) - 1, "\r1. \wIgen \d(%i%%)^n", GetPercent( g_iVotes[ VOTE_YES ], iVotesTotal ) );
  224. iLen += formatex( szMenu[ iLen ], charsmax( szMenu ) - 1, "\r2. \wNem \d(%i%%)^n^n", GetPercent( g_iVotes[ VOTE_NO ], iVotesTotal ) );
  225.  
  226. if( bResults ) {
  227. if( g_bWillFree )
  228. iLen += formatex( szMenu[ iLen ], charsmax( szMenu ) - 1, " \yA Kovetkezo kor szabad lesz!" );
  229. else {
  230. if( !iVotesTotal )
  231. iLen += formatex( szMenu[ iLen ], charsmax( szMenu ) - 1, " \yNincs szavazat!" );
  232. }
  233.  
  234. show_menu( id, ( MENU_KEY_1 | MENU_KEY_2 | MENU_KEY_0 ), szMenu, -1, "DrunFreeRoundVote" );
  235.  
  236. set_task( 5.0, "CloseMenu", id );
  237. } else {
  238. iLen += formatex( szMenu[ iLen ], charsmax( szMenu ) - 1, " \dvisszaszamlalas: \r%i", g_iCountdown );
  239.  
  240. show_menu( id, ( MENU_KEY_1 | MENU_KEY_2 ), szMenu, -1, "DrunFreeRoundVote" );
  241. }
  242. }
  243.  
  244. public CloseMenu( id )
  245. if( GetUserMenu( id ) == g_iMenuID )
  246. client_cmd( id, "slot1" );
  247.  
  248. GetUserMenu( id ) {
  249. new iMenu, iKeys;
  250. get_user_menu( id, iMenu, iKeys );
  251.  
  252. return iMenu;
  253. }
  254.  
  255. public HandleVote( id, iKey ) {
  256. if( !g_bVoting || !task_exists( TASK_VOTE ) )
  257. return;
  258.  
  259. if( g_bVoted[ id ] ) {
  260. ShowVoteMenu( id, 0 );
  261.  
  262. return;
  263. }
  264.  
  265. if( iKey > 1 )
  266. return;
  267.  
  268. new iVotes = ( /* get_user_flags( id ) & ADMIN_KICK ||*/ get_user_team( id ) == 1 ) ? 2 : 1;
  269.  
  270. g_bVoted[ id ] = true;
  271. g_iVotes[ iKey ] += iVotes;
  272.  
  273. new szName[ 32 ];
  274. get_user_name( id, szName, 31 );
  275.  
  276. GreenPrint( 0, "^3%s^1 szavazata:^4 %s^1. [^4+%i^1 szavazat]", szName, iKey == VOTE_YES ? "Igen" : "Nem", iVotes);
  277.  
  278. ShowVoteMenu( id, 0 );
  279. }
  280.  
  281. public FwdHamUse_Button( iEntity, id, iActivator, iUseType, Float:flValue ) {
  282. if( g_bFreeRound && iUseType == 2 && flValue == 1.0 && is_user_alive( id )
  283. && get_user_team( id ) == 1 && get_pdata_int( iEntity, m_toggle_state, 4 ) == 1 ) {
  284. /* Oh hi this code actually happen! :D */
  285.  
  286. set_hudmessage( 0, 100, 255, -1.0, 0.25, 0, 2.0, 2.0, 0.2, 0.2, 3 );
  287. show_hudmessage( id, "Szabad kor!^nA gombok inaktivak!" );
  288.  
  289. return HAM_SUPERCEDE;
  290. }
  291.  
  292. return HAM_IGNORED;
  293. }
  294.  
  295. GetPercent( is, of ) // Brad
  296. return ( of != 0 ) ? floatround( floatmul( float( is ) / float( of ), 100.0 ) ) : 0;
  297.  
  298. GreenPrint( id, const message[ ], any:... ) {
  299. static szMessage[ 192 ], iLen;
  300. if( !iLen )
  301. iLen = formatex( szMessage, 191, "^4[Halalfutam Szabad-Kor]^1 " );
  302.  
  303. vformat( szMessage[ iLen ], 191 - iLen, message, 3 );
  304.  
  305. message_begin( id ? MSG_ONE_UNRELIABLE : MSG_BROADCAST, g_iMsgSayText, _, id );
  306. write_byte( id ? id : 1 );
  307. write_string( szMessage );
  308. message_end( );
  309.  
  310. return 1;
  311. }