Always snap to grid
UE1:NBSPMsgMutator (Class)
From Unreal Wiki, The Unreal Engine Documentation Site
Revision as of 12:52, 1 April 2009 by Azura (Talk | contribs) (Created page with '== Purpose == == Variables == == Discussion == == Possible improvements == == Complete source code == <uscript>//============================================================...')
Purpose
Variables
Discussion
Possible improvements
Complete source code
//============================================================================= // NBSPMsgMutator ==> NoBullShitPlus v1.09 //============================================================================= class NBSPMsgMutator expands Mutator; var NBSP nbsp; var string cmd[10]; function PostBeginPlay() { Level.Game.RegisterMessageMutator(self); Disable('Tick'); } function bool MutatorBroadcastMessage( Actor Sender,Pawn Receiver, out coerce string Msg, optional bool bBeep, out optional name Type ) { local Actor A; local bool l; A = Sender; // Hack ... for AdminLogout() going in PHYS_Walking while state is 'PlayerWaiting' If (A.IsA('GameInfo') && Receiver != None && Receiver.PlayerReplicationInfo != None && (Receiver.PlayerReplicationInfo.PlayerName@"gave up administrator abilities.") == Msg && (Receiver.GetStateName() == 'PlayerWaiting' || Receiver.PlayerReplicationInfo.bIsSpectator)) { Receiver.GotoState(''); Receiver.GotoState('PlayerWaiting'); } while (!A.isa('Pawn') && A.Owner != None) A=A.Owner; if (A.isa('spectator')) l=((left(msg,len(spectator(A).playerreplicationinfo.playername)+1))==(spectator(A).playerreplicationinfo.playername$":") || A.IsA('MessagingSpectator')); if (l) l=(type=='Event'); if (A.isa('Pawn') && !l) return false; if ( NextMessageMutator != None ) { return NextMessageMutator.MutatorBroadcastMessage( Sender,Receiver, Msg, bBeep ); } else return Super.MutatorBroadcastMessage( Sender,Receiver, Msg, bBeep ); } 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 Actor A; A = Sender; while (!A.isa('Pawn') && A.Owner != None) A=A.Owner; if (A.isa('Pawn')) return false; if ( NextMessageMutator != None ) { return NextMessageMutator.MutatorBroadcastLocalizedMessage( Sender, Receiver, Message, Switch, RelatedPRI_1, RelatedPRI_2, OptionalObject ); } else return Super.MutatorBroadcastLocalizedMessage( Sender, Receiver, Message, Switch, RelatedPRI_1, RelatedPRI_2, OptionalObject ); } // MutatorBroadcastLocalizedMessage function bool MutatorTeamMessage (Actor Sender, Pawn Receiver, PlayerReplicationInfo PRI, coerce string S, name Type, optional bool bBeep) { if ( (Sender != None) && (Receiver != None) ) { if ((Sender.IsA('PlayerPawn')) && (Receiver.IsA('PlayerPawn')) && (nbsp.xx())) { if (!Sender.IsA('Spectator')) { S=ets(S,PlayerPawn(Sender)); if (NextMessageMutator != None) { if (NextMessageMutator.MutatorTeamMessage(Sender,Receiver,PRI,S,Type,bBeep)) { Receiver.TeamMessage(PRI,S,Type,bBeep); } } else { Receiver.TeamMessage(PRI,S,Type,bBeep); } } else { if ( NextMessageMutator != None ) { if ( NextMessageMutator.MutatorTeamMessage(Sender,Receiver,PRI,S,Type,bBeep) ) { Receiver.TeamMessage(PRI,S,Type,bBeep); } } else { Receiver.TeamMessage(PRI,S,Type,bBeep); } } return False; } else { if ( NextMessageMutator != None ) { return NextMessageMutator.MutatorTeamMessage(Sender,Receiver,PRI,S,Type,bBeep); } else { return True; } } } } function float DistanceFrom (Actor P1, Actor P2) { local float dx; local float dy; local float dz; local float ad; dx=P1.Location.X - P2.Location.X; dy=P1.Location.Y - P2.Location.Y; dz=P1.Location.Z - P2.Location.Z; ad=Sqrt(Square(dx) + Square(dy) + Square(dz)); return ad; } function string NearestObj (PlayerPawn s) { local FortStandard F; local FortStandard nf; local float dt; local float tf; dt=0.00; foreach AllActors(Class'FortStandard',F) { tf=DistanceFrom(s,F); if ( (dt == 0) || (tf < dt) ) { nf=F; dt=tf; } } if ( nf.FortName == "Assault Target" ) { return string(nf); } else { if ( (nf.FortName == "") || (nf.FortName == " ") ) { return string(nf); } else { return nf.FortName; } } } function string NearestTeamMate (PlayerPawn s) { local PlayerPawn PP, xPP; local float dtx, tpd; dtx=0.00; foreach AllActors(Class'PlayerPawn',PP) { tpd=DistanceFrom(s,PP); if ( (PP != s) && (PP.PlayerReplicationInfo.Team == s.PlayerReplicationInfo.Team) && ((dtx == 0) || (tpd < dtx)) ) { xPP=PP; dtx=tpd; } } if ( xPP != None ) { return xPP.PlayerReplicationInfo.PlayerName; } else { return "NO TEAM MATES"; } } function int GetArmourAmount (Pawn P) { local int a; local Inventory v; v=P.Inventory; while (v != None) { if ( v.bIsAnArmor ) { a += v.Charge; } v=v.Inventory; } return a; } function string ets (string t, PlayerPawn s) { local string ls, m, o, c; local int p, z, X, k; local CTFFlag F, Red_F, Blue_F; local FlagBase Red_FB, Blue_FB; local float dRed_b, dBlue_b, dBlue_f, dRed_f; m=t; p=InStr(m,"%"); while (p != -1) { // if there is a % if ( p > 0 ) { //this sets o to whatever is before the % o=o $ Left(m,p); m=Mid(m,p); p=0; } X=Len(m); //set c to the % command c=Mid(m,p,2); // if the len(m) > 2, there must be a command if ( X - 2 > 0 ) m=Right(m,X - 2); else m=""; //find the c Switch (c) { Case cmd[0]: if ( Level.Game.IsA('TeamGamePlus') ) { if ( s.PlayerReplicationInfo.PlayerLocation != None ) ls=s.PlayerReplicationInfo.PlayerLocation.LocationName; else { if (s.PlayerReplicationInfo.PlayerZone != None) ls=s.PlayerReplicationInfo.PlayerZone.ZoneName; } if (len(ls) == 0) { if (Level.Game.IsA('Assault')) ls="Near" @ NearestObj(s); else ls="Unknown"; } o=o $ ls; } else o=o $ c; break; Case cmd[1]: if (s.Health > 0) o=o $ string(s.Health); else o=o $ "0"; break; case cmd[2]: o=o $ string(GetArmourAmount(s)); break; case cmd[3]: if (s.Health > 0) { if (s.Weapon != None) o=o $ s.Weapon.ItemName; else o=o $ "Empty hands"; } else o=o $ "Empty hands"; break; case cmd[4]: if (s.Health > 0) { if (s.Weapon.ItemName != "Translocator") o=o $ string(s.Weapon.AmmoType.AmmoAmount); else o=o $ "0"; } else o=o $ "0"; break; case cmd[5]: o=o $ s.PlayerReplicationInfo.PlayerName; break; case cmd[6]: if ( Level.Game.IsA('TeamGamePlus') && Level.Game.IsA('Assault')) o=o $ NearestObj(s); else o=o $ c; break; case cmd[7]: if ( Level.Game.IsA('TeamGamePlus') ) o=o $ NearestTeamMate(s); else o=o $ c; break; case cmd[8]: if ( s.GameReplicationInfo.IsA('CTFReplicationInfo') ) { for (k=0;k<2;k++ ) { F = CTFReplicationInfo(Level.Game.GameReplicationInfo).FlagList[k]; if ( F.HomeBase.Team == 0 ) Red_FB = F.HomeBase; else if ( F.HomeBase.Team == 1 ) Blue_FB = F.HomeBase; if ( F.Team == 0 ) Red_F = F; else if ( F.Team == 1 ) Blue_F = F; } dRed_b = VSize(Location - Red_FB.Location); dBlue_b = VSize(Location - Blue_FB.Location); dRed_f = VSize(Location - Red_F.position().Location); dBlue_f = VSize(Location - Blue_F.position().Location); if ( s.PlayerReplicationInfo.Team == 0 ) { if ( (dRed_f < 2048) && (Red_F.Holder != None) && ((Blue_F.Holder == None) || (dRed_f < dBlue_f)) ) z=0; else if ( (dBlue_f < 2048) && (Blue_F.Holder != None) && ((Red_F.Holder == None) || (dRed_f > dBlue_f)) ) z=1; else if ( dBlue_b < 2049 ) z=2; else if ( dRed_b < 2048 ) z=3; else z=4; } else if ( s.PlayerReplicationInfo.Team == 1 ) { if ( (dBlue_f < 2048) && (Blue_F.Holder != None) && ((Red_F.Holder == None) || (dRed_f >= dBlue_f)) ) z=0; else if ( (dRed_f < 2048) && (Red_F.Holder != None) && ((Blue_F.Holder == None) || (dRed_f < dBlue_f)) ) z=1; else if ( dRed_b < 2048 ) z=2; else if ( dBlue_b < 2048 ) z=3; else z=4; } if ( (Blue_F.Holder == s) || (Red_F.Holder == s) ) z=5; switch (z) { case 0: o=o $ "Attacking Enemy Flag Carrier"; break; case 1: o=o $ "Supporting Our Flag Carrier"; break; case 2: o=o $ "Attacking"; break; case 3: o=o $ "Defending"; break; case 4: o=o $ "Floating"; break; case 5: o=o $ "Carrying Flag"; break; } } else if ( Level.Game.IsA('TeamGamePlus') && Level.Game.IsA('Assault')) { if (s.PlayerReplicationInfo.Team == (Assault(Level.Game).CurrentDefender)) o=o $ "Defending"; else o=o $ "Attacking"; } else o=o $ c; break; case cmd[9]: o=o $ "%"; break; default: o=o $ c; break; } p=InStr(m,"%"); } if ( Len(m) > 0 ) o=o $ m; return o; } defaultproperties { cmd(0)="%L" cmd(1)="%H" cmd(2)="%A" cmd(3)="%W" cmd(4)="%M" cmd(5)="%N" cmd(6)="%O" cmd(7)="%T" cmd(8)="%P" cmd(9)="%%" }