| Home Page | Recent Changes

Mod Ideas/InfiniteAmmoCombo

Infinite Ammo Combo

The Idea

I am trying to make an adrenaline combo for the rapidly dying UT2003. When activated, it will either return any ammo used instantly or stop ammo from being used in firing.

I have tried some thing out but I can't get it to work:

class InfinAmmoCombo extends Combo;

var xEmitter Effect;
var xEmitter Effect2;
var Ammunition LastAmmo;


function StartEffect(xPawn P)
{
    if (P.Role == ROLE_Authority)
    {
        Effect = Spawn(class'OffensiveEffect', P,, P.Location, P.Rotation);
        Effect2 = Spawn(class'RegenCrosses', P,, P.Location, P.Rotation);
    }
    LastAmmo = Pawn(Owner).Weapon.Ammo[0];
//    AmmoHeal(P);
    SetTimer(0.01, true);
    Timer();
}


//function AmmoHeal(xPawn P)
function Timer()
{
    local Inventory Inv;

    if (Pawn(Owner).Role == ROLE_Authority)
    {
        if( inv.IsA('Weapon') && (!inv.IsA('TransLauncher')) && (!inv.IsA('ShieldGun')) && (!inv.IsA('ShieldGun')) && (!inv.IsA('ShieldGun')) )
        {
            if (LastAmmo != Pawn(Owner).Weapon.Ammo[0])
            {
               Pawn(Owner).Weapon.Ammo[0] = LastAmmo;
               Log("Ammo is good");
            }
           LastAmmo = Pawn(Owner).Inventory.Ammo[0];
        }
    }
}

function StopEffect(xPawn P)
{
    if ( Effect != None )
        Effect.Destroy();
}

defaultproperties
{
    ExecMessage="Infinite Ammo! Go Berserk!!"
    ComboAnnouncement=sound'AnnouncerMain.Berzerk'
    keys(0)=1
    keys(1)=1
    keys(2)=2
    keys(3)=2
}

The Problem

I'm not too good with UnrealScript and would like some advice on this matter. I have tried looking at mods and mutators which regenerate ammo but they work on all ammo. I just want it on the current weapon. If it does compile, nothing happens. Any ideas?

Comments

T1: First of all, could you provide some of the errors UCC gives you? And why do you check the shieldgun thrice? And Maybe a Shieldgun(Inv) != none would be faster (not sure about this, some of the other wiki people would have to confirm this).

Oh wait, I think I just found your problem. Inv isn't being given any values. You have to say somewhere Inv=Pawn(Owner).Inventory; or something like that. I'll go check in the wiki.

ShadowRaven: I got rid of the multiple Shield Gun calls, I was going to replace them with redeemer and ion painer ammo after I got the ammo system working itself. Common errors are (aside from syntax) Unrecognized member "Ammo" in "Inventory and Unrecognized member "AmmoAmount" in Weapon" (AmmoAmount worked in the StartEffect function, variable scope is stoppping me from using it in Timer().

I know Ammo[0] isn't it as the array indicates number of fire modes.

I'm thinking to have to call each weapon seperately however that loses the mod compatability.

porkmanii: Ammunition objects (as in Weapon.Ammo[]) store the amount of ammo, and usually don't change throughout the lifetime of a weapon. I'm not sure about UT2003, but in UT2004 Ammunition generally isn't used. Weapons have a property called "bNoAmmoInstances" which, if true (the default value), disables Ammunition and uses AmmoCharge (var int AmmoCharge[2]) instead. If you want the amount of ammo to remain constant, you may have to record the value returned by Weapon.AmmoAmount(mode), and add back some amount to keep it at that level every time it changes.

One other problem I can see is that if the player changes weapons, your code assigns the Ammunition from the previous weapon. If you implement this as an Inventory item, you could detect when the player changes weapons - an OwnerEvent() call where EventName == 'ChangedWeapon'. Alternatively you could watch the weapon's ammo class, resetting the "LastAmmo" every time the class changes. This would also allow compatibility with weapons with multiple ammo types, like ChaosUT's Crossbow.

Pawn.Inventory refers to the first Inventory item in the Pawn's inventory chain. Even if Ammo[] was declared in Inventory and not Weapon, why would you want to use Pawn.Inventory's Ammo[] property?

Mad: I managed to get this combo working the way you intended to, where the current weapon the player is holding is the only weapon with infinite ammo. The problem is, I managed to get this working in UT2004, so I don't know of any differences within the code between 2003 and 2004.

The xPawn class has access to the current weapon being used by calling xPawn.Weapon. Within the weapon class contains an array of WeaponFire classes called FireModeClasses. The WeaponFire classes handle the amount of ammo being used for a particular weapon. Use the function GetFireMode to obtain access to the specific Weapon's WeaponFire and adjust the AmmoPerFire accordingly. Here is the code that I used to make this work.

class ComboUnlimitedAmmo extends Combo;

var int nAmmoPerFireOne;         //For primary ammo
var int nAmmoPerFireTwo;         //For seondary ammo

/*
This function will get called when right combination is entered.
*/
function StartEffect(xPawn P)
{
     nAmmoPerFireOne = P.Weapon.GetFireMode(0).AmmoPerFire;
     nAmmoPerFireTwo = P.Weapon.GetFireMode(1).AmmoPerFire;
     P.Weapon.GetFireMode(0).AmmoPerFire = 0;
     P.Weapon.GetFireMode(1).AmmoPerFire = 0;
}


/*
This function gets called when adrenaline is all gone.
*/
function StopEffect(xPawn P)
{
     P.Weapon.GetFireMode(0).AmmoPerFire = nAmmoPerFireOne;
     P.Weapon.GetFireMode(1).AmmoPerFire = nAmmoPerFireTwo;
}

defaultproperties
{
     nAmmoPerFireOne = 1;
     nAmmoPerFireTwo = 1;
     Duration = 20;
     ExecMessage = "Unlimited Ammo!"
     keys[0] = 4;//CK_LEFT;
     keys[1] = 8;//CK_RIGHT;
     keys[2] = 4;//CK_LEFT;
     keys[3] = 8;//CK_RIGHT;
}

The problem with the code is, once the combo is initiated, the current gun the player is holding will only have unlimited ammo. Also, the ammo count will decrement by one before going to "infinite" mode. These are both an easy fix, and I will update the code once I figure out how. I hope this helps anyone out.

Eliot: ForEach maybe can fix this i havent tested it though :p, anyway this will work for everybody ingame:/ anyway its good for a mutator then.

function StartEffect(xPawn P)
{
    local Weapon W;

    ForEach DynamicActors( Class'Weapon', W )
    {
      //nAmmoPerFireOne = W.GetFireMode(0).AmmoPerFire;
      //nAmmoPerFireTwo = W.GetFireMode(1).AmmoPerFire;
        W.GetFireMode(0).AmmoPerFire = 0;
        W.GetFireMode(1).AmmoPerFire = 0;
    }
}

function StopEffect(xPawn P)
{
    local Weapon W;

    ForEach DynamicActors( Class'Weapon', W )
    {
        W.GetFireMode(0).AmmoPerFire = W.GetFireMode(0).Default.AmmoPerFire;
        W.GetFireMode(1).AmmoPerFire = W.GetFireMode(1).Default.AmmoPerFire;
    }
}

defaultproperties
{
    Duration = 20;
    ExecMessage = "Unlimited Ammo!"
    keys[0] = 4;//CK_LEFT;
    keys[1] = 8;//CK_RIGHT;
    keys[2] = 4;//CK_LEFT;
    keys[3] = 8;//CK_RIGHT;
}

Category Custom Class

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