Announcement

Collapse
No announcement yet.

Enhanced Vehicle EMP

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

    Enhanced Vehicle EMP

    I've always disliked the stock EMP & especially the stock EMP mine. It goes off way too many times & will shut a vehicle down for a huge duration. Long ago I modded Hedsteem's EMP mine to just activate once but I still dislike the fact that you get kicked out of the vehicle & it stays locked for 20 seconds. It might as well just blow up the vehicle because by the time it becomes unlocked again it's usually destroyed. If you could stay in the vehicle then at least you would have the advantage of the vehicle protecting you at least until it ran out of health. So after kicking this idea around in my head for years, I finally decided to recode the vehicle EMP, at least for the vehicles I'm making for my server. So I thought I would share the code in case someone else would like to use it. I was surprised at how simple it was & got it to work on the first try. When a vehicle gets EMP'd, it shuts the vehicle down & disables the weapon system. After the EMP duration has lapsed, the vehicle becomes operational again. If you leave the vehicle during the EMP duration, it locks the vehicle to prevent you from just re-entering the vehicle & cancelling the EMP duration. I had to make a different EMP code for flying vehicles. Here is the code with notes explaining what is going on. Add this code to your vehicle for the new EMP effect.

    Code:
    //new emp code for ground vehicles//==========================================================
    simulated function bool DisableVehicle()
    {
    
    
    	if ( Occupied() )
    	{
    		bIsDisabled = true;  //disables vehicle
    
    		if (Role == ROLE_Authority)
    		{
    			SetTimer(DisabledTime, false, 'EnableVehicle');  //starts the EMP duration timer
    			SetDriving(false);  //hack to fool the game engine to think no one is driving
    		        StopFiringWeapon(); //Stop shooting
    		}
    
    
    
    
    
    		if (WorldInfo.NetMode != NM_DedicatedServer)
    		{
    			if (DisabledEffectComponent == None)
    			{
    				DisabledEffectComponent = new(self) class'ParticleSystemComponent';
    				DisabledEffectComponent.SetTemplate(DisabledTemplate);
    				AttachComponent(DisabledEffectComponent);
    			}
    			DisabledEffectComponent.ActivateSystem();
    		}
    		return true;
    	}
    	return false;
    }
    
    simulated function EnableVehicle()
    {
    	bIsDisabled = false;  //starts the vehicle back up
    
    
    	if (WorldInfo.NetMode != NM_DedicatedServer && DisabledEffectComponent != None)
    	{
    		DetachComponent(DisabledEffectComponent);
    		DisabledEffectComponent = None;
    	}
    		if ( Controller == None )  //check to see if driver left
                    {
                      SetDriving(false);  //no one driving, leave shut down
    		}
                           else
                    {
                      SetDriving(true);  //driver detected, start vehicle
                    }
    }
    
    defaultproperties
    {
       DisabledTime=5.000000  //set this to the desired EMP duration
    }
    Code:
    /** state to automatically land when player jumps out while high above land */
    //fixed to make flying vehicles crash to the ground when EMP'd
    state AutoLanding
    {
    	simulated function SetDriving(bool bNewDriving)
    	{
    		if ( bNewDriving )
    		{
    			GotoState('Auto');
    			Global.SetDriving(bNewDriving);
    		}
    	}
    
    	function bool Died(Controller Killer, class<DamageType> DamageType, vector HitLocation)
    	{
    		if (Global.Died(Killer, DamageType, HitLocation))
    		{
    			SetDriving(false);
    			return true;
    		}
    		else
    		{
    			return false;
    		}
    	}
    
    	function Tick(float DeltaTime)
    	{
    		local actor HitActor;
    		local vector HitNormal, HitLocation;
    
                      if (bIsDisabled)  //check to see if this vehicle has been EMP'd
    		{
    			GotoState('Auto');  //disable auto landing
    			SetDriving(false);
    		}
    
    		if (bChassisTouchingGround)
    		{
    			GotoState('Auto');
    			SetDriving(false);
    		}
    		else
    		{
    			HitActor = Trace(HitLocation, HitNormal, Location - vect(0,0,2500), Location, false);
    			if ( Velocity.Z < -1200 )
    				OutputRise = 1.0;
    			else if ( HitActor == None )
    				OutputRise = -1.0;
    			else if ( VSize(HitLocation - Location) < -2*Velocity.Z )
    			{
    				if ( Velocity.Z > -100 )
    					OutputRise = 0;
    				else
    					OutputRise = 1.0;
    			}
    			else if ( Velocity.Z > -500 )
    				OutputRise = -0.4;
    			else
    				OutputRise = -0.1;
    		}
    	}
    }
    
    
    //new emp code for flying vehicles
    simulated function bool DisableVehicle()
    {
    
    
    	if ( Occupied() )
    	{
    		bIsDisabled = true;  //disables vehicle
    
    
    		if (Role == ROLE_Authority)
    		{
    			SetTimer(DisabledTime, false, 'EnableVehicle');  //starts the EMP duration timer
    			SetDriving(false);  //hack to fool the game engine to think no one is driving
    		        StopFiringWeapon(); //Stop shooting
    		        bAutoLand=False; //disable auto land
    		}
    
    	if ( UTVehicleSimChopper(SimObj) != None )  //this code disables all movement. bots like to over ride!
    	{
    		UTVehicleSimChopper(SimObj).MaxThrustForce=0.000000;
    		UTVehicleSimChopper(SimObj).MaxReverseForce=0.000000;
    		UTVehicleSimChopper(SimObj).MaxStrafeForce=0.000000;
    		UTVehicleSimChopper(SimObj).MaxRiseForce=0.000000;
    		UTVehicleSimChopper(SimObj).TurnTorqueMax=0;
    		UTVehicleSimChopper(SimObj).RollTorqueMax=0;
    	}
    
    
    
    		if (WorldInfo.NetMode != NM_DedicatedServer)
    		{
    			if (DisabledEffectComponent == None)
    			{
    				DisabledEffectComponent = new(self) class'ParticleSystemComponent';
    				DisabledEffectComponent.SetTemplate(DisabledTemplate);
    				AttachComponent(DisabledEffectComponent);
    			}
    			DisabledEffectComponent.ActivateSystem();
    		}
    		return true;
    	}
    	return false;
    }
    
    simulated function EnableVehicle()
    {
    	bIsDisabled = false; //starts the vehicle back up
    
    	if (WorldInfo.NetMode != NM_DedicatedServer && DisabledEffectComponent != None)
    	{
    		DetachComponent(DisabledEffectComponent);
    		DisabledEffectComponent = None;
    	}
    
    	if ( UTVehicleSimChopper(SimObj) != None )  //gives controls back to driver. the values are in the vehicles sim vehicle class.
    	{
    		UTVehicleSimChopper(SimObj).MaxThrustForce=800.000000;
    		UTVehicleSimChopper(SimObj).MaxReverseForce=200.000000;
    		UTVehicleSimChopper(SimObj).MaxStrafeForce=550.000000;
    		UTVehicleSimChopper(SimObj).MaxRiseForce=600.000000;
    		UTVehicleSimChopper(SimObj).TurnTorqueMax=10000;
    		UTVehicleSimChopper(SimObj).RollTorqueMax=150;
    	}
    		if ( Controller == None )  //check to see if driver left
    		{
                                        SetDriving(false);  //no one driving, leave shut down
    		                    bAutoLand=True;  //enable auto land
    		}
                                             else
                                             {
                                                    	SetDriving(true);  //driver detected, start vehicle
    		                                        bAutoLand=True;   //enable auto land
    
                                              }
    
    }
    
    
    
    defaultproperties
    {
       DisabledTime=5.000000  //set this to the desired EMP duration

    #2
    This is going to work great in the new version of UT.

    Comment

    Working...
    X