Advertisement
Guest User

Untitled

a guest
Dec 14th, 2018
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.25 KB | None | 0 0
  1. function ShuffleTeamsNextMatch()
  2. {
  3. local Array<Rx_Controller> Team1, Team2, All;
  4. local int Team1Score, Team2Score;
  5. local int GDICount, NodCount;
  6. local Rx_Controller PC, Highest;
  7.  
  8. // Gather all Human Players
  9. foreach WorldInfo.AllControllers(class'Rx_Controller', PC)
  10. {
  11. if ( (PC.PlayerReplicationInfo != None) && (PC.PlayerReplicationInfo.Team != None) )
  12. All.AddItem(PC);
  13. }
  14.  
  15. // Sort them all into 2 teams.
  16. while (All.Length > 0)
  17. {
  18. Highest = None;
  19. foreach All(PC)
  20. {
  21. if (Highest == None)
  22. Highest = PC;
  23. else if (Rx_PRI(PC.PlayerReplicationInfo).OldRenScore > Rx_PRI(Highest.PlayerReplicationInfo).OldRenScore)
  24. Highest = PC;
  25. }
  26.  
  27. All.RemoveItem(Highest);
  28.  
  29. if (Team1Score <= Team2Score)
  30. {
  31. Team1.AddItem(Highest);
  32. Team1Score += Rx_PRI(Highest.PlayerReplicationInfo).OldRenScore;
  33. }
  34. else
  35. {
  36. Team2.AddItem(Highest);
  37. Team2Score += Rx_PRI(Highest.PlayerReplicationInfo).OldRenScore;
  38. }
  39.  
  40. // If the small team + the rest is less than the larger team, then place all remaining players in the small team.
  41. if (Team1.Length >= Team2.Length + All.Length)
  42. {
  43. // Dump the rest in Team2.
  44. foreach All(PC)
  45. Team2.AddItem(PC);
  46. break;
  47. }
  48. else if (Team2.Length >= Team1.Length + All.Length)
  49. {
  50. // Dump the rest in Team1.
  51. foreach All(PC)
  52. Team1.AddItem(PC);
  53. break;
  54. }
  55. }
  56.  
  57. // Figure out which team will be which faction. Just do the one that moves the least.
  58. foreach Team1(PC)
  59. {
  60. if (PC.PlayerReplicationInfo.Team.TeamIndex == 0)
  61. ++GDICount;
  62. else
  63. ++NodCount;
  64. }
  65. if (GDICount >= NodCount)
  66. {
  67. // Team 1 go GDI, Team 2 go Nod
  68. foreach Team1(PC)
  69. if (PC.PlayerReplicationInfo.Team.TeamIndex != 0)
  70. `RxEngineObject.AddGDIPlayer(PC.PlayerReplicationInfo);
  71. foreach Team2(PC)
  72. if (PC.PlayerReplicationInfo.Team.TeamIndex != 1)
  73. `RxEngineObject.AddNodPlayer(PC.PlayerReplicationInfo);
  74. }
  75. else
  76. {
  77. // Team 1 go Nod, Team 2 go GDI
  78. foreach Team1(PC)
  79. if (PC.PlayerReplicationInfo.Team.TeamIndex != 1)
  80. `RxEngineObject.AddNodPlayer(PC.PlayerReplicationInfo);
  81. foreach Team2(PC)
  82. if (PC.PlayerReplicationInfo.Team.TeamIndex != 0)
  83. `RxEngineObject.AddGDIPlayer(PC.PlayerReplicationInfo);
  84. }
  85.  
  86. // Terribly unoptimized, but done.
  87.  
  88. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement