Code:
/**
* Iron sights zoom aiming class by DazJW
*
*/
class AimWeaponClass extends UTWeapon
HideDropDown
abstract;
/** Weapon animations for use while zoomed */
var(Animations) array<name> WeaponFireAnimZoom;
var(Animations) array<name> WeaponIdleAnimsZoom;
/** Arm animations for use while zoomed */
var(Animations) array<name> ArmFireAnimZoom;
var(Animations) array<name> ArmIdleAnimsZoom;
/** Original UT3 values from UTPawn for use while not zoom aiming */
var float BaseGroundSpeed;
var float BaseAirSpeed;
var float BaseWaterSpeed;
var float BaseJumpZ;
/** New values for use while zoom aiming */
var float ZoomGroundSpeed;
var float ZoomAirSpeed;
var float ZoomWaterSpeed;
var float ZoomJumpZ;
/** Spread value while zoom aiming */
var float SpreadScoped;
/** Spread value while not zoom aiming */
var float SpreadNoScoped;
/** Boolean for if the player is zoom aiming */
var bool AmIZoomed;
/** Boolean for if the crosshair should be displayed */
var bool bDisplayCrosshair;
/** Amount of FOV to subract from FOV when zoomed */
var float ZoomedFOVSub;
/** Zoom minimum time, from UT3 Sniper Rifle*/
var bool bAbortZoom;
/** Tracks number of zoom started calls, from UT3 Sniper Rifle */
var int ZoomCount;
/** Tell the server that the client needs this information */
replication
{
if ( Role == ROLE_Authority )
AmIZoomed;
}
/** Function to run when zooming in or out, checks the AmIZoomed boolean and decides which set of properties to use */
server reliable function CheckMyZoom()
{
Local Pawn P;
P = Pawn(Owner);
if (AmIZoomed == true)
{
P.GroundSpeed = Default.ZoomGroundSpeed;
P.AirSpeed = Default.ZoomAirSpeed;
P.WaterSpeed = Default.ZoomWaterSpeed;
P.JumpZ = Default.ZoomJumpZ;
Spread[CurrentFireMode] = Default.SpreadScoped;
FireInterval[CurrentFireMode] = Default.FireInterval[CurrentFireMode]/1.25;
}
else
{
P.GroundSpeed = Default.BaseGroundSpeed;
P.AirSpeed = Default.BaseAirSpeed;
P.WaterSpeed = Default.BaseWaterSpeed;
P.JumpZ = Default.BaseJumpZ;
Spread[CurrentFireMode] = Default.SpreadNoScoped;
FireInterval[CurrentFireMode] = Default.FireInterval[CurrentFireMode];
}
}
/** This adds to the Activate function to force CheckMyZoom when the weapon is equipped so we get the proper values for not zoom aiming */
simulated function Activate()
{
CheckMyZoom();
GetSetFOV();
super.Activate();
}
/** Checks the DisplayCrosshair boolean and acts accordingly, unedited from UT3 Sniper Rifle */
simulated function DrawWeaponCrosshair( Hud HUD )
{
local UTPlayerController PC;
if( bDisplayCrosshair )
{
PC = UTPlayerController(Instigator.Controller);
if ( (PC == None) || PC.bNoCrosshair )
{
return;
}
super.DrawWeaponCrosshair(HUD);
}
}
/** This retrieves the Player's FOV setting for later reference */
simulated function GetSetFOV()
{
local UTPlayerController PC;
PC = UTPlayerController(Instigator.Controller);
ZoomedTargetFOV = PC.FOVAngle - ZoomedFOVSub;
}
/** This runs when you right click to zoom aim - it turns the crosshair off, plays the zoom in animation for the weapon and arms and calls the GotoZoom, PlayMyZoomIdle and ServerGotoZoom functions */
simulated function StartZoom(UTPlayerController PC)
{
ZoomCount++;
if (ZoomCount == 1 && !IsTimerActive('Gotozoom') && IsActiveWeapon() && HasAmmo(0) && Instigator.IsFirstPerson())
{
bAbortZoom = false;
bDisplayCrosshair = false;
PlayWeaponAnimation('WeaponZoomIn',0.2);
PlayArmAnimation('WeaponZoomIn',0.2);
SetTimer(0.2, false, 'Gotozoom');
SetTimer(0.2,false,'PlayMyZoomIdle');
if( Role < Role_Authority )
{
// if we're a client, synchronize server
SetTimer(0.2, false, 'ServerGotozoom');
}
}
}
/** Subtracts the ZoomedFOVSub value in default properties from the players FOV to zoom in, sets AmIZoomed to true and calls the CheckMyZoom function which will return true and set the zoom aiming values as AmIZoomed is set to true */
simulated function Gotozoom()
{
local UTPlayerController PC;
PC = UTPlayerController(Instigator.Controller);
if (GetZoomedState() == ZST_NotZoomed)
{
if (bAbortZoom) // stop the zoom after 1 tick
{
SetTimer(0.0001, false, 'StopZoom');
}
PC.FOVAngle = ZoomedTargetFOV;
PC.StartZoom(ZoomedTargetFOV, ZoomedRate);
}
AmIZoomed = true;
CheckMyZoom();
}
/** Server version of the above to make sure everything is in sync, doesn't set the zoom level because that is a client side visual change */
reliable server function ServerGotoZoom()
{
AmIZoomed = true;
CheckMyZoom();
}
/** This runs when you right click to leave zoom aim mode and calls LeaveZoom and ServerLeaveZoom so everything is in sync again */
simulated function EndZoom(UTPlayerController PC)
{
bAbortZoom = false;
if (IsTimerActive('Gotozoom'))
{
ClearTimer('Gotozoom');
}
SetTimer(0.001,false,'LeaveZoom');
if( Role < Role_Authority )
{
// if we're a client, synchronize server
SetTimer(0.001,false,'ServerLeaveZoom');
}
}
/** This reverses the effects of StartZoom - it resets the zoom level, plays the zoom out animation for the weapon and arms, runs RestartCrosshair which makes the crosshair visible again, sets AmIZoomed to false and runs CheckMyZoom which returns false and sets us back to the original values for everything */
simulated function LeaveZoom()
{
local UTPlayerController PC;
PC = UTPlayerController(Instigator.Controller);
if (PC != none)
{
PC.EndZoom();
}
ZoomCount = 0;
PlayWeaponAnimation('WeaponZoomOut',0.3);
PlayArmAnimation('WeaponZoomOut',0.3);
SetTimer(0.3,false,'RestartCrosshair');
AmIZoomed = false;
bAbortZoom = false;
CheckMyZoom();
}
/** Server version of the above, doesn't reset the zoom level because it was never changed server side and doesn't play the animations because they're a client side visual effect */
reliable server function ServerLeaveZoom()
{
AmIZoomed = false;
CheckMyZoom();
}
/** This stops the zooming in, unedited from UT3 Sniper Rifle */
simulated function StopZoom()
{
local UTPlayerController PC;
if (WorldInfo.NetMode != NM_DedicatedServer)
{
PC = UTPlayerController(Instigator.Controller);
if (PC != None && LocalPlayer(PC.Player) != none)
{
PC.StopZoom();
}
}
}
/** This turns the crosshair on, unedited from the UT3 Sniper Rifle */
simulated function RestartCrosshair()
{
bDisplayCrosshair = true;
}
/** This adds LeaveZoom to the PutDownWeapon function in UTWeapon so we get our original zoom level, etcetera back if we switch weapons while zoom aiming, unedited from the UT3 Sniper Rifle */
simulated function PutDownWeapon()
{
LeaveZoom();
Super.PutDownWeapon();
}
/** This stops autoswitching to a newly picked up weapon while zoom aiming, unedited from the UT3 Sniper Rifle */
simulated function bool DenyClientWeaponSet()
{
// don't autoswitch while zoomed
return (GetZoomedState() != ZST_NotZoomed);
}
/** This forces a zoom out if you enter a vehicle while zoom aiming, unedited from the UT3 Sniper Rifle */
simulated function HolderEnteredVehicle()
{
local UTPawn UTP;
PlayWeaponAnimation('WeaponZoomOut', 0.3);
if (WorldInfo.NetMode != NM_DedicatedServer)
{
UTP = UTPawn(Instigator);
if (UTP != None)
{
// Check we have access to mesh and animations
if (UTP.ArmsMesh[0] != None && ArmsAnimSet != None && GetArmAnimNodeSeq() != None)
{
UTP.ArmsMesh[0].PlayAnim('WeaponZoomOut', 0.3, false);
}
}
}
}
/** Adds to UTweapon's PlayWeaponPutDown to stop zoom aiming related stuff if we switch away from the weapon */
simulated function PlayWeaponPutDown()
{
ClearTimer('GotoZoom');
ClearTimer('StopZoom');
if(UTPlayerController(Instigator.Controller) != none)
{
UTPlayerController(Instigator.Controller).EndZoom();
}
super.PlayWeaponPutDown();
}
/** Overwrites UTweapon's PlayFireEffects to decide whether we should be playing the normal fire animation or the zoom aiming firee animation */
simulated function PlayFireEffects( byte FireModeNum, optional vector HitLocation )
{
if (AmIZoomed == true)
{
if ( FireModeNum < WeaponFireAnim.Length && WeaponFireAnim[FireModeNum] != '' )
PlayWeaponAnimation( WeaponFireAnimZoom[FireModeNum], GetFireInterval(FireModeNum) );
if ( FireModeNum < ArmFireAnim.Length && ArmFireAnim[FireModeNum] != '' && ArmsAnimSet != none)
PlayArmAnimation( ArmFireAnimZoom[FireModeNum], GetFireInterval(FireModeNum) );
}
else
{
if ( FireModeNum < WeaponFireAnim.Length && WeaponFireAnim[FireModeNum] != '' )
PlayWeaponAnimation( WeaponFireAnim[FireModeNum], GetFireInterval(FireModeNum) );
if ( FireModeNum < ArmFireAnim.Length && ArmFireAnim[FireModeNum] != '' && ArmsAnimSet != none)
PlayArmAnimation( ArmFireAnim[FireModeNum], GetFireInterval(FireModeNum) );
}
// Start muzzle flash effect
CauseMuzzleFlash();
ShakeView();
}
/** Adds to UTweapon's Active state to decide whether we should be playing the normal idle animation or the zoom aiming idle animation */
simulated state Active
{
simulated event OnAnimEnd(optional AnimNodeSequence SeqNode, optional float PlayedTime, optional float ExcessTime)
{
local int IdleIndex;
if ( WorldInfo.NetMode != NM_DedicatedServer && WeaponIdleAnims.Length > 0 )
{
if (AmIZoomed == true)
{
IdleIndex = Rand(WeaponIdleAnimsZoom.Length);
PlayWeaponAnimation(WeaponIdleAnimsZoom[IdleIndex], 0.0, true);
if(ArmIdleAnims.Length > IdleIndex && ArmsAnimSet != none)
{
PlayArmAnimation(ArmIdleAnimsZoom[IdleIndex], 0.0,, true);
}
}
else
{
IdleIndex = Rand(WeaponIdleAnims.Length);
PlayWeaponAnimation(WeaponIdleAnims[IdleIndex], 0.0, true);
if(ArmIdleAnims.Length > IdleIndex && ArmsAnimSet != none)
{
PlayArmAnimation(ArmIdleAnims[IdleIndex], 0.0,, true);
}
}
}
}
}
/** Plays the zoom aiming versions of the idle animations for the weapon and arms */
simulated function PlayMyZoomIdle()
{
local int IdleIndex;
IdleIndex = Rand(WeaponIdleAnims.Length);
PlayWeaponAnimation(WeaponIdleAnimsZoom[IdleIndex], 0.0, true);
if(ArmIdleAnims.Length > IdleIndex && ArmsAnimSet != none)
{
PlayArmAnimation(ArmIdleAnimsZoom[IdleIndex], 0.0,, true);
}
}
defaultproperties
{
//
//These values do not need to be present in your weapon class if you extend this class
//
//This is necessary so secondary fire doesn't actually fire
InstantHitDamageTypes(1)=None
FiringStatesArray(1)=Active
FireInterval(1)=+0.00001
//This defines the animations for the arms and the weapon while zoom aiming
WeaponFireAnimZoom(0)=WeaponZoomFire
WeaponIdleAnimsZoom(0)=WeaponZoomIdle
ArmFireAnimZoom(0)=WeaponZoomFire
ArmIdleAnimsZoom(0)=WeaponZoomIdle
//This sets which fire mode is zoom mode
bZoomedFireMode(0)=0
bZoomedFireMode(1)=1
//This says to display the crosshair when the weapon is first equipped
bDisplaycrosshair = true;
//This vastly reduces the weapon bob effect when landing from a jump or fall in order to prevent model clipping while aiming
JumpDamping=0.1
//These reduce the weapon lagging behind the crosshair effect to ensure the sights are properly lined up when you enter zoom aiming mode
MaxPitchLag=40
MaxYawLag=50
//Original UT3 movement values to use while not zoom aiming
BaseGroundSpeed=440.0
BaseAirSpeed=440.0
BaseWaterSpeed=220.0
BaseJumpZ=322.0
//This says the weapon isn't zoom aiming when the weapon is first equipped
AmIZoomed=false
//This sets how fast we want to zoom, a very high value gives an instant zoom rather than the UT3 Sniper Rifle's hold to zoom setup
ZoomedRate=300000.0
//
//This value does not need to be present in your weapon class but can be if you wish to have a different amount of zoom while zoom aiming
//
//This sets how much we want to zoom in, this is a value to be subtracted because smaller FOV values are greater levels of zoom
ZoomedFOVSub=60.0
//
//These values should be present in your weapon class and be altered to suit your needs
//
//This is the spread value for use while zoom aiming, smaller number is more accurate
SpreadScoped=0.0025
//This is the spread value for use while not zoom aiming, larger number is less accurate
SpreadNoScoped=0.045
//New lower speed movement values for use while zoom aiming
ZoomGroundSpeed=210.0
ZoomAirSpeed=340.0
ZoomWaterSpeed=110.0
ZoomJumpZ=256.0
}
this is the coding that i used from your download, i did nothing to it
Bookmarks