There is no spoon
Legacy:Evolution/EvoETV
From Unreal Wiki, The Unreal Engine Documentation Site
-
//-----------------------------------------------------------
-
//
-
//-----------------------------------------------------------
-
class EvoETV extends Mutator;
-
-
var TeamInfo Teams[4];
-
var int MessageCount;
-
var Pawn MovingPawn;
-
var bool debug;
-
var string MyIP;
-
var string MyLocalIP;
-
-
function PostBeginPlay()
-
{
-
local int i;
-
super.PostBeginPlay();
-
Level.Game.RegisterMessageMutator(Self);
-
-
for (i=0;i<TeamGamePlus(Level.Game).MaxTeams;i++)
-
Teams[i]=TeamGamePlus(Level.Game).Teams[i];
-
-
if ((TeamGamePlus(Level.Game)!=None)&&(TeamGamePlus(Level.Game).TimeLimit!=0))
-
SetTimer(float((TeamGamePlus(Level.Game).TimeLimit*60)/3),true);
-
else SetTimer(600.0,true);
-
-
Timer();
-
}
-
-
function Timer()
-
{
-
BroadcastMessage("SYSTEM: type 'mutate et' in your console to even the teams.");
-
}
-
-
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 )
-
{
-
local int OldTeam;
-
if ((Message==class'DeathMatchMessage')&&(switch==3))
-
{
-
if (RelatedPRI_1!=None)
-
{
-
if ((MovingPawn!=None)&&(RelatedPRI_1.Owner==MovingPawn))
-
{
-
if (++MessageCount<NumPlayers())
-
{
-
if (debug)
-
{
-
log(class@"Intercepting message to"@Receiver.PlayerReplicationInfo.PlayerName@"that"@RelatedPRI_1.PlayerName@"is changing teams.");
-
log(class@"Count:"@MessageCount@"NumPlayers:"@NumPlayers());
-
}
-
return false;
-
}
-
else
-
{
-
MovingPawn=None;
-
RelatedPRI_1.TweenRate=0;
-
MessageCount=0;
-
if (debug)
-
{
-
if (RelatedPRI_1.Team==0)
-
OldTeam=1;
-
log(class@"Teams were successfully balanced."@RelatedPRI_1.PlayerName@"was moved to"@TeamGamePlus(Level.Game).TeamColor[OldTeam]);
-
}
-
}
-
}
-
else
-
{
-
RelatedPRI_1.TweenRate = Level.TimeSeconds;
-
if (debug)
-
log(class@"TEAMCHANGE("$Level.TimeSeconds$"):"@RelatedPRI_1.PlayerName@RelatedPRI_1.Team@RelatedPRI_1.TweenRate);
-
}
-
}
-
}
-
-
if ( NextMessageMutator != None )
-
return NextMessageMutator.MutatorBroadcastLocalizedMessage( Sender, Receiver, Message, Switch, RelatedPRI_1, RelatedPRI_2, OptionalObject );
-
else
-
return true;
-
}
-
-
function Mutate(string MutateString, PlayerPawn Sender)
-
{
-
local int pos;
-
local string address;
-
local Pawn P;
-
if (MutateString~="et")
-
{
-
if (debug)
-
log("*************************ET CALLED****************************");
-
if ((Max(Teams[0].Size,Teams[1].Size) - Min(Teams[0].Size,Teams[1].Size))>1)
-
{
-
EvenTeams(Sender);
-
if (debug)
-
log(class@"Call to EvenTeams from"@Sender.PlayerReplicationInfo.PlayerName@"complete - team were NOT even");
-
}
-
else
-
{
-
Sender.ClientMessage("Teams are even,"@Sender.PlayerReplicationInfo.PlayerName);
-
if (debug)
-
{
-
log(class@"Call to EvenTeams from"@Sender.PlayerReplicationInfo.PlayerName@"complete - teams were even");
-
log(class@"Red Size:"$Teams[0].Size@"Blue Size:"$Teams[1].Size);
-
for (P=Level.PawnList;P!=None;P=P.NextPawn)
-
if (P.PlayerReplicationInfo!=None)
-
log(Class@p.playerreplicationinfo.playername@"on team"@p.playerreplicationinfo.team);
-
}
-
-
}
-
return;
-
}
-
else if (MutateString~="etdebug")
-
{
-
address = Sender.GetPlayerNetworkAddress();
-
if (((InStr(Address,MyIP)!=-1)||(InStr(Address,MyLocalIP)!=-1))||Sender.bAdmin)
-
{
-
log(class@"etdebug was called!!!"@Address);
-
debug=true;
-
Sender.ClientMessage("Debug has been enabled!!!");
-
return;
-
}
-
}
-
else if (MutateString~="etalert")
-
{
-
address = Sender.GetPlayerNetworkAddress();
-
if (((InStr(Address,MyIP)!=-1)||(InStr(Address,MyLocalIP)!=-1))||Sender.bAdmin)
-
log(class@"ETALERT:"@Level.TimeSeconds@"Red:"$TeamGamePlus(Level.Game).TeamColor[0]@"Blue:"$TeamGamePlus(Level.Game).TeamColor[1]);
-
return;
-
}
-
-
else if (NextMutator!=None)
-
NextMutator.Mutate(MutateString, Sender);
-
}
-
-
function EvenTeams(PlayerPawn Sender)
-
{
-
local Pawn P;
-
local float NewestTime;
-
local Pawn NewestPawn;
-
local int Smallest,Biggest,i;
-
-
for (i=1;i<TeamGamePlus(Level.Game).MaxTeams;i++)
-
if (Teams[i].Size>Teams[Biggest].Size)
-
Biggest=i;
-
-
if (debug)
-
log(class@"Biggest Team:"@TeamGamePlus(Level.Game).TeamColor[Biggest]);
-
-
for (P=Level.PawnList;P!=None;P=P.NextPawn)
-
{
-
if ((P.PlayerReplicationInfo!=None)&&(P.PlayerReplicationInfo.Team==Biggest) && (P.PlayerReplicationInfo.HasFlag==None)&&(Spectator(P)==None))
-
{
-
if (debug)
-
log(class@"Checking"@P@P.PlayerReplicationInfo.PlayerName@TeamGamePlus(Level.Game).TeamColor[P.PlayerReplicationInfo.Team]@P.PlayerReplicationInfo.TweenRate);
-
-
if (P.PlayerReplicationInfo.TweenRate > NewestTime)
-
{
-
if (debug)
-
log(class@"Found newer time than"@NewestTime@P@P.PlayerReplicationInfo.PlayerName);
-
NewestTime = P.PlayerReplicationInfo.TweenRate;
-
NewestPawn = P;
-
}
-
}
-
}
-
if (newestPawn!=none)
-
{
-
-
if (debug)
-
log(class@"Attempting to move"@NewestPawn.PlayerReplicationInfo.PlayerName@PlayerPawn(NewestPawn).GetPlayerNetworkaddress());
-
if (newestPawn.PlayerReplicationInfo.HasFlag!=None)
-
{
-
Sender.ClientMessage("Not allowed to switch"@NewestPawn.PlayerReplicationInfo.PlayerName@"while the player is holding a flag.");
-
if (debug)
-
log(class@"Failed to switch"@NewestPawn.PlayerReplicationInfo.PlayerName$", FC");
-
return;
-
}
-
-
MovingPawn=NewestPawn;
-
NewestPawn.Died( None, '', NewestPawn.Location );
-
Smallest = 0;
-
-
for( i=1; i<TeamGamePlus(Level.Game).MaxTeams; i++ )
-
if ( Teams[Smallest].Size > Teams[i].Size )
-
Smallest = i;
-
-
if (TeamGamePlus(Level.Game).ChangeTeam(NewestPawn, Smallest))
-
BroadcastMessage(NewestPawn.PlayerReplicationInfo.PlayerName@"was moved to the"@TeamGamePlus(Level.Game).TeamColor[Smallest]@"team.");
-
else BroadcastMessage(NewestPawn.PlayerReplicationInfo.PlayerName@"could not be moved!!!");
-
}
-
else
-
{
-
log(class@"NEWEST PAWN WAS NONE!");
-
Sender.ClientMessage("There was an error balancing the teams. Please try again in a few seconds.");
-
}
-
}
-
-
function int NumPlayers()
-
{
-
if (debug)
-
log(class@"NumPlayer()::NumPlayers:"$DeathMatchPlus(Level.Game).NumPlayers@"NumBots:"$DeathMatchPlus(Level.Game).NumBots);
-
if (LastManStanding(Level.Game)!=None)
-
return DeathMatchPlus(Level.Game).NumPlayers+DeathMatchPlus(Level.Game).NumBots-LastManStanding(Level.Game).NumGhosts;
-
else return DeathMatchPlus(Level.Game).NumPlayers+DeathMatchPlus(Level.Game).NumBots;
-
}