Announcement

Collapse
No announcement yet.

UT99: trying to make enhanced flags

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    UT99: trying to make enhanced flags

    I ask here because most people now work on ut200x...

    I get accessed none every time I work with HomeBase BUT everything else works (pick flags, score, drop, return), except for my new code of course and some of the team based code.
    Basically I wanted to add a few convenient automatic (configurable) messages when the flag is picked up and when it's dropped.

    Here is the code.

    Code:
    class EnhancedFlags extends Mutator;
    
    var bool bPreInitialized;
    var bool bPostInitialized;
    var bool bReplaced;
    
    event PreBeginPlay()
    {
    	if( bPreInitialized )
    	{
    		return;
    	}
    
    	bPreInitialized = true;
    }
    
    function PostBeginPlay()
    {
    	local int i;
    
    	if( bPostInitialized )
    	{
    		return;
    	}
    
    	bPostInitialized = true;
    
    	if( !Level.Game.IsA( 'CTFGame' ) )
    	{
    		return;
    	}
    
    	SetTimer( 1.0, true );
    }
    
    simulated function Timer()
    {
    	local int i;
    	local CTFFlag Flag;
    
    	local byte Team;      	
    	local bool bHome;
    	local bool bKnownLocation; //for bot AI
    	local bool bHeld;
    	local Pawn		Holder;
    	local FlagBase	HomeBase;
    	
    	//ForEach AllActors( class'FlagBase', Base )
    	//{
    	//	Base.Skin = FlagTeamTextures[ Base.Team ];
    	//}
    
    	if( CTFReplicationInfo( Level.Game.GameReplicationInfo ) != None )
    	{
    		for( i = 0; i < 4; i ++ )
    		{
    			if( CTFReplicationInfo( Level.Game.GameReplicationInfo ).FlagList[ i ] != None )
    			{
    				Log("Swapping flag");
    				Team=CTFReplicationInfo( Level.Game.GameReplicationInfo ).FlagList[ i ].Team;
    				bHome=CTFReplicationInfo( Level.Game.GameReplicationInfo ).FlagList[ i ].bHome;
    				bKnownLocation=CTFReplicationInfo( Level.Game.GameReplicationInfo ).FlagList[ i ].bKnownLocation;
    				bHeld=CTFReplicationInfo( Level.Game.GameReplicationInfo ).FlagList[ i ].bHeld;
    				Holder=CTFReplicationInfo( Level.Game.GameReplicationInfo ).FlagList[ i ].Holder;
    				HomeBase=CTFReplicationInfo( Level.Game.GameReplicationInfo ).FlagList[ i ].HomeBase;
    				
    				ReplaceWith(CTFReplicationInfo( Level.Game.GameReplicationInfo ).FlagList[ i ], "EnhancedFlags.xxCTFFlag");
    				
    				CTFReplicationInfo( Level.Game.GameReplicationInfo ).FlagList[ i ].Team=Team;
    				CTFReplicationInfo( Level.Game.GameReplicationInfo ).FlagList[ i ].bHome=bHome;
    				CTFReplicationInfo( Level.Game.GameReplicationInfo ).FlagList[ i ].bKnownLocation=bKnownLocation;
    				CTFReplicationInfo( Level.Game.GameReplicationInfo ).FlagList[ i ].bHeld=bHeld;
    				CTFReplicationInfo( Level.Game.GameReplicationInfo ).FlagList[ i ].Holder=Holder;
    				CTFReplicationInfo( Level.Game.GameReplicationInfo ).FlagList[ i ].HomeBase=HomeBase;
    				Log("Flag swapped");
    			}
    		}
    
    		SetTimer( 0.0, false );
    	}
    }
    
    defaultproperties
    {
    }
    Code:
    class xxCTFFlag extends CTFFlag
    	config(EnhancedFlags);
    
    var config bool bNotifyPickup;
    var config bool bNotifyDrop;
    var config bool bVoiceNotify;
    var config string sPickupMsg;
    var config string sDropMsg;
    
    
    function SendHome()
    {
    	local Pawn aPawn;
    
    	if ( Holder != None )
    	{
    		Holder.AmbientGlow = Holder.Default.AmbientGlow;
    		Holder.LightType = LT_None;
    		Holder.PlayerReplicationInfo.HasFlag = None;
    		if ( Holder.Inventory != None )
    			Holder.Inventory.SetOwnerDisplay();
    		Holder = None;
    	}
    	GotoState('Home');
    	SetPhysics(PHYS_None);
    	bCollideWorld = false;
    	SetLocation(HomeBase.Location);
    	SetRotation(HomeBase.Rotation);
    	SetBase(None);
    	SetCollision(true,false,false);
    	For (aPawn = Level.PawnList; aPawn!=None; aPawn=aPawn.nextPawn )
    		if ( aPawn.MoveTarget == self )
    			aPawn.MoveTimer = -1.0;
    }
    
    function PostBeginPlay()
    {
    	Super.PostBeginPlay();
    	//SaveConfig();
    	LoopAnim('pflag');
    }
    
    function Drop(vector newVel)
    {
    	local Pawn OldHolder;
    	local vector X,Y,Z;
    	local bool bHolderPainZone;
    
    	Log("Drop");
    	if (bNotifyPickup==true)
    	{
    		Holder.BroadcastMessage (sDropmsg, false, 'TeamSay');
    		//if (TournamentPlayer(Holder).bAutoTaunt || bVoiceNotify==true)
    		//Holder.SendTeamMessage(None, 'OTHER', 2, 10);
    	}
    	BroadcastLocalizedMessage( class'CTFMessage', 2, Holder.PlayerReplicationInfo, None, CTFGame(Level.Game).Teams[Team] );
    	if (Level.Game.WorldLog != None)
    		Level.Game.WorldLog.LogSpecialEvent("flag_dropped", Holder.PlayerReplicationInfo.PlayerID, CTFGame(Level.Game).Teams[Team].TeamIndex);
    	if (Level.Game.LocalLog != None)
    		Level.Game.LocalLog.LogSpecialEvent("flag_dropped", Holder.PlayerReplicationInfo.PlayerID, CTFGame(Level.Game).Teams[Team].TeamIndex);
    
    	RotationRate.Yaw = Rand(200000) - 100000;
    	RotationRate.Pitch = Rand(200000 - Abs(RotationRate.Yaw)) - 0.5 * (200000 - Abs(RotationRate.Yaw));
    	Velocity = (0.2 + FRand()) * (newVel + 400 * FRand() * VRand());
    	If (Region.Zone.bWaterZone)
    		Velocity *= 0.5;
    	OldHolder = Holder;
    	Holder.PlayerReplicationInfo.HasFlag = None;
    	Holder.AmbientGlow = Holder.Default.AmbientGlow;
    	LightType = LT_Steady;
    	Holder.LightType = LT_None;
    	bHolderPainZone = (Holder.Region.Zone.bPainZone && (Holder.Region.Zone.DamagePerSec > 0));
    	bHolderPainZone = bHolderPainZone || (Holder.FootRegion.Zone.bPainZone && (Holder.FootRegion.Zone.DamagePerSec > 0));
    	if ( Holder.Inventory != None )
    		Holder.Inventory.SetOwnerDisplay();
    	Holder = None;
    
    	GetAxes(OldHolder.Rotation, X,Y,Z);
    	SetRotation(rotator(-1 * X));
    	bCollideWorld = true;
    	SetCollisionSize(0.5 * Default.CollisionRadius, CollisionHeight);
     	if ( !SetLocation(OldHolder.Location - 2 * OldHolder.CollisionRadius * X + OldHolder.CollisionHeight * vect(0,0,0.5)) 
    		&& !SetLocation(OldHolder.Location) )
    	{
    		SetCollisionSize(0.8 * OldHolder.CollisionRadius, FMin(CollisionHeight, 0.8 * OldHolder.CollisionHeight));
    		if ( !SetLocation(OldHolder.Location) )
    		{
    			SendHome();
    			return;
    		}
    	}
    
    	SetPhysics(PHYS_Falling);
    	SetBase(None);
    	SetCollision(true, false, false);
    	GotoState('Dropped');
    	if ( bHolderPainZone )
    		Timer();
    }
    
    state Dropped
    {
    	function TakeDamage( int NDamage, Pawn instigatedBy, Vector hitlocation, 
    						Vector momentum, name damageType)
    	{
    		if ( Region.Zone.bPainZone && (Region.Zone.DamagePerSec > 0) )
    			timer();
    	}
    
    	singular function ZoneChange( ZoneInfo NewZone )
    	{
    		Super.ZoneChange(NewZone);
    		if ( NewZone.bPainZone && (NewZone.DamagePerSec > 0) )
    			timer();
    	}
    
    	function Timer()
    	{
    		SendHome();
    		BroadcastLocalizedMessage( class'CTFMessage', 3, None, None, CTFGame(Level.Game).Teams[Team] );
    		if (Level.Game.WorldLog != None)
    			Level.Game.WorldLog.LogSpecialEvent("flag_returned_timeout", CTFGame(Level.Game).Teams[Team].TeamIndex);
    		if (Level.Game.LocalLog != None)
    			Level.Game.LocalLog.LogSpecialEvent("flag_returned_timeout", CTFGame(Level.Game).Teams[Team].TeamIndex);
    	}
    
    	function Touch(Actor Other)
    	{
    		local CTFFlag aFlag;
    		local Pawn aPawn;
    		local NavigationPoint N;
    		local int num, i;
    		
    		aPawn = Pawn(Other);
    		if ( (aPawn != None) && aPawn.bIsPlayer && (aPawn.Health > 0)
    			&& !aPawn.IsInState('FeigningDeath') )
    		{
    			aPawn.MoveTimer = -1;
    			if ( aPawn.PlayerReplicationInfo.Team == Team )
    			{
    				// returned flag
    				CTFGame(Level.Game).ScoreFlag(aPawn, self);
    				SendHome();
    				return;
    			}
    			else
    			{
    				Holder = aPawn;
    				Holder.PlayerReplicationInfo.HasFlag = self;
    				SetHolderLighting();
    				if ( Holder.IsA('Bot') )
    				{
    					Bot(Holder).AlternatePath = None;
    					Holder.SendTeamMessage(None, 'OTHER', 2, 10);
    				}
    				else if ( Holder.IsA('TournamentPlayer'))
    				{
    					if (TournamentPlayer(Holder).bAutoTaunt || bNotifyPickup==true)
    					{
    						Holder.BroadcastMessage (sPickupmsg, false, 'TeamSay');
    						if (TournamentPlayer(Holder).bAutoTaunt || bVoiceNotify==true)
    							Holder.SendTeamMessage(None, 'OTHER', 2, 10);
    					}
    				}
    			}
    			BroadcastLocalizedMessage( class'CTFMessage', 4, Holder.PlayerReplicationInfo, None, CTFGame(Level.Game).Teams[Team] );
    			if (Level.Game.WorldLog != None)
    				Level.Game.WorldLog.LogSpecialEvent("flag_pickedup", Holder.PlayerReplicationInfo.PlayerID, CTFGame(Level.Game).Teams[Team].TeamIndex);
    			if (Level.Game.LocalLog != None)
    				Level.Game.LocalLog.LogSpecialEvent("flag_pickedup", Holder.PlayerReplicationInfo.PlayerID, CTFGame(Level.Game).Teams[Team].TeamIndex);
    			GotoState('Held');
    		}
    	}
    
    	function BeginState()
    	{
    		LightEffect = LE_NonIncidence;
    		SetTimer(25.0, false);
    		bCollideWorld = true;
    		bKnownLocation = false;
    		bHidden = false;
    	}
    
    	function EndState()
    	{
    		bHidden = true;
    	}
    
    Begin:
    	if ( Region.Zone.bPainZone && (Region.Zone.DamagePerSec > 0) )
    		timer();
    
    }
    
    auto state Home
    {
    	function Timer()
    	{
    		//if (HomeBase!=none)
    			if ( VSize(Location - HomeBase.Location) > 10 )
    			{
    				SendHome();
    				BroadcastLocalizedMessage( class'CTFMessage', 5, None, None, CTFGame(Level.Game).Teams[Team] );
    			}
    	}
    
    	function Touch(Actor Other)
    	{
    		local CTFFlag aFlag;
    		local Pawn aPawn;
    		local NavigationPoint N;
    		local int i;
    		local float totalweight, selection, PartialWeight;
    		local Bot B;
    		
    		Log("Touch");
    		aPawn = Pawn(Other);
    		if ( (aPawn != None) && aPawn.bIsPlayer && (aPawn.Health > 0) )
    		{
    			Log("Touch if 1");
    			// check if scored capture
    			if ( aPawn.PlayerReplicationInfo.Team == Team )
    			{
    				if ( aPawn.PlayerReplicationInfo.HasFlag != None )
    				{
    					//Score!
    					Log("Touch score");
    					aFlag = CTFFlag(aPawn.PlayerReplicationInfo.HasFlag);
    					CTFGame(Level.Game).ScoreFlag(aPawn, aFlag);
    					aFlag.SendHome();
    				}
    			}
    			else
    			{
    				Log("Touch if 2");
    				Holder = aPawn;
    				Holder.MoveTimer = -1;
    				Holder.PlayerReplicationInfo.HasFlag = self;
    				Holder.MakeNoise(2.0);
    				SetHolderLighting();
    				B = Bot(Holder);
    				if ( B != None )
    				{
    					B.AlternatePath = None;
    					if ( FRand() < 0.5 )
    					{
    						for ( N=Level.NavigationPointList; N!=None; N=N.nextNavigationPoint )
    							if ( N.IsA('AlternatePath') && (AlternatePath(N).bTwoWay || (AlternatePath(N).team == Holder.PlayerReplicationInfo.team)) )
    							{
    								if ( AlternatePath(N).bTwoWay && (AlternatePath(N).team != Holder.PlayerReplicationInfo.team) )
    									TotalWeight += 4000;
    								TotalWeight += AlternatePath(N).SelectionWeight;
    							}
    						selection = TotalWeight * FRand();
    						for ( N=Level.NavigationPointList; N!=None; N=N.nextNavigationPoint )
    							if ( N.IsA('AlternatePath') && (AlternatePath(N).bTwoWay ||(AlternatePath(N).team == Holder.PlayerReplicationInfo.team)) )
    							{
    								B.AlternatePath = AlternatePath(N);
    								if ( AlternatePath(N).bTwoWay && (AlternatePath(N).team != Holder.PlayerReplicationInfo.team) )
    								{
    									PartialWeight += 4000;
    								}
    								PartialWeight += AlternatePath(N).SelectionWeight;
    								if ( PartialWeight > selection )
    									break;
    							}
    					}
    					B.SendTeamMessage(None, 'OTHER', 2, 10);
    				}
    				else if ( Holder.IsA('TournamentPlayer'))
    				{
    					Log("tplayer");
    					if (TournamentPlayer(Holder).bAutoTaunt || bNotifyPickup==true)
    					{
    						Log("notifyok");
    						Holder.BroadcastMessage (sPickupmsg, false, 'TeamSay');
    						if (TournamentPlayer(Holder).bAutoTaunt || bVoiceNotify==true)
    						{
    							Log("voicenotify");
    							Holder.SendTeamMessage(None, 'OTHER', 2, 10);
    						}
    					}
    				}
    				
    				if (Level.Game.WorldLog != None)
    					Level.Game.WorldLog.LogSpecialEvent("flag_taken", Holder.PlayerReplicationInfo.PlayerID, CTFGame(Level.Game).Teams[Team].TeamIndex);
    				if (Level.Game.LocalLog != None)
    					Level.Game.LocalLog.LogSpecialEvent("flag_taken", Holder.PlayerReplicationInfo.PlayerID, CTFGame(Level.Game).Teams[Team].TeamIndex);
    				BroadcastLocalizedMessage( class'CTFMessage', 6, Holder.PlayerReplicationInfo, None, CTFGame(Level.Game).Teams[Team] );
    				GotoState('Held');
    			}
    		}
    	}
    
    	function BeginState()
    	{
    		bHome = true;
    		bCollideWorld = false;
    		bKnownLocation = true;
    		if ( HomeBase != None ) // will be none when flag is created
    		{
    			HomeBase.bHidden = false;
    			HomeBase.AmbientSound = None;
    		}
    		SetTimer(1.0, true);
    		SetCollisionSize(Default.CollisionRadius, Default.CollisionHeight);
    	}
    
    	function EndState()
    	{
    		bHome = false;
    		HomeBase.bHidden = true;
    		SetTimer(0.0, false);
    	}
    }
    
    defaultproperties
    {
         Skin=Texture'Botpack.Skins.JpflagB'
    
    
    	bNotifyPickup=false
    	bVoiceNotify=false
    	bNotifyDrop=false
    	sPickupmsg"I GOT THE FLAG!"
    	sDropmsg="FLAG DROPPED!"
    }
    I really can't figure out what's wrong... It seems like both flags are red, even if they are skinned etc the right way...

    #2
    I re-worked David Catmull's CTF4 for UT99, so if you want the complete source code for it I can email it to you, or possibly host it for a few days.&nbsp;&nbsp;Let me know what works best for you (it runs to about 1Mb total, including the custom textures).

    Comment


      #3
      Thank you, I've sent my email address by pm to you

      However this is my question. Will it work with (say) UTPure or other anticheat software?

      If not then my interest for this modification is going to drop a lot, as I wanted to make a tool useful for ctf clanwars.

      Comment


        #4
        Not sure as it's been a couple of years since I set foot on a UT99 server.&nbsp;&nbsp;The project I re-wrote was a GameType, so UTPure (never heard of it) may not have some sort of config that will allow you to play custom games.&nbsp;&nbsp;You can always just look at the code, and see if it helps with your problem.

        Comment

        Working...
        X