| Home Page | Recent Changes

Stat Points System

This tutorial is for creating a stat-based system in which to modify UT2003 (Like UT2003RPG).

For now we will be working with the firing rate of the minigun. If you have not already done so, you will have to obtain the Unrealscript sources for UT2003. You will also need to Set Up Package Folders for this mod. Once you have done that, copy MinigunFire.uc from XWeapons to the folder you just created for this mod.

 

You need to change the name first: (so you don't overwrite anything)

class SPSMinigunFire extends InstantFire

After that you should see a line that looks something like this:

simulated function PostBeginPlay()
{
    Super.PostBeginPlay();
    FireRate = 1.f / (RoundsPerRotation * BarrelRotationsPerSec);
    MaxRollSpeed = 65536.f*BarrelRotationsPerSec;
    Gun = Minigun(Owner);
}

In order to use the variable we want, we will have to add it to the variable definitions at the top of the page. The variable Definitions look like this:

var() float MaxRollSpeed;
var() float RollSpeed;
var() float BarrelRotationsPerSec;
var() int   RoundsPerRotation;
var() float FireTime;
var() Sound WindingSound;
var() Sound FiringSound;
var MiniGun Gun;
var() float WindUpTime;

var() String FiringForce;
var() String WindingForce;
 

This declares the variables used. (Yeah, we probably know this – skip this step and give a link to the variable syntax page instead)

We will be adding a line to it that looks like this

var() float StatPoints

After that you will need to set up a system for determining stat points. I'll cover that here: /StatPointDetermination?

Anyway, add this line to under PostBeginPlay

function ModeTick(float dt)
{
    if (StatPoints > 0)
    {        
        NewFireRate = FireRate + (StatPoints / 5);
    }
    else {
        FireRate = 1.f / (RoundsPerRotation * BarrelRotationsPerSec);
    }
}

The final code should look like this:

simulated function PostBeginPlay()
{
    Super.PostBeginPlay();
    FireRate = 1.f / (RoundsPerRotation * BarrelRotationsPerSec);
    MaxRollSpeed = 65536.f*BarrelRotationsPerSec;
    Gun = Minigun(Owner);
}

function ModeTick(float dt)
{
          if (StatPoints > 0)
          {        
                NewFireRate = FireRate + (StatPoints / 5);
          else
                FireRate = 1.f / (RoundsPerRotation * BarrelRotationsPerSec);
          }
}

That should do it! I'm not completely sure on the uscript format, but here is it in easy to understand format:

 If the variable StatPoints is greater than 0, then the firing rate is the old fire rate + the value of the variable 
 StatPoints divided by 5.  If it is not above zero, then the firing rate is rounds per rotation * barrel rotations 
 per sec, ie. normal firing rate.

Hope I got this right!

Comments

RDGDanClark: I didn't check the code itself, I just noticed that you had !>, which is invalid. The way to write "not greater than" is "less than or equal to", which is <=. For example "Negative two is not greater than zero" is the same as "Negative two is less than (or equal to) zero".

Dragonmaw: Thanks. I meant it to be greater than 0, but I pressed a wrong key.

Solid Snake: Good tutorial. I don't know what the replication will be like on the network since adjusting those values is client side? I'll have to have a look into that a little later. Also you may want to tell people that they will also have to subclass a weapon and change the fireclass to this one (I'll bet you will get a question in how to use this script...).

Random Guest: I don't know if this will work.. You assign a value to NewFireRate, without doing anything with it then. How? And can you please continue with /StatPointDetermination?? Thanks for making what you have already though.

dataangel: Does this need any netcode?

Solid Snake: Yes it does because only the minigun will be affected by this type of change. Ideally you want a global stat system in place so that all weapons will be affected by any changes. Lastly you want replication because these are important values. You don't really want cheating with a stat system like this.

lizardman6: Will these pages of code also work with UT2004?

DaWrecka:

"Once you have done that, copy MinigunFire.uc from XWeapons to the folder you just created for this mod."

What? No! Bad! Very very bad! Copying entire source files in their entirety is a very, very, VERY bad habit to get into, as not only does it completely defeat the object of object orientation, but you will have to re-copy and re-edit the entire thing to accomodate any bugfixes in the base code.

An infinitely better solution is to create a class which is declared as:

class SPSMinigunFire extends MinigunFire;

This way it already incorporates all of the code contained in the base MinigunFire. Then you merely edit functions to suit.

Inheritance is your friend, not your enemy.

The only time you should ever duplicate entire classes is when you want to have them as children of a new base class with custom functions. (For example, you might have a WeaponFire subclass which adds functions for selecting targets automatically and rendering of a crosshair, among other things.)

While I'm not trying to be unkind here, I'd say if you don't have a good understanding of OOP and inheritance, you still don't have a basic understanding of UnrealScript and shouldn't be attempting a project like this until you do. I'd recommend reading and thoroughly understanding the UnrealScript Lessons, and in particular Object Oriented Programming Overview and Unreal Object Oriented Programming.

Related Topics

/Ammo Modifier:Your next suggested step, this explains how to modify ammo capacity using a stat-based system

UnrealScript Lessons

Category Custom Class

Category Tutorial

The Unreal Engine Documentation Site

Wiki Community

Topic Categories

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