| Home Page | Recent Changes | Preferences

Creating A New Weapontype

I just started with coding but I am missing some practical examples. So I put here what I found out so far together with the code.

I assume that you have installed the SDK files or exported the codefiles from UnrealEd. In that case you see various directories like "XWeapons" etc. in your unreal directory – see Setting Up UnrealScript for instructions.

Getting Started

For learning Unreal, I started a new Package called TestPak.

I created the TestPak.int file in that folder which contains:

 [Public]
 Object=(Name=TestPak,Class=Class,MetaClass=Engine.Weapon)

Don't forget to add it to the ut2003.ini file:

EditPackages=TestPak

(below the other EditPackages lines)

Create a subfolder to the TestPak directory called classes

That's now your point to start from.

For the beginning I copied the AssaultRifleWeapon? and the codefiles belonging to that weapon for later modification. You can start that way too. If you want to rename the Weapon classes, you have to rename the files but also the file's content. Example:

 copy c:\ut2003\XWeapons\Classes\AssaultRifle.uc c:\ut2003\testpak\classes\TestWeapon.uc

open the file and change

 class AssaultRifle extends Weapon
    config(user);

to:

 class TestWeapon extends Weapon
    config(user);

If you have renamed all the files you want to modify (I copied, renamed and modified the files: Grenade.uc to TestGrenade.uc, GrenadeAmmo.uc to TestGrenadeAmmo.uc, AssaultRifle.uc to TestWeapon.uc, AssaultAmmoPickup.uc to TestWeaponAmmoPickup.uc, AssaultAttachment.uc to TestWeaponAttachment.uc, AssaultFire.uc to TestWeaponFire.uc, AssaultGrenade.uc to TestWeaponGrenade.uc, AssaultRiflePickup.uc to TestWeaponPickup.uc) You can start making minor corrections in the files. Before doing that you can run ucc make all, testing if your copying process was successfull. If not, you have done something wrong or I described it badly - in that case you are welcome to modify this page ;).

Well ok - if you start a testlevel (with cheatings enabled) you can put in the console: summon testpak.testweaponpickup and the weapon will appear right in front of you. If not, check if the testpak.u file is present in the system directory.

You will find out that it is still the normal AssaultRifle gun. And it is still shooting the same way etc. So stop playing around and modify the files further. Open TestWeapon.uc. Jump to the last lines where the defaultproperties are written.

Watch out for lines like that now:

 PickupClass=class'AssaultRiflePickup'

These lines are still pointing to the "old" classes that you want to overwrite!

So change the lines this way:

 PickupClass=Class'TestPak.TestWeaponPickup'

You will have to do this in all the files that you copied!

Change the

 ItemName="Assault Rifle"

to something else like "supergun" or so...

Watch out for errors and test it inbetween by compiling and testing! It is hard to find errors if you made lots of "heavy" changes. Don't forget to delete testpak.u before compiling your code!

If you rerun a level and summon your weapon, it should tell you that you collected the "supergun" - or whatever you named it. But there are lot's of further changes to be made.

I won't describe every line that I have changed because if you are clever, you will see the property values yourself that are important while changing the class names. Lines like

 InventoryGroup=2

should make you curious for changing (this value will move the weapon to another slot in your inventory and can be changed easily).

So, you can easily make now minor changes yourself: How much ammo it has, how fast it shoots and so on. As I started up by zero I spend a lot of time on figuring out how the new gun behaves on the changes. I guess you should do the same.

Tests like: How fast can I shoot are always funny ;) - especially if you need only one second to fire 300 projectiles on your enemy :D

A little more tuning

Still not satisfied? Well I wasn't too, - I wanted to create a bow. I am unable to create my own animation stuff since I have no conversion tool for 3D meshes, but I created an Staticmesh arrow that will be shot when triggering the grenade. This is easily be done in the defaultproperties of the TestGrenade.uc file:

 StaticMesh=StaticMesh'YourStaticMeshPackage.YourGrenade'

