hlmod.hu

Magyar Half-Life Mód közösség!
Pontos idő: 2024.05.10. 06:18



Jelenlévő felhasználók

Jelenleg 476 felhasználó van jelen :: 0 regisztrált, 0 rejtett és 476 vendég

A legtöbb felhasználó (1565 fő) 2020.11.21. 11:26-kor tartózkodott itt.

Regisztrált felhasználók: nincs regisztrált felhasználó az elmúlt 5 percben aktív felhasználók alapján

Utoljára aktív
Ahhoz hogy lásd ki volt utoljára aktív, be kell jelentkezned.



Az oldal teljeskörű
használatához regisztrálj.

Regisztráció

Kereső


Új téma nyitása  Hozzászólás a témához  [ 2 hozzászólás ] 
Szerző Üzenet
 Hozzászólás témája: Team Limiter!
HozzászólásElküldve: 2014.09.06. 14:28 
Offline
Beavatott

Csatlakozott: 2014.05.23. 18:32
Hozzászólások: 68
Megköszönt másnak: 88 alkalommal
Megköszönték neki: 2 alkalommal
Valaki ezt átírja hogy 5-té csapatnál 2-ct lehessen? Meg hozzá hasnonló
SMA Forráskód: [ Mindet kijelol ]
  1. #include < amxmodx >
  2. #include < amxmisc >
  3. #include < engine >
  4. #include < cstrike >
  5. #include < hamsandwich >
  6.  
  7. #define OppositeTeam(%1) CsTeams:( ( ( _:%1 ) % 2 ) + 1 )
  8. /*CsTeams:OppositeTeam( CsTeams:iTeam )
  9. {
  10. return CsTeams:( ( ( _:iTeam ) % 2 ) + 1 );
  11. }*/
  12.  
  13. #define MAX_PLAYERS 32
  14.  
  15. new const g_szSpawnClassnames[ CsTeams ][ ] =
  16. {
  17. "",
  18. "info_player_deathmatch",
  19. "info_player_start",
  20. ""
  21. };
  22.  
  23. new const g_szFakeSpawnClassnames[ CsTeams ][ ] =
  24. {
  25. "",
  26. "removed_t_spawn",
  27. "removed_ct_spawn",
  28. ""
  29. };
  30.  
  31. enum _:RemoveMethods
  32. {
  33. Remove_Kick,
  34. Remove_Spec,
  35. Remove_Transfer
  36. };
  37.  
  38. const g_iDefaultMethod = Remove_Spec;
  39.  
  40. new const g_szRemoveMethods[ RemoveMethods ][ ] =
  41. {
  42. "kick",
  43. "spec",
  44. "transfer"
  45. };
  46.  
  47. new Trie:g_tMethodNameToIndex;
  48.  
  49. new Float:g_fJoinTime[ MAX_PLAYERS + 1 ];
  50.  
  51. new pCvar_RemoveMethod;
  52.  
  53. new bool:g_bFreezeTime = false;
  54.  
  55. public plugin_init( )
  56. {
  57. register_plugin( "Team Limiter", "0.0.3", "Exolent" );
  58.  
  59. register_concmd( "team_limits", "CmdSetTeamLimits", ADMIN_RCON, "<terrorist limit> <ct limit> -- * for map default" );
  60.  
  61. register_event( "HLTV", "EventNewRound", "a", "1=0", "2=0" );
  62. register_logevent( "EventRoundStart", 2, "1=Round_Start" );
  63.  
  64. pCvar_RemoveMethod = register_cvar( "tl_remove", g_szRemoveMethods[ g_iDefaultMethod ] );
  65.  
  66. g_tMethodNameToIndex = TrieCreate( );
  67.  
  68. for( new iMethod = 0; iMethod < RemoveMethods; iMethod++ )
  69. {
  70. TrieSetCell( g_tMethodNameToIndex, g_szRemoveMethods[ iMethod ], iMethod );
  71. }
  72. }
  73.  
  74. public plugin_end( )
  75. {
  76. TrieDestroy( g_tMethodNameToIndex );
  77. }
  78.  
  79. public client_putinserver( iPlayer )
  80. {
  81. g_fJoinTime[ iPlayer ] = get_gametime( );
  82. }
  83.  
  84. public CmdSetTeamLimits( iAdmin, iLevel, iCID )
  85. {
  86. if( !cmd_access( iAdmin, iLevel, iCID, 3 ) )
  87. {
  88. return PLUGIN_HANDLED;
  89. }
  90.  
  91. new szT[ 3 ], szCT[ 3 ];
  92. read_argv( 1, szT, charsmax( szT ) );
  93. read_argv( 2, szCT, charsmax( szCT ) );
  94.  
  95. new iNewLimit[ CsTeams ];
  96. iNewLimit[ CS_TEAM_T ] = is_str_num( szT ) ? str_to_num( szT ) : -1;
  97. iNewLimit[ CS_TEAM_CT ] = is_str_num( szCT ) ? str_to_num( szCT ) : -1;
  98.  
  99. if( iNewLimit[ CS_TEAM_T ] < 0 && iNewLimit[ CS_TEAM_CT ] < 0 )
  100. {
  101. console_print( iAdmin, "Setting both limits to < 0 doesn't change the team limit of either team." );
  102. return PLUGIN_HANDLED;
  103. }
  104.  
  105. new iRemoveMethod = GetRemoveMethod( );
  106.  
  107. new iAllPlayers[ MAX_PLAYERS ], iAllNum;
  108. get_players( iAllPlayers, iAllNum );
  109.  
  110. new iPlayers[ CsTeams ][ MAX_PLAYERS ], iNum[ CsTeams ];
  111.  
  112. new iPlayer, CsTeams:iTeam;
  113. for( new i = 0; i < iAllNum; i++ )
  114. {
  115. iPlayer = iAllPlayers[ i ];
  116. iTeam = cs_get_user_team( iPlayer );
  117.  
  118. iPlayers[ iTeam ][ iNum[ iTeam ]++ ] = iPlayer;
  119. }
  120.  
  121. new iTransferPlayers[ CsTeams ][ MAX_PLAYERS ], iTransferNum[ CsTeams ];
  122.  
  123. new bool:bSame = true;
  124. new iCurLimit;
  125. new iFakeCount;
  126. new iDiff;
  127. new iEntity;
  128.  
  129. for( new CsTeams:iTeam = CS_TEAM_T; iTeam <= CS_TEAM_CT; iTeam++ )
  130. {
  131. iCurLimit = 0;
  132. iEntity = 0;
  133. while( ( iEntity = find_ent_by_class( iEntity, g_szSpawnClassnames[ iTeam ] ) ) )
  134. {
  135. iCurLimit++;
  136. }
  137.  
  138. if( iNewLimit[ iTeam ] < 0 )
  139. {
  140. // there is no limit, so check if fake ones exist so the maximum spawns are available
  141.  
  142. iFakeCount = 0;
  143. iEntity = 0;
  144. while( ( iEntity = find_ent_by_class( iEntity, g_szFakeSpawnClassnames[ iTeam ] ) ) )
  145. {
  146. iFakeCount++;
  147. }
  148.  
  149. // set to real spawns + fake spawns (even if no fake ones exist, it will still skip)
  150. iNewLimit[ iTeam ] = iCurLimit + iFakeCount;
  151. }
  152.  
  153. iDiff = iCurLimit - iNewLimit[ iTeam ];
  154.  
  155. if( !iDiff )
  156. {
  157. continue;
  158. }
  159.  
  160. bSame = false;
  161.  
  162. if( iDiff > 0 )
  163. {
  164. // current > new = deleting
  165.  
  166. iCurLimit = iDiff;
  167. while( iDiff > 0 )
  168. {
  169. iEntity = find_ent_by_class( -1, g_szSpawnClassnames[ iTeam ] );
  170.  
  171. if( !is_valid_ent( iEntity ) )
  172. {
  173. iNewLimit[ iTeam ] += iDiff;
  174.  
  175. console_print( iAdmin, "There were not enough %sT spawn points to remove. Only removed %i of %i.",\
  176. iTeam == CS_TEAM_T ? "" : "C", ( iCurLimit - iDiff ), iCurLimit );
  177.  
  178. break;
  179. }
  180.  
  181. entity_set_string( iEntity, EV_SZ_classname, g_szFakeSpawnClassnames[ iTeam ] );
  182.  
  183. iDiff--;
  184. }
  185.  
  186. iDiff = iNum[ iTeam ] - iNewLimit[ iTeam ];
  187.  
  188. if( iDiff > 0 )
  189. {
  190. // more players than spawn points
  191.  
  192. if( iNum[ iTeam ] > 1 )
  193. {
  194. // sort from earliest joining to latest
  195. SortCustom1D( iPlayers[ iTeam ], iNum[ iTeam ], "SortByJoinTime" );
  196. }
  197.  
  198. // last players in array are the last players who joined
  199. while( iDiff > 0 )
  200. {
  201. iPlayer = iPlayers[ iTeam ][ iNum[ iTeam ] - iDiff ];
  202.  
  203. switch( iRemoveMethod )
  204. {
  205. case Remove_Kick:
  206. {
  207. message_begin( MSG_ONE, SVC_DISCONNECT, _, iPlayer );
  208. write_string( "Sorry, your spawn point was removed." );
  209. message_end( );
  210. }
  211. case Remove_Spec:
  212. {
  213. TransferPlayer( iPlayer, CS_TEAM_SPECTATOR );
  214. }
  215. case Remove_Transfer:
  216. {
  217. iTransferPlayers[ iTeam ][ iTransferNum[ iTeam ]++ ] = iPlayer;
  218. }
  219. }
  220.  
  221. iDiff--;
  222. }
  223. }
  224. }
  225. else
  226. {
  227. // current < new = adding
  228. iDiff *= -1;
  229.  
  230. iCurLimit = iDiff;
  231. while( iDiff > 0 )
  232. {
  233. iEntity = find_ent_by_class( -1, g_szFakeSpawnClassnames[ iTeam ] );
  234.  
  235. if( !is_valid_ent( iEntity ) )
  236. {
  237. iNewLimit[ iTeam ] -= iDiff;
  238.  
  239. console_print( iAdmin, "There were not enough %sT spawn points to restore. Only restored %i of %i.",\
  240. iTeam == CS_TEAM_T ? "" : "C", ( iCurLimit - iDiff ), iCurLimit );
  241.  
  242. break;
  243. }
  244.  
  245. entity_set_string( iEntity, EV_SZ_classname, g_szSpawnClassnames[ iTeam ] );
  246.  
  247. iDiff--;
  248. }
  249. }
  250. }
  251.  
  252. if( bSame )
  253. {
  254. console_print( iAdmin, "The teams are already limited to this amount." );
  255. }
  256. else
  257. {
  258. if( iRemoveMethod == Remove_Transfer )
  259. {
  260. // find how many both need to transfer so they don't just trade places
  261. new iSame = min( iTransferNum[ CS_TEAM_T ], iTransferNum[ CS_TEAM_CT ] );
  262. new i;
  263. new CsTeams:iOppositeTeam;
  264. new iAvailable;
  265.  
  266. for( new CsTeams:iTeam = CS_TEAM_T; iTeam <= CS_TEAM_CT; iTeam++ )
  267. {
  268. SortCustom1D( iTransferPlayers[ iTeam ], iTransferNum[ iTeam ], "SortByJoinTime" );
  269.  
  270. // transfer last joined players who can't fit on a team to spectator
  271. for( i = 0; i < iSame; i++ )
  272. {
  273. TransferPlayer( iTransferPlayers[ iTeam ][ iTransferNum[ iTeam ] - i - 1 ], CS_TEAM_SPECTATOR );
  274. }
  275.  
  276. // find how many players need to be transferred
  277. iDiff = iTransferNum[ iTeam ] - iSame;
  278.  
  279. // get opposite team to transfer to
  280. iOppositeTeam = OppositeTeam( iTeam );
  281.  
  282. // find how many slots are available for players
  283. iAvailable = iNewLimit[ iOppositeTeam ] - iNum[ iOppositeTeam ];
  284.  
  285. // available < needed = move extra players to spectator
  286. while( i < iTransferNum[ iTeam ] )
  287. {
  288. TransferPlayer( iTransferPlayers[ iTeam ][ iTransferNum[ iTeam ] - i - 1 ], ( iAvailable < iDiff ) ? CS_TEAM_SPECTATOR : iOppositeTeam );
  289.  
  290. iDiff--;
  291. i++;
  292. }
  293. }
  294. }
  295.  
  296. console_print( iAdmin, "The teams have been limited to T:%i, CT:%i", iNewLimit[ CS_TEAM_T ], iNewLimit[ CS_TEAM_CT ] );
  297.  
  298. new szName[ 32 ];
  299. get_user_name( iAdmin, szName, charsmax( szName ) );
  300.  
  301. new szSteamID[ 35 ];
  302. get_user_authid( iAdmin, szSteamID, charsmax( szSteamID ) );
  303.  
  304. show_activity( iAdmin, szName, "limited the teams to T:%i, CT:%i", iNewLimit[ CS_TEAM_T ], iNewLimit[ CS_TEAM_CT ] );
  305.  
  306. log_amx( "%s<%s> limited the teams to T:%i, CT:%i", szName, szSteamID, iNewLimit[ CS_TEAM_T ], iNewLimit[ CS_TEAM_CT ] );
  307. }
  308.  
  309. return PLUGIN_HANDLED;
  310. }
  311.  
  312. public EventNewRound( )
  313. {
  314. g_bFreezeTime = true;
  315. }
  316.  
  317. public EventRoundStart( )
  318. {
  319. g_bFreezeTime = false;
  320. }
  321.  
  322. public SortByJoinTime( iIndex1, iIndex2, iPlayers[ ], iData[ ], iDataSize )
  323. {
  324. return ( ( g_fJoinTime[ iPlayers[ iIndex1 ] ] - g_fJoinTime[ iPlayers[ iIndex2 ] ] ) < 0.0 ) ? -1 : 1;
  325. }
  326.  
  327. GetRemoveMethod( )
  328. {
  329. new szMethod[ 32 ];
  330. get_pcvar_string( pCvar_RemoveMethod, szMethod, charsmax( szMethod ) );
  331. strtolower( szMethod );
  332.  
  333. new iMethod;
  334. if( TrieGetCell( g_tMethodNameToIndex, szMethod, iMethod ) )
  335. {
  336. return iMethod;
  337. }
  338.  
  339. if( is_str_num( szMethod ) )
  340. {
  341. iMethod = str_to_num( szMethod );
  342.  
  343. if( 0 <= iMethod < RemoveMethods )
  344. {
  345. return iMethod;
  346. }
  347. }
  348.  
  349. static szInvalidMessage[ 128 ];
  350. new iLen = formatex( szInvalidMessage, charsmax( szInvalidMessage ), "Invalid remove method '%s'. Valid Methods: [", szMethod );
  351.  
  352. for( iMethod = 0; iMethod < RemoveMethods; iMethod++ )
  353. {
  354. iLen += formatex( szInvalidMessage[ iLen ], charsmax( szInvalidMessage ) - iLen, "'%s', ", g_szRemoveMethods[ iMethod ] );
  355. }
  356.  
  357. // remove the last ", " from the end
  358. iLen -= 2;
  359.  
  360. copy( szInvalidMessage[ iLen ], charsmax( szInvalidMessage ) - iLen, "]" );
  361.  
  362. log_amx( "%s", szInvalidMessage );
  363.  
  364. set_pcvar_string( pCvar_RemoveMethod, g_szRemoveMethods[ g_iDefaultMethod ] );
  365.  
  366. return g_iDefaultMethod;
  367. }
  368.  
  369. TransferPlayer( iPlayer, CsTeams:iTeam )
  370. {
  371. static const szTeamNames[ CsTeams ][ ] =
  372. {
  373. "Spectator",
  374. "Terrorist",
  375. "Counter-Terrorist",
  376. "Spectator"
  377. };
  378.  
  379. client_print( iPlayer, print_chat, "* Sorry, your spawn point was removed, so you are now a %s.", szTeamNames[ iTeam ] );
  380.  
  381. cs_set_user_team( iPlayer, iTeam );
  382.  
  383. if( is_user_alive( iPlayer ) )
  384. {
  385. // if switched teams during freezetime, revive player
  386. if( ( CS_TEAM_T <= iTeam <= CS_TEAM_CT ) && g_bFreezeTime )
  387. {
  388. ExecuteHamB( Ham_CS_RoundRespawn, iPlayer );
  389. }
  390. else
  391. {
  392. user_silentkill( iPlayer );
  393. }
  394. }
  395. }
  396. /* AMXX-Studio Notes - DO NOT MODIFY BELOW HERE
  397. *{\\ rtf1\\ ansi\\ deff0{\\ fonttbl{\\ f0\\ fnil Tahoma;}}\n\\ viewkind4\\ uc1\\ pard\\ lang1033\\ f0\\ fs16 \n\\ par }
  398. */


