Unreal Script: An Introduction
Parts 7 to 8
Brandon Holbert
7. Complex Types
• Delegates
• Interfaces
• Pre Processors
Delegates
• Unreal script delegates or delegates in other languages like c# for example aren’t the easiest concept to grasp.
• They’re simply function pointers even in
Uscript.
• You define the type of function and what arguments it needs to look for, and that’s a delegate.
Delegates
• So in Uscript
– Declaration:
Class Button extends Window; delegate OnClick( Button B, int MouseX, int MouseY
); function MyOnClick ( Button B, int MouseX, int
MouseY)
{
}
Delegates
Class button extends window;
Var int MouseDownX, MouseDownY;
Delegate OnClick(Button B, int MouseX, int MouseY );
Function MouseDown( int MouseX, int MouseY)
{
MouseDownX = MouseX;
MouseDownY = MouseY;
}
Function MouseUp (int MouseX, int MouseY)
{ if( MouseX == MouseDownX && MouseY == MouseDownY )
OnClick (self, MouseX, MouseY);
}
Delegates
• Or if you had it in a function argument delegate OnClick (int a, int b); function Foo (delegate<OnClick> myDelegate)
{ local int x, y; myDelegate(x, y);
}
Delegates
.
Class myClass extends object; var Button aButton; function bar(int a, int b)
{ aButton.OnClick = someFunc;
}
Delegates function someFunc(int a, int b) {} defaultProperties
{ aButton.OnClick = bar
}
Interfaces
• Interfaces like many things in unreal script is very similar to the equivalent java implementation.
• Interfaces can only contain function declarations and no content in the function body. The functions will be fully implemented in the class that will use the interface. States, events, functions, delegates can all be used in an interface. Enums, structs, consts can also be used in an interface but not variables.
Interfaces
• Declaring an interface
– Interfaces can inherit from other interfaces.
– If there is no inheritance the interface automatically inherits from core.interface
Interface myInterface extends parentInterface;
// the rest…
Interfaces
• You’ll see a lot of native interfaces in unreal script also.
• Native means that the class uses c++ in some way.
• It will either have a c++ code snippet in the class or it will use c++ code in another class.
– Native classes in Uscript get there own header files at compile time and it’s another way to interact with the unreal engine.
Interfaces
• Referencing an interface from a class
Class < className > extends < parentClassName > implements(<interfaceName1>,
<interfaceName2>,…);
• To use the interface in a class that implements it you call it like you do with any other class
– myInterface.Foo(int(a), float(b));
Pre Processors
• In Uscript they are usually for conditional blocks of code like `debug or `final_release
• The syntax for any pre processor is the back quote followed by the name
`<preproccesorName>
• Pre-processors in any language happens before the compilation of anything else so the same goes here.
• A macro can only be used across one file and any inherited classes can’t take advantage of its parent classes macro directly.
Pre Processors
• Defining a new Uscript macro
– `define <newMacroName> (params[]) macro body
– `define myNewMacro “my macro”
• After that every place you use the macro it will be replaced by your definition
• A multi-line definition for a macro
– `define aMacro(anInt) \n
– var int `anInt \n
– // a third line
Pre Processors
– You use the “\n” to expand on your macro and implement it on more than 1 line
– The left parenthesis for the parameter list for a macro must come right after the macro name with no spaces. That is really the only limitation for the syntax. Otherwise you should be okay to write it how you want
– If no body is defined for a macro it will expand to a empty string (“”)
Pre Processors
• Common macros
– `if (<condition>)
`else
`endif
– Just like a normal if else block if the macro’s condition is true it will enter that block if false it will go to the else block. End if is used to denote the end of the entire if/else block
– `isdefined(<macroname>) &
`notdefined(<macroname>)
• Both conditional macros
• Returns a 1 if true
– `undefine(<macroname>)
• Remove the definition for the macro specified
– Wont’ work with macros that have `cond, `txt, `#
Pre Processors
• Common macros
– `include(<filename>)
• `include(Engine\Classes\GameStats.uci);
• Includes the contents of a file in a given file location
– If you only specify the filename without the directory structure then it will search for the include file in the classes directory for the package that is being compiled (example the Engine package)
• This is in the GameplayEvents class which extends Object
– That file “Engine\Classes\GameStats.uci” just like the classes we’ve been making is the file path for the uci file GameStats.
Which contains a list of global events like const
GAMEEVENT_MATCH_STARTED.
– The GameStats.uci file is a great reference file for macro syntax
Pre Processors
• Log & Warn
• `log(<outputstring>, optional bool
<requiredCondition>, optional name logName);
• `warn(<outputstring>, optional bool
<requiredCondition>);
– The condition specified means that the log or warnign will only be called if the condition is true
– Both of these are disabled if final_Release is used.
Pre Processors
• Assert
– `assert(bool <condition>)
• `assert(QueryCompletionAction ==
QUERYACTION_None);
• if ( GameInterface != None )
• {
– GameInterface.ClearJoinOnlineGameCompleteDelega
te(OnJoinGameComplete);
– GameInterface.ClearFindOnlineGamesCompleteDeleg
ate(OnFindOnlineGamesCompleteDelegate);
• }
– If the enum QueryCompletionAction is equal to
QueryAction_None then proceed into the if statement
8. Weapons
• In this section we’ll go through creating a simple weapon based off of the rocket launcher.
• Then we’ll go a step further and show some tips and tricks a long the way.
Weapon types
• The rocket launcher in udk is different than most of the other weapons in the unreal tournament lineup.
• Not only do you have a weapon with functions that handle shooting and variables for shooting intervals, but you have a projectile object that is totally separate from the weapon.
Weapon types
• It get’s it own mesh a lifetime and many things it can do within its lifetime and you can make many things and be very creative with what you get with just UDK.
• So we’ll mod the rocket launcher and we’ll need to make a weapon class and projectile class.
Weapons
• The naming convention unreal goes with are
UTWeap_<weaponName> and
UTProj_<projectileName>.
• Create a UTProj_PlasmaRocket and
UTWeap_PlasmaRocketLauncher class.
Weapons, PlasmaRocketLauncher
• So we’re going to mod two weapons together.
• We want to mod the rocket launcher but use the shock ball from the shock rifle.
• We also want the shock ball to bounce off of walls.
Weapons, PlasmaRocketLauncher
• We want our UTWeap_PlasmaRocketLauncher class to extend
UTWeap_RocketLauncher_Content.
• The rocket launcher content class has many variables that we want to keep
• That is why we go off of that class and not directly off of UTWeap_RocketLauncher
Weapons, PlasmaRocketLauncher
• At any point you wanted to override a variable just call it in your default properties block and give it your own value.
• So in default properties:
DefaultProperties
{
WeaponProjectiles(0)=class’UTProj_PlasmaRocketLauncher’
AmmoCount=18
}
Weapons, PlasmaRocketLauncher
• If you find where weapon projectiles is used in the classes we’re extending you’ll see we just overrode the LMB fire mode to use our new projectile class.
• By default it was set to ‘UTProj_Rocket’ which is the rocket fired by the rocket launcher. Not too hard right?
– Be aware that because both files will be in the same package (UnrealScriptIntro) we don’t need to define the
<packageName>.className just the class name.
Weapons, PlasmaRocket
• Go to the UTProj_PlasmaRocket class that you created earlier and have it extend UTProj_Rocket;
– For the most part we don’t want to remake how the projectile lives since most of this functionality is implemented in the extended class UTProj_Rocket.
– The rocket projectile class is a great class to extend for any grenade or projectile you use that will do something during it’s life time that is logic based.
– Some things can be handled by UDK’s particle system.
– So keep both options in mind, but one is visual and the other (the particles) and the other can include unique functionality like locking on a target.
Weapons, PlasmaRocket
• With the two classes as is you should be able to go into the editor and see your weapon type.
• Easiest way for me to do this is to place down a weapon locker and have the new weapon spawn on it.
• View > Actor Classes > Pickups > Weapon >
UTWeaponPickupFactory.
• Place the actor in the world and in it’s properties find the weapon to spawn and you should see
PlasmaRockectLauncher in there.
Weapons, PlasmaRocket
Weapons, PlasmaRocket
• Okay so the requirement for the projectile was to use the shock ball from the shock rifle and make it bounce off the walls.
• If you navigate into the UTProj_Rocket class that our projectile class is extending we’ll find a few variables we’ll want to override.
Weapons, PlasmaRocket
• ProjFlightTemplate, ProjExplosionTemplate,
ProjectileLightClass.
• Copy all three of those lines in UTProj_Rocket into the default properties for
UTProj_PlasmaRocket.
Weapons, PlasmaRocket
• There are three things we need to get in relation to the shock ball.\ You’ll notice that the
ProjFlightTemplate and
ProjExplosionTemplate both equal a particle systems.
• The best way to find what we want is to hop into the editor.
• In there you can rightclick objects and get their full name.
Weapons, PlasmaRocket
• In the editor and in the content browser you’ll find what we want under the UDKGame package Content > UT3 > Weapons >
WP_ShockRifle > P_WP_ShockRifle_Ball
Weapons, PlasmaRocket
• So in default properties you should have
DefaultProperties
{
}
ProjFlightTemplate=ParticleSystem’WP_Shock
Rifle.Particles.P_WP_ShockRifle_Ball’
ProjExplosionTemplate= //nothing yet
ProjectileLightClass= // nothing yet
Weapons, PlasmaRocket
• Now we need the explosion. Back in UEd
UDKGame > Content > UT3 > Weapons >
WP_ShockRifle >
P_WP_ShockRifle_Ball_Impact. This particle system represent what the death of our projectile will look like to the user.
Weapons, PlasmaRocket
{
• So in default properties you should now have this
DefaultProperties
}
ProjFlightTemplate=ParticleSystem’WP_ShockRifle.Particle
s.P_WP_ShockRifle_Ball’
ProjExplosionTemplate=
ParticleSystem’WP_ShockRifle.Particles.P_WP_ShockRifle_B
all_Impact’
ProjectileLightClass= // nothing yet
Weapons, PlasmaRocket
• The last thing is the projectile’s light class
• We don’t want the orange rocket light we want the blue/purple shockball light.
• So set it to class’UTGame.UTShockBallLight’ which is referencing a .uc file in the UTGame package.
• We’ll be creating our own later on.
• Now we need to bounce off of some walls!
Weapons, PlasmaRocket
• The bouncing code will exist in the projectile class because when the projectile is created (when the player fires the weapon) it is its own object and the weapon won’t influence it anymore.
• Now you can add things to your class to allow the weapon and projectile talk or the player and projectile to talk more likely but that is a different set of modifying.
• There are going to be a few functions we’ll be modding for in for our projectile and they originally exist in the UTProjectile class.
Weapons, PlasmaRocket
• The first one is ProcessTouch(Actor other,
Vector HitLocation, Vector HitNormal).
• What this does is it says if we hit an actor like a pawn then have that actor take damage.
• If not, if DamageRadius > 0.0 (meaning there isn’t an area we can damage) explode at the location we’re at.
• So we want direct damage to an actor but we don’t want it hitting a wall and exploding.
Weapons, PlasmaRocket
• Copy the function into our projectile class and set it to this
/**
* We don’t want our projectile to explode when it hits stuff.
*/ simulated function ProcessTouch(Actor Other, Vector
HitLocation, Vector HitNormal)
{
// If the object isn't ourself. We are the instigator.
if(Other != Instigator)
{
Other.TakeDamage(Damage,InstigatorController,HitLocation,Mo mentumTransfer * Normal(Velocity), MyDamageType,, self);
Shutdown();
}
}
Weapons, PlasmaRocket
• The next function is we want to override is HitWall.
Which exists in Projectile.uc. If you trace back up you’ll get to it.
– Now HitWall exists in more than one class but we want to override the one in Projectile.uc
• So HitWall(Vector HitNormal, actor Wall,
PrimitiveComponent WallComp)
• Copy and paste that function into our projectile class.
• Now we don’t care about the meat of the function.
• So we can remove that.
Weapons, PlasmaRocket
• What we want is to set the projectiles velocity a mirror of the vector we hit the wall at, and we want to set the projectile’s rotation.
• So we’ll adjust the Velocity property of the projectile and set it to MirrorVectorByNormal(Velocity,
HitNormal).
• Then we want to call SetRotation(Rotator(Velocity)).
That function will apply that value to our projectile.
Otherwise it won’t change anything with just adjusting the velocity. So you should have this. Oh let’s also add a `log statement.
Weapons, PlasmaRocket
/**
* What to do when we hit a wall
*/ simulated event HitWall(vector HitNormal, actor
Wall, PrimitiveComponent WallComp)
{
`log("I HIT A WALL!");
}
Velocity = MirrorVectorByNormal(Velocity,
HitNormal); // bounce off of the wall
SetRotation(Rotator(Velocity));
Weapons, PlasmaRocket
• Another variable we should adjust is the speed variable.
• Play around with it, but start off with nothing to crazy like 500.
• Set the lifespan and DrawScale as well.
• The rocket is pretty small with it’s default size and we want to see the shock ball.
Weapons, PlasmaRocket
DefaultProperties
{
ProjFlightTemplate=ParticleSystem’WP_ShockRifle.Particles.P_WP_
ShockRifle_Ball’
ProjExplosionTemplate=
ParticleSystem’WP_ShockRifle.Particles.P_WP_ShockRifle_Ball_Imp
act’
ProjectileLightClass= // nothing yet
}
Speed = 500 // or 200000 for crazy speed!!!
LifeSpan=25.0 // if set to 0.0 then infinite lifetime until it’s forced to explode via contact to
// enemy.
DrawScale = 1.4
Weapons, PlasmaRocket
• Add sound
• We don’t want the rocket sound for the shock ball.
• So same drill as before.
• In UEd find in the content browser under UDKGame >
Content > UT3 > Sounds > Weapon >
A_Weapon_ShockRifle >
A_Weapon_SR_ComboExplosion.
– Copy the full name.
• Back in DefaultProperties add a variable to override
– ExplosionSound=SoundCue'A_Weapon_ShockRifle.Cue
.A_Weapon_SR_ComboExplosionCue'
Weapons, PlasmaRocket
• Thanks to Eat3D.com and Rusty Sempsrott for most of that material. “Unreal Script: An Introduction and Application” 2011
Weapons, PlasmaRocket Mod
• Let’s further customize our weapon.
• Now I’ve been playing too much Battlefield 3 and Mass Effect lately.
• So I want an over the shoulder view with a right-click zoom and I want a rifle with a under-slung grenade launcher.
• So we’ll have a bit o’ work to do.
Weapons, PlasmaRocket Mod
– The best way to mod is finding what’s already been done
– Seeing how it’s implemented
– Stripping that code and converting it to how you want it.
– So really explore UDK and what it ships with.
Weapons, PlasmaRocket Mod
• What we have at the moment is a rocket launcher that shoots a bouncing shock ball with the LMB and if you hold the RMB shoots up to 3 rockets.
• Let’s start simple and modify the projectile. I don’t want a shock ball or rocket. As we learned before when making the plasma rocket we had to use particle systems for the
ProjExplosionTemplate and ProjFlightTemplate.
Weapons, PlasmaRocket Mod
• So go into UEd and find under
UDKGame > Content > UT3 >
Vehicles > VH_Manta >
PS_Manta_Projectile.
– Grab the full name and copy that for the value of the
ProjFlightTemplate
Weapons, PlasmaRocket Mod
• Now I’m partial to big explosions so for the ProjExplosionTemplate find in the Content Browser in
UEd under UDKGame package
Content > UT3 > Effects >
FX_VehicleExplosions >
PS_Vehicle_DamageImpact
– Grab the full name and copy that for the value of ProjExplosionTemplate
Weapons, PlasmaRocket Mod
• So we don’t want a purple light for our new projectile. I
• ’m sure this is an appropriate one made for it as well, but let’s make our own.
• Create a new class and call it ModBulletLight
• The variable we’ll override is called
ProjectileLightClass.
Weapons, PlasmaRocket Mod
• So this is the light you would see as the projectile is flying.
• It’s a point light.
• So if you’ve made one in UEd it’s just like that.
• So our light class will extend
PointLightComponent, and pretending this is my first point light I’ve made in Uscript let’s go back up to UTProj_Rocket and see what light class it used. class'UTGame.UTRocketLight‘.
Weapons, PlasmaRocket Mod
• Okay So I know if we go to UTRocketLight.uc in the UTGame package we’ll see what types of variables we can mod.
• Alright so we have Brightness, Radius,
LightColor. We can use that.
• We also can look at what a point light has for it’s properties in UEd.
Weapons, PlasmaRocket Mod
• Great. If we take a look at the properties here we see a lot all of the properties we’ll want to adjust.
• So add this to your default properties in your
ModBulletLight class defaultproperties
{
Brightness=9
Radius=40
CastShadows=false
LightColor=(R=255,G=254,B=
249,A=230)
}
Weapons, PlasmaRocket Mod
• All of that from fooling around with a pointlight in UEd.
• Finally set that variable in the
UTProj_PlasmaRocket class
ProjectileLightClass=class'UnrealScriptIn tro.ModBulletLight'
Weapons, PlasmaRocket Mod
• Another thing is that we don’t want is to bounce off of the walls.
• So you can replace what’s in HitWall (Keep the log if you want)
• Replace that code with super.HitWall(HitNormal, Wall, WallComp).
Weapons, PlasmaRocket Mod
• Just like java what we just did was say “call our parent class’s definition for this function
HitWall”.
• Alright let’s adjust our
UTWeap_PlasmaRocketLauncher class
Weapons, PlasmaRocket Mod
DefaultProperties
{
WeaponProjectiles(0)=class'UTProj_Plas maRocket'
// Ammo
AmmoCount=20
MaxAmmoCount=1000
// time between each fire
FireInterval(0)=+.09
Weapons, PlasmaRocket Mod
MuzzleFlashPSCTemplate=MyPackage.Effects.P_
WP_RockerLauncher_Muzzle_Flash_NEW
MuzzleFlashDuration=0.08
MuzzleFlashLightClass=class'UTGame.UTRocket
MuzzleFlashLight’
}
• So what we adjusted were ammo properties, and how quickly we want each round to fire when we hold the LMB
Weapons, PlasmaRocket Mod
• Now we want to add a right-click zoom feature.
• Similar to how mass effect does it.
• So if you’re not familiar with that, it’s a slight zoom in when you click the RMB.
• Now when we’re zoomed in we should also adjust how the weapon fires.
• Something that shows the player is more focused.
Weapons, PlasmaRocket Mod
• So I think we can do that by adjusting fire-rate or accuracy of the weapon.
• Now I know that unreal tournament had a sniper rifle so there must be something already implemented to handle zooming in, and there is.
• In UTWeapon there are two functions we want to use.
Weapons, PlasmaRocket Mod
• One is StartZoom(UTPlayerController PC) which just zooms the camera that’s attached to our player
• EndZoom(UTPlayercontroller PC) which stops the zooming.
• To set up what we’re going to do next. Copy both of those functions into the plasma rocket launcher class.
• Looking through the UTWeapon properties we see more things that we can override.
Weapons, PlasmaRocket Mod
– /** If set to non-zero, this fire mode will zoom the weapon. */
– var array<byte>bZoomedFireMode;
• This is the property we’ll need to set so our RMB does the zooming.
– var float ZoomedTargetFOV;
• How much zoom do we want?
– var float ZoomedRate;
• How quickly do we want to zoom in
– var float ZoomFadeTime;
• A timing variable to adjust how our zoom in and out looks
Weapons, PlasmaRocket Mod
• So here is what we’ll set those to
DefaultProperties
{
// Zoom on RMB, 0 in array is LMB, 1 is
// RMB bZoomedFireMode(1)=1
ZoomedTargetFOV=60.0
ZoomedRate=150.0
}
ZoomFadeTime=.5
Weapons, PlasmaRocket Mod
• Okay so we want to make so that we can only fire in semi-automatic mode when we’re zoomed in.
• That is to say we only fire one round per mouse click when zoomed in and fully automatic when not zoomed in.
Weapons, PlasmaRocket Mod
• So we’ll need a global variable and let’s call it
var bool bIsZoomedInState and in
DefaultProperties set it to false because our default state isn’t going to be zoomed in.
• We also want to reuse the StartZoom and
EndZoom functions in UTWeapon.
• So remove what’s in their bodies right now and do this
Weapons, PlasmaRocket Mod var bool bIsZoomedInState; simulated function StartZoom(UTPlayerController PC)
{ bIsZoomedInState = true; super.StartZoom(PC);
} simulated function EndZoom(UTPlayerController PC)
{ bIsZoomedInState = false; super.EndZoom(PC);
}
Weapons, PlasmaRocket Mod
• In Weapon.uc there are two functions that we can use that control the weapon firing.
– ShouldRefire()
• Checks to see if the weapon can fire again.
– StartFire(byte FireModeNum)
• Called when the local player fires the weapon
• What we want with those functions is to control how we fire and when we can fire based on our zoomed in state.
Weapons, PlasmaRocket Mod simulated function bool ShouldRefire()
{
// if doesn't have ammo to keep on firing, then stop
{ if( !HasAmmo( CurrentFireMode ) ) return false;
}
// don't refire if owner is still willing to fire else if(bIsZoomedInState)
{ return false;
} else
{
// refire if owner is still willing to fire return StillFiring( CurrentFireMode );
}
}
Weapons, PlasmaRocket Mod simulated function StartFire(byte FireModeNum)
{ if(bIsZoomedInState)
{ super.StartFire(FireModeNum); super.EndFire(FireModeNum);
} else
{ super.StartFire(FireModeNum);
}
}
Weapons, PlasmaRocket Mod
• We just overrode those to functions so that when we’re zoomed we fire once and stop so no sequential fire.
• The fire event is done.
• One thing to note is that the parent version of
StartFire has an exec keyword.
• This means that it can take commands from the user via keybindings.
Weapons, PlasmaRocket Mod
• So you’ll find those in config files.
• We’ll get to that later.
• The next step is adjusting the accuracy of our projectiles when we fire.
• We’ll do that in the projectile class
UTProj_PlasmaRocket
Weapons, PlasmaRocket Mod
• In UTWeapon there is a function called
GetZoomedState() and it returns true if we’re zoomed in.
• We’ll need to override that.
• The function handles a few properties that we don’t deal with.
• We simply want to return true or false if we’re zoomed in.
Weapons, PlasmaRocket Mod
• In UTWeapon there is a function called GetZoomedState() and it returns true if we’re zoomed in. We’ll need to override that. The function handles a few properties that we don’t deal with. We simply want to return true or false if we’re zoomed in.
• And we’ll implment it like this simulated function bool GetZoomedState()
{ local PlayerController PC;
PC = PlayerController(Instigator.Controller); if ( PC != none && PC.GetFOVAngle() != PC.DefaultFOV )
{
// zoomed in if ( PC.GetFOVAngle() == PC.DesiredFOV )
{ return true;
}
} return false;
}
Weapons, PlasmaRocket Mod function Init(vector Direction)
{
} if(!GetZoomedState())
{
Direction.X = Direction.X * RandRange(1.0,1.4);
Direction.Y = Direction.Y * RandRange(1.0,1.4);
Direction.Z = Direction.Z * RandRange(1.0,1.4);
} super.Init(Direction);
Weapons, PlasmaRocket Mod
• We still want to use what’s in the original init function so we will call that after we check the zoom state.
• And that’s it!
• You should be able to test that out now.
• The next step will be the grenade launcher!
Weapons, RocketGrenade
• Following the same pattern we want to create two classes UTWeap_RocketGrenade and
UTProj_RocketGrendade.
• class UTWeap_RocketGrenade extends
UTWeap_RocketLauncher_Content;
• class UTProj_RocketGrenade extends
UTProj_Grenade;
Weapons, RocketGrenade
• In the UTProj_Grenade class we have a function that we need to change.
• That’s PostBeginPlay() which sets certain variables after the grenade has been created.
• UTProj_Grenade is setting a cooking time so that the grenade detonates after X time has elapsed.
Weapons, RocketGrenade
• It also sets a rotation for the grenade.
• This is a good thing to keep if we were doing a hand thrown grenade to simulate the possible flight characteristics of that.
• But we want to change that for our grenade launcher.
• So add this PostBeginPlay() to
UTProj_RocketGrenade
Weapons, RocketGrenade simulated function PostBeginPlay()
{ super.PostBeginPlay();
SetTimer(0,false); // After X time call
Timer(). If input is 0 don't call Timer.
}
RotationRate.Yaw = 0;
RotationRate.Roll = 0;
RotationRate.Pitch = 0;
Weapons, RocketGrenade
• In that parent grenade class there is also a
HitWall function.
• If the grenades hits the ground or a wall it will bounce.
• Our grenade is moving too fast to not explode on impact.
• So we also want to override that so we can remove the bouncing feature.
Weapons, RocketGrenade simulated event HitWall(vector HitNormal, Actor
Wall, PrimitiveComponent WallComp)
{ bBlockedByInstigator = true; if ( WorldInfo.NetMode != NM_DedicatedServer )
{
PlaySound(ImpactSound, true);
}
}
`log("I HIT A WALL!");
Explode(Location, HitNormal);
Weapons, RocketGrenade
• No we’ll go set our default properties
• UTProj_RocketGrenade
DefaultProperties
{
ProjFlightTemplate=ParticleSystem'MyPackage.Effects.P_W
P_RocketLauncher_Smoke_Trail_NEW'
ProjExplosionTemplate=ParticleSystem'WP_RocketLauncher.
Effects.P_WP_RocketLauncher_RocketExplosion'
ExplosionLightClass=class'UTGame.UTRocketExplosionLight
'
//ProjFlightTemplate=ParticleSystem'WP_ShockRifle.Parti
cles.P_WP_ShockRifle_Ball'
//ProjExplosionTemplate=ParticleSystem'WP_ShockRifle.Pa
rticles.P_WP_ShockRifle_Beam_Impact‘
Weapons, RocketGrenade
ExplosionSound=SoundCue'A_Weapon_ShockRifle.Cue.A_
Weapon_SR_ComboExplosionCue'
ProjectileLightClass=class'UnrealScriptIntro.ModBulletLight'
DrawScale=0.5
MaxSpeed=20000.0
Speed=2850.0
LifeSpan=300.0
Damage=100.0
}
• One thing to note is that I modified the original smoke trail particle system for the rocket launcher. It is a thin smoke trail that shoots out the back of the projectile.
Weapons, RocketGrenade
MaxEffectDistance=20000.0
MaxExplosionLightDistance=+10000.0
TossZ=+0.0
bNetTemporary=false bWaitForEffects=false
DurationOfDecal=20.0
bBounce=false;
DamageRadius=400.0
ExplosionDecal=MaterialInstanceTimeVarying'WP_Rocket
Launcher.Decals.MITV_WP_RocketLauncher_Impact_Deca
l01'
DecalWidth=128.0
DecalHeight=128.0
Weapons, RocketGrenade
}
AmbientSound=SoundCue'A_Weapon_RocketLauncher.Cue.A_
Weapon_RL_Travel_Cue'
ExplosionSound=SoundCue'A_Weapon_RocketLauncher.Cue.
A_Weapon_RL_Impact_Cue'
RotationRate=(Roll=50000) bCollideWorld=true
CheckRadius=0.0
bCheckProjectileLight=true
ExplosionLightClass=class'UTGame.UTRocketExplosionLi
ght' bAttachExplosionToVehicles=false
Weapons, RocketGrenade
• UTWeap_RocketGrenade class UTWeap_RocketGrenade extends UTWeap_RocketLauncher_Content;
DefaultProperties
{
WeaponProjectiles(0)=class'UTProj_RocketGrenade'
// Ammo
AmmoCount=5
MaxAmmoCount=10
// time between each fire
FireInterval(0)=+3.5
bSniping=false
// Alt fire max loaded up count, defaults
MaxLoadCount=3
SpreadDist=100
Weapons, RocketGrenade
// Zoom on RMB, 0 in array is LMB, 1 is RMB bZoomedFireMode(1)=1
ZoomedTargetFOV=60.0
ZoomedRate=150.0
ZoomFadeTime=.5
// Adjust muzzle flash
MuzzleFlashSocket=MuzzleFlashSocketA
MuzzleFlashSocketList(0)=MuzzleFlashSocketA
MuzzleFlashSocketList(1)=MuzzleFlashSocketC
MuzzleFlashSocketList(2)=MuzzleFlashSocketB
// Created this particle effect and it is in MyPackage
MuzzleFlashPSCTemplate=MyPackage.Effects.P_WP_RockerLau
ncher_Muzzle_Flash_NEW
Weapons, RocketGrenade
}
//MuzzleFlashPSCTemplate=WP_RocketLauncher.Effects.P_WP_RockerLaun
cher_Muzzle_Flash_NEW
MuzzleFlashDuration=0.08
MuzzleFlashLightClass=class'UTGame.UTRocketMuzzleFlashLight'
CrosshairImage=Texture2D'MyPackage.rgbtes3t'
CrossHairCoordinates=(U=0,V=0,UL=128,VL=128)
// Lock on abilities
ConsoleLockAim=0.992
LockRange=1
LockAim=0.997
LockChecktime=0.1
LockAcquireTime=1.1
LockTolerance=0.2
Weapons, RocketGrenade
• One thing you’ll notice is an easy way to adjust crosshairs.
• Set the image to an image in a package you have in the editor and set the coordinates on that image page.
CrosshairImage=Texture2D'MyPackage.rgbtes3t'
CrossHairCoordinates=(U=0,V=0,UL=128,VL=128)
Weapons, RocketGrenade
Weapons, RocketGrenade
• So in the map I’d put both weapon spawn on top of one another
• when the user picks up the 1 weapon they’re picking up both.
Weapons, RocketGrenade
• Another thing we’ll adjust is how we can call these weapons when we have them.
• So this is where my Battlefield 3 influences come in.
• When we press the ‘F’ key we go to the primary rifle and the ‘G’ key will take us to the grenade.
• This will be solved with setting
InventoryGroups.
Weapons, RocketGrenade
• This is where the item sits within inventory.
• We can call these inventory items with the number buttons (0-9) and we’ll adjust it to go off of F and G.
• There are four lines we’ll have to implement.
– In UTWeap_PlasmaRocketLauncher Default Properties
• InventoryGroup=2
– In UTWeap_RocketGrenade Default Properties
• InventoryGroup=3
Weapons, RocketGrenade
– The last thing will be in a config file where we can map keys on the keyboard to certain actions
• In DefaultInput.ini
– ;.Bindings=(Name="G",Command="GBA_SwitchToBestWea pon") commented out
– .Bindings=(Name="G",Command="GBA_SwitchWeapon3")
– ;.Bindings=(Name="F",Command="GBA_FeignDeath") commented out
– .Bindings=(Name="F",Command="GBA_SwitchWeapon2")
• And there you have it!
• Two awesome custom weapons with zooming and custom keys!
Weapons
• To start from scratch understand that a
Weapon is an Actor.
• So something that can be manipulated and used in the game and you place it in the players inventory.
– class Weapon extends Inventory
Weapons
• I would recommend if you are going to make a custom weapon or inventory item to go through the Weapon class.
• You’ll see how the item is equipped, used (fire events), and disposed of.