| Home Page | Recent Changes | Preferences

TheHealer/TUTHealer

TUTHealer - The Healer Part 1 of 9

In this part of the Healer tutorial, we will set up our main weapon class. Before we get into the code, make sure that your file is set up correctly.

Filename: {Base Directory}/TheHealer/classes/TUTHealer.uc

If you've changed the name of the package folder or the filename itself, make sure you make those changes throughout the code we'll be working with.

Quick Link: This is the complete source code for people who want to skip ahead. If you want to copy/paste into your file, this is the page to do it on.

Heading and Class Declaration

In order to keep our code reader-friendly (always a good thing if you need someone's help!), we will add a standard comment block to the top of the file. This will describe what's going on in the file.

After the comment block, we declare the class. Make sure you name the class with the same name as the filename, or bad things happen.

//------------------------------------------------------------------------------
// class name : TUTHealer
// class type : base
// description: the Tutorial Healer weapon
// author     : HSDanClark
//------------------------------------------------------------------------------
// TODO       : the TODO field is useful when you want to notate things you
//              think of and don't want to forget before you can get to them.
// 1. Add more comments.
// 2. Other stuff you can think of...
//------------------------------------------------------------------------------
class TUTHealer extends Weapon
    config(TUTUser);

Notice that our Healer is extending Weapon:

UT2003 :: Actor >> Inventory >> Weapon >> TUTHealer

Also, notice that we will be using a custom config file, which we will set up in [Part 9]?.

Exec Directives and Variable Declarations

#EXEC OBJ LOAD FILE=InterfaceContent.utx

var(FirstPerson) float NewEffectOffset;

Here we load our texture package via an EXEC directive. This texture package contains the icon you see in the bottom right corner of the HUD when you have the weapon selected.

We only need one variable with class scope, you'll see what it's used for in a little bit. Notice the (FirstPerson) part – this allows us to modify the value of this variable from within UnrealEd, and the "FirstPerson" within the parentheses means that it will fall under the "FirstPerson" group in the Actor Properties Window.

Functions

simulated function vector GetEffectStart()
{
    local Vector X,Y,Z;

    if ( Instigator.IsFirstPerson() && (Hand == 0) )
    {
        GetViewAxes(X, Y, Z);
        if ( class'PlayerController'.Default.bSmallWeapons || Level.bClassicView )
            return (Instigator.Location +
                Instigator.CalcDrawOffset(self) +
                SmallEffectOffset.X * X  +
                SmallEffectOffset.Y * Y * Hand -
                NewEffectOffset * Z);
        else
            return (Instigator.Location +
                Instigator.CalcDrawOffset(self) +
                EffectOffset.X * X +
                EffectOffset.Y * Y * Hand +
                EffectOffset.Z * Z);
    }
    return Super.GetEffectStart();
}
simulated function Destroyed()
{
    Super.Destroyed();
}

simulated function bool StartFire(int Mode)
{
    return Super.StartFire(Mode);
}

These two functions call their counterparts from their parent class by way of the Super keyword.

// AI Interface
// ::TODO:: write the AI Interface!!!
// End AI Interface

Normally, this is where the AI interface would appear. Writing a proper AI interface is beyond the scope of this tutorial. We cannot use the AI interface as it was written for the Link Gun because there are too many changes to the functionality of the weapon for it to be useful.

Also, notice the ::TODO:: notation. This is very useful when coding, as you can easily mark a section that you need to come back to later – simply do a search for // ::TODO:: in your editor.

function ConsumeAmmo(int mode, float load)
{
    Ammo[mode].UseAmmo(1);
}

Here we have the weapon using up ammo, depending on what firemode the weapon is in. This isn't especially useful for us since we only have one type of ammo for both our beams, but for many weapons with very different firemodes, this is crucial.

simulated function IncrementFlashCount(int mode)
{
    Super.IncrementFlashCount(mode);
}

simulated function bool PutDown()
{
    return Super.PutDown();
}

simulated function BringUp(optional Weapon PrevWeapon)
{
    Super.BringUp(PrevWeapon);
}

These three functions call their counterparts from the Healer's parent class (Weapon).

Default Properties

defaultproperties
{
    bMatchWeapons=true
    ItemName="Tutorial Healer Gun"
    IconMaterial=Material'InterfaceContent.Hud.SkinA'
    IconCoords=(X1=200,Y1=190,X2=321,Y2=280)

    FireModeClass(0)=TUTHealerFire       // heal beam
    FireModeClass(1)=TUTHealerAltFire    // damage beam
    InventoryGroup=5
    DrawScale=1.0
    Mesh=mesh'Weapons.LinkGun_1st'
    BobDamping=1.575000
    PickupClass=class'TUTHealerPickup'
    EffectOffset=(X=100,Y=25,Z=-3)
    IdleAnimRate=0.03
    PutDownAnim=PutDown
    DisplayFOV=60

    PlayerViewOffset=(X=-2,Y=-2,Z=-3)
    SmallViewOffset=(X=10,Y=4,Z=-9)
    PlayerViewPivot=(Pitch=0,Roll=0,Yaw=500)
    UV2Texture=Material'XGameShaders.WeaponEnvShader'

    AttachmentClass=class'TUTHealerAttachment'
    SelectSound=Sound'WeaponSounds.LinkGun.SwitchToLinkGun'
    SelectForce="SwitchToTUTHealer"

    AIRating=+0.68
    CurrentRating=+0.68

    HudColor=(r=128,g=255,b=128,a=255)
    DefaultPriority=5

    CenteredOffsetY=-12.0
    CenteredYaw=-300
    CenteredRoll=3000
    NewEffectOffset=5.0
}

I will not go into great detail about each property, but will hit some of the more important ones.

  • IconMaterial – this is where we use the icon that we loaded via the EXEC directive at the top of the file.
  • InventoryGroup – this is the slot that the weapon will use in your inventory. Here, it's in slot 5, same as the Link Gun. You will still be able to pick up and use the Link Gun, just scroll twice through slot 5, or press the hotkey you have assigned to slot 5 twice.
  • PickupClass – this links our weapon to the pickup class so you can see it on the ground.
  • Notice that we are using the Link Gun resources for our Mesh and SelectSound

The Next Step

Continue to Part 2, TheHealer/TUTHealerPickup

The complete tutorial map:

  1. /TUTHealer – Our main weapon class.
    1. Filename: {Base Directory}/TheHealer/classes/TUTHealer.uc
  2. /TUTHealerPickup – Our weapon's pickup class, what you see on the ground.
    1. Filename: {Base Directory}/TheHealer/classes/TUTHealerPickup.uc
  3. /TUTHealerAmmo – Our weapon's ammo class.
    1. Filename: {Base Directory}/TheHealer/classes/TUTHealerAmmo.uc
  4. /TUTHealerAmmoPickup – The ammo's pickup class, what you see on the ground.
    1. Filename: {Base Directory}/TheHealer/classes/TUTHealerAmmoPickup.uc
  5. /TUTHealerFire – Our weapon's primary fire class.
    1. Filename: {Base Directory}/TheHealer/classes/TUTHealerFire.uc
  6. /TUTHealerAltFire – Our weapon's alternate (secondary) fire class.
    1. Filename: {Base Directory}/TheHealer/classes/TUTHealerAltFire.uc
  7. /TUTHealerBeamEffect? – The Healer's Beam Effect
    1. Filename: {Base Directory}/TheHealer/classes/TUTHealerBeamEffect.uc
  8. /TUTHealerAttachment? – Our weapon's attachment class.
    1. Filename: {Base Directory}/TheHealer/classes/TUTHealerAttachment.uc
  9. [/TUT The End]? – Putting it all together.

Discussion

The Unreal Engine Documentation Site

Wiki Community

Topic Categories

Image Uploads

Random Page

Recent Changes

Offline Wiki

Unreal Engine

Console Commands

Terminology

Mapping Topics

Mapping Lessons

UnrealEd Interface

Questions&Answers

Scripting Topics

Scripting Lessons

Making Mods

Class Tree

Questions&Answers

Modeling Topics

Questions&Answers

Log In