Advertisement
Guest User

Untitled

a guest
Feb 27th, 2011
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.08 KB | None | 0 0
  1. --  For team deathmatch support later, plus the unassigned colour is ugly as FUCK
  2.  
  3. -- team consts
  4. TEAM_UNASSIGNED     = 1001
  5. TEAM_SPECTATOR      = 1002
  6. TEAM_FREEFORALL     = 1003
  7. TEAM_RED            = 1004
  8. TEAM_BLUE           = 1005
  9.  
  10. -- set ups
  11. team.SetUp( TEAM_FREEFORALL, "Free-for-all", Color( 200, 50, 50, 255 ) );
  12. team.SetUp( TEAM_RED, "Red Team", Color( 200, 50, 50, 255 ) );
  13. team.SetUp( TEAM_BLUE, "Blue Team", Color( 50, 50, 200, 255 ) );
  14.  
  15. -- teams
  16. GM.Teams = {}
  17. GM.Teams[ "FFA" ] = { TEAM_FREEFORALL };
  18. GM.Teams[ "TDM" ] = { TEAM_RED, TEAM_BLUE };
  19.  
  20. -- models
  21. teamModels = {}
  22. teamModels[ TEAM_RED ] = { "models/player/breen.mdl", "models/player/combine_soldier.mdl", "models/player/combine_super_soldier.mdl", "models/player/combine_soldier_prisonguard.mdl", "models/player/police.mdl", "models/player/soldier_stripped.mdl" };
  23. teamModels[ TEAM_BLUE ] = { "models/player/kleiner.mdl", "models/player/alyx.mdl", "models/player/eli.mdl", "models/player/gman_high.mdl", "models/player/barney.mdl", "models/player/Group03/male_01.mdl" };
  24.  
  25. function GM:IsTeamPlay()
  26.     return GetGlobalBool( "Teamplay", false );
  27. end
  28.  
  29. function GM:GetTeamList()
  30.     if( GAMEMODE:IsTeamPlay() ) then
  31.         return GAMEMODE.Teams[ "TDM" ];
  32.     else
  33.         return GAMEMODE.Teams[ "FFA" ];
  34.     end
  35. end
  36.  
  37. function GM:PrecacheTeamModels()
  38.     -- precache stuff
  39.     for k, v in pairs( teamModels ) do
  40.         for kk, vv in pairs( v ) do
  41.             util.PrecacheModel( vv )
  42.             Msg( "Precached Team Model: " .. vv .. "\n" )
  43.         end
  44.     end
  45.        
  46. end
  47.  
  48. function SelectRandomModel( teamid )
  49.     local index = math.random( 1, table.Count( teamModels[ teamid ] ) );
  50.     return teamModels[ teamid ][ index ]
  51. end
  52.  
  53. function GM:IsPlayerTeam( teamid )
  54.     if( gmdm_teamplay:GetBool() == true ) then
  55.         return ( teamid == TEAM_RED or teamid == TEAM_BLUE )
  56.     else
  57.         return ( teamid == TEAM_FREEFORALL )
  58.     end
  59. end
  60.  
  61. function GM:OnActivePlayerSpawn( pl )
  62.  
  63. end
  64.  
  65. function TeamplayInterval( bTeamDeathmatch )
  66.    
  67.     SetGlobalBool( "Interval", false );
  68.    
  69.     if( bTeamDeathmatch == false ) then
  70.         SetGlobalBool( "Teamplay", false );
  71.         local tPlayers = player.GetAll()
  72.        
  73.         for k, v in pairs( tPlayers ) do
  74.             if( v:Team() != TEAM_UNASSIGNED and v:Team() != TEAM_SPECTATOR ) then
  75.                 v:SetTeam( TEAM_FREEFORALL );
  76.                 v:SetFrags( 0 )
  77.                 v:SetDeaths( 0 )
  78.                 v:Spawn();
  79.             end
  80.         end
  81.     else
  82.         SetGlobalBool( "Teamplay", true );
  83.        
  84.         team.SetScore( TEAM_RED, 0 );
  85.         team.SetScore( TEAM_BLUE, 0 );
  86.        
  87.         local tPlayers = player.GetAll()
  88.            
  89.         for k, v in pairs( tPlayers ) do
  90.             if( gmdm_forceautoassign:GetBool() == true ) then
  91.                 if( v:Team() != TEAM_UNASSIGNED and v:Team() != TEAM_SPECTATOR ) then
  92.                     local iTeamRedNum = team.NumPlayers( TEAM_RED );
  93.                     local iTeamBlueNum = team.NumPlayers( TEAM_BLUE );
  94.                    
  95.                     if( iTeamRedNum == iTeamBlueNum ) then
  96.                         v:SetTeam( math.random( 1004, 1005 ) );
  97.                     elseif( iTeamBlueNum > iTeamRedNum ) then
  98.                         v:SetTeam( TEAM_RED );
  99.                     else
  100.                         v:SetTeam( TEAM_BLUE );
  101.                     end
  102.                        
  103.                     v:SetFrags( 0 );
  104.                     v:SetDeaths( 0 );
  105.                     v:Spawn();
  106.                 end
  107.             else
  108.                 v:KillSilent();
  109.                 v:SetTeam( TEAM_UNASSIGNED );
  110.                 v:Spectate( OBS_MODE_FIXED );
  111.                 v:ConCommand( "gmdm_showteammenu" );
  112.             end
  113.         end
  114.     end
  115. end
  116.  
  117. function CCJoinTeam( pl, command, args )
  118.    
  119.     if( CLIENT ) then
  120.         return
  121.     end
  122.     if( GetGlobalBool( "EndOfGame", false ) == true ) then return end
  123.    
  124.     local bTeamplay = GAMEMODE:IsTeamPlay( );
  125.     local iTeamNum = tonumber( args[1] );
  126.    
  127.     if( (pl:Team() != TEAM_UNASSIGNED and pl:Team() != TEAM_SPECTATOR) and pl:Alive() == true ) then
  128.         pl:Kill()
  129.     end
  130.    
  131.     if( bTeamplay == true ) then
  132.         if( iTeamNum == nil ) then return end
  133.         if( iTeamNum == pl:Team() ) then return end
  134.        
  135.         if( iTeamNum == TEAM_BLUE or iTeamNum == TEAM_RED ) then
  136.             pl:KillSilent();
  137.             pl:SetTeam( iTeamNum );
  138.             pl:PrintMessage( HUD_PRINTTALK, pl:Name() .. " is joining the " .. team.GetName( pl:Team() ) );
  139.         elseif( iTeamNum == TEAM_SPECTATOR ) then
  140.             pl:NewPrintMessage( "Not implemented yet" );
  141.         else
  142.             pl:KillSilent( );
  143.            
  144.             local iTeamRedNum = team.NumPlayers( TEAM_RED );
  145.             local iTeamBlueNum = team.NumPlayers( TEAM_BLUE );
  146.            
  147.             if( iTeamRedNum == iTeamBlueNum ) then
  148.                 if( team.GetScore( TEAM_RED ) > team.GetScore( TEAM_BLUE ) ) then
  149.                     pl:SetTeam( TEAM_BLUE );
  150.                 elseif( team.GetScore( TEAM_RED ) < team.GetScore( TEAM_BLUE ) ) then
  151.                     pl:SetTeam( TEAM_RED );
  152.                 else
  153.                     pl:SetTeam( math.random( 1004, 1005 ) );
  154.                 end
  155.             elseif( iTeamBlueNum > iTeamRedNum ) then
  156.                 pl:SetTeam( TEAM_RED );
  157.             else
  158.                 pl:SetTeam( TEAM_BLUE );
  159.             end
  160.  
  161.             pl:PrintMessage( HUD_PRINTTALK, pl:Name() .. " is joining the " .. team.GetName( pl:Team() ) );
  162.            
  163.             if( gmdm_soulcollector:GetBool() ) then
  164.                 team.AddScore( pl:Team(), pl:GetNetworkedInt( "Souls", 0 ) );
  165.             end
  166.         end
  167.     else
  168.         if( pl:Team() != TEAM_FREEFORALL ) then
  169.             pl:KillSilent();
  170.             pl:SetTeam( TEAM_FREEFORALL );
  171.             pl:PrintMessage( HUD_PRINTTALK, pl:Name() .. " has joined in the game" );
  172.         elseif( iTeamNum != nil and iTeamNum == TEAM_SPECTATOR ) then
  173.             pl:KillSilent();
  174.         end
  175.     end
  176. end
  177.  
  178. if( SERVER ) then
  179. concommand.Add( "gmdm_jointeam", CCJoinTeam );
  180. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement