| Home Page | Recent Changes | Preferences

Evolution/EvoETV

00001  //-----------------------------------------------------------
00002  //
00003  //-----------------------------------------------------------
00004  class EvoETV extends Mutator;
00005  
00006  var TeamInfo Teams[4];
00007  var int MessageCount;
00008  var Pawn MovingPawn;
00009  var bool debug;
00010  var string MyIP;
00011  var string MyLocalIP;
00012  
00013  function PostBeginPlay()
00014  {
00015      local int i;
00016      super.PostBeginPlay();
00017      Level.Game.RegisterMessageMutator(Self);
00018      
00019      for (i=0;i<TeamGamePlus(Level.Game).MaxTeams;i++)
00020          Teams[i]=TeamGamePlus(Level.Game).Teams[i];
00021          
00022      if ((TeamGamePlus(Level.Game)!=None)&&(TeamGamePlus(Level.Game).TimeLimit!=0))
00023          SetTimer(float((TeamGamePlus(Level.Game).TimeLimit*60)/3),true);
00024      else SetTimer(600.0,true);
00025      
00026      Timer();
00027  }
00028  
00029  function Timer()
00030  {
00031      BroadcastMessage("SYSTEM: type 'mutate et' in your console to even the teams.");
00032  }
00033  
00034  function bool MutatorBroadcastLocalizedMessage( Actor Sender, Pawn Receiver, out class<LocalMessage> Message, out optional int Switch, out optional PlayerReplicationInfo RelatedPRI_1, out optional PlayerReplicationInfo RelatedPRI_2, out optional Object OptionalObject )
00035  {
00036      local int OldTeam;
00037      if ((Message==class'DeathMatchMessage')&&(switch==3))
00038      {
00039          if (RelatedPRI_1!=None)
00040          {
00041              if ((MovingPawn!=None)&&(RelatedPRI_1.Owner==MovingPawn))
00042              {
00043                  if (++MessageCount<NumPlayers())
00044                  {
00045                      if (debug)
00046                      {
00047                          log(class@"Intercepting message to"@Receiver.PlayerReplicationInfo.PlayerName@"that"@RelatedPRI_1.PlayerName@"is changing teams.");
00048                          log(class@"Count:"@MessageCount@"NumPlayers:"@NumPlayers());
00049                      }
00050                      return false;
00051                  }
00052                  else
00053                  {
00054                      MovingPawn=None;
00055                      RelatedPRI_1.TweenRate=0;
00056                      MessageCount=0;
00057                      if (debug)
00058                      {
00059                          if (RelatedPRI_1.Team==0)
00060                              OldTeam=1;
00061                          log(class@"Teams were successfully balanced."@RelatedPRI_1.PlayerName@"was moved to"@TeamGamePlus(Level.Game).TeamColor[OldTeam]);
00062                      }
00063                  }
00064              }
00065              else
00066              {
00067                  RelatedPRI_1.TweenRate = Level.TimeSeconds;
00068                  if (debug)
00069                      log(class@"TEAMCHANGE("$Level.TimeSeconds$"):"@RelatedPRI_1.PlayerName@RelatedPRI_1.Team@RelatedPRI_1.TweenRate);
00070              }
00071          }
00072      }
00073  
00074      if ( NextMessageMutator != None )
00075          return NextMessageMutator.MutatorBroadcastLocalizedMessage( Sender, Receiver, Message, Switch, RelatedPRI_1, RelatedPRI_2, OptionalObject );
00076      else
00077          return true;
00078  }
00079  
00080  function Mutate(string MutateString, PlayerPawn Sender)
00081  {
00082      local int pos;
00083      local string address;
00084      local Pawn P;
00085      if (MutateString~="et")
00086      {
00087          if (debug)
00088              log("*************************ET CALLED****************************");
00089          if ((Max(Teams[0].Size,Teams[1].Size) - Min(Teams[0].Size,Teams[1].Size))>1)
00090          {
00091              EvenTeams(Sender);
00092              if (debug)
00093                  log(class@"Call to EvenTeams from"@Sender.PlayerReplicationInfo.PlayerName@"complete - team were NOT even");
00094          }
00095          else
00096          {
00097              Sender.ClientMessage("Teams are even,"@Sender.PlayerReplicationInfo.PlayerName);
00098              if (debug)
00099              {
00100                  log(class@"Call to EvenTeams from"@Sender.PlayerReplicationInfo.PlayerName@"complete - teams were even");
00101                  log(class@"Red Size:"$Teams[0].Size@"Blue Size:"$Teams[1].Size);
00102                  for (P=Level.PawnList;P!=None;P=P.NextPawn)
00103                      if (P.PlayerReplicationInfo!=None)
00104                          log(Class@p.playerreplicationinfo.playername@"on team"@p.playerreplicationinfo.team);
00105              }
00106                  
00107          }
00108          return;
00109      }
00110      else if (MutateString~="etdebug")
00111      {
00112          address = Sender.GetPlayerNetworkAddress();
00113          if (((InStr(Address,MyIP)!=-1)||(InStr(Address,MyLocalIP)!=-1))||Sender.bAdmin)
00114          {
00115              log(class@"etdebug was called!!!"@Address);
00116              debug=true;
00117              Sender.ClientMessage("Debug has been enabled!!!");
00118              return;
00119          }
00120      }
00121      else if (MutateString~="etalert")
00122      {
00123          address = Sender.GetPlayerNetworkAddress();
00124          if (((InStr(Address,MyIP)!=-1)||(InStr(Address,MyLocalIP)!=-1))||Sender.bAdmin)
00125              log(class@"ETALERT:"@Level.TimeSeconds@"Red:"$TeamGamePlus(Level.Game).TeamColor[0]@"Blue:"$TeamGamePlus(Level.Game).TeamColor[1]);
00126          return;
00127      }
00128  
00129      else if (NextMutator!=None)
00130          NextMutator.Mutate(MutateString, Sender);
00131  }
00132  
00133  function EvenTeams(PlayerPawn Sender)
00134  {
00135      local Pawn P;
00136      local float NewestTime;
00137      local Pawn NewestPawn;
00138      local int Smallest,Biggest,i;
00139  
00140      for (i=1;i<TeamGamePlus(Level.Game).MaxTeams;i++)
00141          if (Teams[i].Size>Teams[Biggest].Size)
00142              Biggest=i;
00143              
00144      if (debug)
00145          log(class@"Biggest Team:"@TeamGamePlus(Level.Game).TeamColor[Biggest]);
00146          
00147      for (P=Level.PawnList;P!=None;P=P.NextPawn)
00148      {
00149          if ((P.PlayerReplicationInfo!=None)&&(P.PlayerReplicationInfo.Team==Biggest) && (P.PlayerReplicationInfo.HasFlag==None)&&(Spectator(P)==None))
00150          {
00151              if (debug)
00152                  log(class@"Checking"@P@P.PlayerReplicationInfo.PlayerName@TeamGamePlus(Level.Game).TeamColor[P.PlayerReplicationInfo.Team]@P.PlayerReplicationInfo.TweenRate);
00153          
00154          if (P.PlayerReplicationInfo.TweenRate > NewestTime)
00155              {
00156                  if (debug)
00157                      log(class@"Found newer time than"@NewestTime@P@P.PlayerReplicationInfo.PlayerName);
00158                  NewestTime = P.PlayerReplicationInfo.TweenRate;
00159                  NewestPawn = P;
00160              }
00161          }
00162      }
00163      if (newestPawn!=none)
00164      {
00165          
00166          if (debug)
00167              log(class@"Attempting to move"@NewestPawn.PlayerReplicationInfo.PlayerName@PlayerPawn(NewestPawn).GetPlayerNetworkaddress());
00168          if (newestPawn.PlayerReplicationInfo.HasFlag!=None)
00169          {
00170              Sender.ClientMessage("Not allowed to switch"@NewestPawn.PlayerReplicationInfo.PlayerName@"while the player is holding a flag.");
00171              if (debug)
00172                  log(class@"Failed to switch"@NewestPawn.PlayerReplicationInfo.PlayerName$", FC");
00173              return;
00174          }
00175          
00176          MovingPawn=NewestPawn;
00177          NewestPawn.Died( None, '', NewestPawn.Location );
00178          Smallest = 0;
00179          
00180          for( i=1; i<TeamGamePlus(Level.Game).MaxTeams; i++ )
00181              if ( Teams[Smallest].Size > Teams[i].Size )
00182                  Smallest = i;
00183          
00184          if (TeamGamePlus(Level.Game).ChangeTeam(NewestPawn, Smallest))
00185              BroadcastMessage(NewestPawn.PlayerReplicationInfo.PlayerName@"was moved to the"@TeamGamePlus(Level.Game).TeamColor[Smallest]@"team.");
00186          else BroadcastMessage(NewestPawn.PlayerReplicationInfo.PlayerName@"could not be moved!!!");
00187      }
00188      else
00189      {
00190          log(class@"NEWEST PAWN WAS NONE!");
00191          Sender.ClientMessage("There was an error balancing the teams.  Please try again in a few seconds.");
00192      }
00193  }
00194  
00195  function int NumPlayers()
00196  {
00197      if (debug)
00198          log(class@"NumPlayer()::NumPlayers:"$DeathMatchPlus(Level.Game).NumPlayers@"NumBots:"$DeathMatchPlus(Level.Game).NumBots);
00199      if (LastManStanding(Level.Game)!=None)
00200          return DeathMatchPlus(Level.Game).NumPlayers+DeathMatchPlus(Level.Game).NumBots-LastManStanding(Level.Game).NumGhosts;
00201      else return DeathMatchPlus(Level.Game).NumPlayers+DeathMatchPlus(Level.Game).NumBots;
00202  }

The Unreal Engine Documentation Site

Wiki Community

Topic Categories

Image Uploads

Random Page

Recent Changes

Offline Wiki

Unreal Engine

Console Commands

Terminology

Mapping Topics

Mapping Lessons

UnrealEd Interface

Questions&Answers

Scripting Topics

Scripting Lessons

Making Mods

Class Tree

Questions&Answers

Modeling Topics

Questions&Answers

Log In