My program doesn't have bugs. It just develops random features.

UE2:ReloadableWeaponBase

From Unreal Wiki, The Unreal Engine Documentation Site
Jump to: navigation, search

Introduction[edit]

This is a very rough version of a reloadable weapon base class. It is not designed with replication (and thus online play) in mind and it is currently unknown whether it will work properly in an online modification as is. If you need reloadable weapons for a single player modification, then this could be what you're looking for. Again, it is merely a skeleton and has no animation support and will only work with the primary fire mode (FireMode[0]). To use this class, you will need to not only create it/compile it, but you will need to make a sub-class of it, where your sub-class is the actual weapon you will use in-game.

Properties[edit]

Visible[edit]

bool bReloading 
True if the weapon has started reloading
int iReloadWait 
Time interval between reloading a bullet. Set only in your sub-class.
int iTimeToReload 
Set internally. Do not play around with it.
bool bClipReload 
Will force the weapon's reloading to behave more like an assault rifle, rather than a shot gun (per clips versus per bullet/shell).
int iNumberOfClips 
Number of clips the weapon has. Used only if bClipReload is true. Set only in your sub-class.
bool bSingleReload 
Will force the weapon's reloading to behave more like a shotgun and reload per bullet/shell.
int iNumberOfBullets 
Number of bullets the weapon has. Set only in your sub-class.

Methods[edit]

(exec) ReloadMe() 
Reloads the weapons ammo.
Timer() 
Controls the reloading system.

Source Code[edit]

UE2 Weapon >> ReloadableWeaponsBase (custom)
class ReloadableWeaponsBase extends Weapon;
 
/* Note: The Reloading features of this custom class will only affect FireMode(0) or Primary Fire
   As most weapons will only have one fire that will use ammo */
   //TODO:  ADD DISABLING OF THE ABILITY TO FIRE WHEN RELOADING
   //TODO:  ADD ANIMATION SUPPORT
   //TODO:  ADD SUPPORT BOOLS FOR MORE FIREMODES
 
//New Reloadable Weapon System
 
//Basic Reload Vars
var bool bReloading; //True if the weapon has commenced reloading
var int iReloadWait; //How much time to wait before each reload is done? SET THIS ONLY IN YOUR CUSTOM WEAPON CLASS
var int iTimeToReload; //Internally Set... IGNORE
 
//Clips Reload Vars
var bool bClipReload; //Set to true in weapon class if you want the gun to reload like an assault rifle
var int iNumberOfClips; //How many clips does this gun have? SET IN WEAPON CLASS
 
//Single Reload Vars
var bool bSingleReload; //Set to true in weapon class if you want the gun to reload like a shotgun
var int iNumberOfBullets; //How many bullets does this gun have left? SET IN WEAPON CLASS
 
exec function ReloadMe()
{
     iTimeToReload=iReloadWait; //reset the amount of time to wait before you have completely reloaded
     bReloading=True; //reloading has commenced
     SetTimer(1.0, True);
}
 
function Timer()
{
       Super.Timer();
 
       if(bClipReload)
       {
             if(bReloading) //Reloading
             {
                if(iTimeToReload != 0)
                iTimeToReload--;  //decrement the wait time
 
                if(iTimeToReload == 0) //when iTimeToReload is 0, reload the weapon as long as...
                {
                      if(iNumberOfClips != 0) //You still have clips left
                      {
                           if ( AmmoClass[0] != None )
			        AmmoCharge[0] = MaxAmmo(0); //max out the ammo of your primary fire
 
                           iNumberOfClips--; //Decrement the number of clips we have as we used one up!
                      }
                      bReloading=False; //No longer reloading
                }
             }
       }
       if(bSingleReload)
       {           
            if(bReloading) //Reloading
            {
                         if(iTimeToReload != 0)
                         iTimeToReload--;  //decrement time to reload
                         if(iTimeToReload == 0) //if time to reload is 0 (you don't have to wait anymore)
                         {
                            if(iNumberOfBullets != 0) //and if you still have bullets left
                            {
                              AddAmmo(1,0);   //give gun 1 ammo and...
                              iNumberOfBullets--; //take away one bullet from the belt
                            }
                          }
 
                          if(AmmoMaxed(0)) //if you can't put anymore more bullets in... stop reloading
                          {
                                iTimeToReload = iReloadWait;
                                bReloading=False;
                          }
            }
       }
}

Notes[edit]

To reload your weapon, you will have to call 'reloadme' from the console. For gametypes and mods, you should make a custom bind to call this function.