Now I was able to shoot arrows - that exploded and flew strange (rotating and so on). ...

So I made some changes on the functions that let the grenade explode - I deleted the functions that made the thing blowing up. Get rid of the randomspin-values, too. Also, I wanted to make the arrow stick:

var bool bLanded; // put this in the beginning of the file

simulated function Landed( vector HitNormal ) {
    HitWall(HitNormal,None);
}

simulated function HitWall(vector HitNormal, actor HitWall) {
    bLanded=true;
    Velocity=0*Velocity;
    SetPhysics(PHYS_None);
}

Now, the arrow will stick wherever it lands (except for the players it is hitting).

But you will see that the arrow is not flying realy... A simple function will fix it:

simulated function Tick( float DeltaTime ) {
   if (!bLanded) SetRotation(rotator(velocity));
}

Tick is called every moment in Unreal, so I guess this is the dirty way how to implement it, but I also think it does not matter so much when testing. Has anyone a better Idea?

At least the arrow is flying nice through the air and sticks where it lands in the right direction!

Now - I wanted to make it stick in the body of the enemy of course *hehehe*.

So I modified the ProcessTouch function:

simulated function ProcessTouch( actor Other, vector HitLocation )
{
    local float dist;
    local Name bone; //which bone it should be attached
    local Vector X;
    local class<DamageType> dmg;

    dmg=class'XWeapons.DamTypeShieldImpact';
    if ( Pawn(Other) != None && (Other != Instigator || bCanHitOwner) && (!bLanded))
    {
    bLanded=True;
    X=Normal(Velocity+vect(0,0,0.5));
    SetPhysics(PHYS_None);
    bone=Other.GetClosestBone(HitLocation,Velocity,dist);
    Other.TakeDamage(0, Instigator, HitLocation, 60000*(X), None); // just push the other player back
    Other.AttachToBone(Self,bone);

        Velocity=0*Velocity;
    }
}

So this is not much - but I needed some time to find out how all that works with together with a friend. And it is still not sticking the way in the enemy that how I like it to do...

Final words

I am not a professional in describing things. And I am not sure if I mentioned all the important stuff. If you think there is a bug, feel free to correct it. Add some lines if you are encountering problems, too.

This all took me about 8 hours to get run. Much work, I hope you won't need so long with this little help. By the way- if Unrealed doesn't show your package - load it manually.

Related Topics

Discussion

RegularX: Looks pretty good - added a link to this from the Weapon Mutator from the tute series.

Foxpaw: Some of the stuff at the beginning overlaps with the setting up your pacakge stuff. Or something. I don't know the actual link. Anyways, it could probrably get a Refactor Me.

Kentyman: At the top of this page you create your own weapon folder structure and script files by copy/pasting existing script files. This sort of clashes with the idea of Object Orientated Programming where you simply extend existing classes and modify them as you see fit (instead of first replicating all the code and then changing it)

Neo Reloaded: Is it possible to create weapons in UnrealEd?

Wormbo: If you mean weapon models, that's a clear no. If you mean the code behind them – well, let's put it this way: Don't try it. Any text editor is better for that. ;)

Beansdeath: Wondering- once a new weapon is made, bow&arrow, or what have you, how do you go about changing the weap. icon on the HUD to show a new weap. icon, say a little bow&arrow, so you arent holding a bow and have a assault rife icon? would be a good bit to add here.


Category Tutorial

The Unreal Engine Documentation Site

Wiki Community

Topic Categories

Image Uploads

Random Page

Recent Changes

Offline Wiki

Unreal Engine

Console Commands

Terminology

FAQs

Help Desk

Mapping Topics

Mapping Lessons

UnrealEd Interface

UnrealScript Topics

UnrealScript Lessons

Making Mods

Class Tree

Modeling Topics

Chongqing Page

Log In