Hozzászólás jelentése
Vissza a tetejére
   
 Hozzászólás témája: Re: Team Limiter!
HozzászólásElküldve: 2014.09.07. 23:15 
Offline
Beavatott
Avatar

Csatlakozott: 2014.07.03. 12:19
Hozzászólások: 81
Megköszönt másnak: 2 alkalommal
Megköszönték neki: 7 alkalommal
Szia!
5 té csapatnál 2 CT lehessen? WTF? Na mind1.
Ha arra gondoltál, hogy ha van 5 Terror akkor 2 CT lehessen,akkor ittvan ez: Team Join Management by Exolent
Itt mindent be tudsz állítani kedvedre és nem kell átírni semmit.
Amúgymeg azt hiszem, a szervered server.cfg nevű fájljában be lehet valahogy állítani ezt,
de fejből már nem emlékszem hogyan.


Hozzászólás jelentése
Vissza a tetejére
   
Hozzászólások megjelenítése:  Rendezés  
Új téma nyitása  Hozzászólás a témához  [ 2 hozzászólás ] 


Ki van itt

Jelenlévő fórumozók: nincs regisztrált felhasználó valamint 13 vendég


Nyithatsz új témákat ebben a fórumban.
Válaszolhatsz egy témára ebben a fórumban.
Nem szerkesztheted a hozzászólásaidat ebben a fórumban.
Nem törölheted a hozzászólásaidat ebben a fórumban.
Nem küldhetsz csatolmányokat ebben a fórumban.

Keresés:
Ugrás:  
Powered by phpBB® Forum Software © phpBB Limited
Magyar fordítás © Magyar phpBB Közösség
Portal: Kiss Portal Extension © Michael O'Toole