• Please make sure you are familiar with the forum rules. You can find them here: https://forums.tripwireinteractive.com/index.php?threads/forum-rules.2334636/

Code Custom Ammo Regeneration

Snebbers

Member
Jul 27, 2011
23
0
I have been asked by a fellow forum user to create a mutator for their custom server which regenerates ammo over time instant of purely having infinite ammo, to stifle the exploitation of various weapons that have high damage.

Using a very early GliderAmmo mutator as a base to butcher (Sorry about that :( the original is below).

Code:
class GliderAmmo extends Mutator;

event PreBeginPlay()
{
    SetTimer(1.0,true);
}
 
function Timer()
{
    local Controller C;
 
    for (C = Level.ControllerList; C != None; C = C.NextController)
    {
        ModifyPawn(C.Pawn);
    }
}

static simulated function ModifyPawn(Pawn pawn)
{
    GiveAmmo(pawn);
}

static function GiveAmmo(Pawn pawn)
{
    local KFHumanPawn human;
    Local Inventory Inv;

    human = KFHumanPawn(pawn);
    
    if (human != None)
    {
        for (Inv = human.Inventory; Inv != None; Inv = Inv.Inventory)
        {
            if (Inv != None)
            {
                if ( KFAmmunition(Inv) != None && (FragAmmo(Inv) == None) && (PipeBombAmmo(Inv) == None) && (KFAmmunition(Inv).AmmoAmount < KFAmmunition(Inv).MaxAmmo) )
                {
                  [COLOR=Red] KFAmmunition(Inv).AmmoAmount = KFAmmunition(Inv).MaxAmmo;[/COLOR]
                }
            }
        }
    }
}

defaultproperties
{
     GroupName="KF-GliderAmmo"
     FriendlyName="GliderAmmo"
     Description="Unlimited  ammunition"
}
I changed the line highlighted to

Code:
KFAmmunition(Inv).AmmoAmount = KFAmmunition(Inv).AmmoAmount + (KFAmmunition(Inv).MaxAmmo*0.01);
Which worked very nicely, and as I anticipated ammo started to regenerate at 1% of the players MaxAmmo per second, as instructed by the timer. Weapons with a max ammo less than 100 did not regenerate ammo as they seemed to be treated as 0, I'm not 100% sure but I could get around that with a float... I think.

I was then asked to make different categories of ammo regeneration based on the class of weapon used. Ammo regeneration ranging from 1% of MaxAmmo per 2 seconds for specifically assualt rifles to 1 bullet per 12 seconds for things like the law and M99.

I had the idea to make an ini and group weapons into categories (Although I am just making stabs in the dark, I'll be honest).

To try and segregate different timers into for different functions I thought maybe I could try and make different regeneration amounts in different functions. Which you can see here:
Code:
class SnebbersAmmoRegen extends Mutator;

event PreBeginPlay()
{
    SetTimer(1 ,true);
}

function Timer()
{
    local Controller C;
 
    for (C = Level.ControllerList; C != None; C = C.NextController)
    {
        ModifyPawn(C.Pawn);
    }
}

static simulated function ModifyPawn(Pawn pawn)
{
    AmmoRegen0(pawn);
    AmmoRegen1(pawn);
    AmmoRegen2(pawn);
    AmmoRegen3(pawn);
    AmmoRegen4(pawn);
    AmmoRegen5(pawn);
    AmmoRegen6(pawn);
}

static function AmmoRegen0(Pawn pawn)
{
    local KFHumanPawn human;
    Local Inventory Inv;

    human = KFHumanPawn(pawn);
    
    if (human != None)
    {
        for (Inv = human.Inventory; Inv != None; Inv = Inv.Inventory)
        {
            if (Inv != None)
            {
                if ( KFAmmunition(Inv) != None && (KFAmmunition(Inv).AmmoAmount < KFAmmunition(Inv).MaxAmmo) )
                {
                    
                   KFAmmunition(Inv).AmmoAmount = KFAmmunition(Inv).MaxAmmo;
                }
            }
        }
    }
}

static function AmmoRegen1(Pawn pawn)
{
    local KFHumanPawn human;
    Local Inventory Inv;

    human = KFHumanPawn(pawn);
    
    if (human != None)
    {
        for (Inv = human.Inventory; Inv != None; Inv = Inv.Inventory)
        {
            if (Inv != None)
            {
                if ( KFAmmunition(Inv) != None && (KFAmmunition(Inv).AmmoAmount < KFAmmunition(Inv).MaxAmmo) )
                {
                    
                    KFAmmunition(Inv).AmmoAmount = KFAmmunition(Inv).AmmoAmount + (KFAmmunition(Inv).MaxAmmo*0.01);
                }
            }
        }
    }
}

static function AmmoRegen2(Pawn pawn)
{
    local KFHumanPawn human;
    Local Inventory Inv;

    human = KFHumanPawn(pawn);
    
    if (human != None)
    {
        for (Inv = human.Inventory; Inv != None; Inv = Inv.Inventory)
        {
            if (Inv != None)
            {
                if ( KFAmmunition(Inv) != None && (KFAmmunition(Inv).AmmoAmount < KFAmmunition(Inv).MaxAmmo) )
                {
                    
                   KFAmmunition(Inv).AmmoAmount = KFAmmunition(Inv).AmmoAmount + 1;
                }
            }
        }
    }
}

static function AmmoRegen3(Pawn pawn)
{
    local KFHumanPawn human;
    Local Inventory Inv;

    human = KFHumanPawn(pawn);
    
    if (human != None)
    {
        for (Inv = human.Inventory; Inv != None; Inv = Inv.Inventory)
        {
            if (Inv != None)
            {
                if ( KFAmmunition(Inv) != None && (KFAmmunition(Inv).AmmoAmount < KFAmmunition(Inv).MaxAmmo) )
                {
                    
                   KFAmmunition(Inv).AmmoAmount = KFAmmunition(Inv).AmmoAmount + KFWeapon(Inv).MagCapacity;
                }
            }
        }
    }
}

static function AmmoRegen4(Pawn pawn)
{
    local KFHumanPawn human;
    Local Inventory Inv;

    human = KFHumanPawn(pawn);
    
    if (human != None)
    {
        for (Inv = human.Inventory; Inv != None; Inv = Inv.Inventory)
        {
            if (Inv != None)
            {
                if ( KFAmmunition(Inv) != None && (KFAmmunition(Inv).AmmoAmount < KFAmmunition(Inv).MaxAmmo) )
                {
                    
                   KFAmmunition(Inv).AmmoAmount = KFAmmunition(Inv).AmmoAmount + 1;
                }
            }
        }
    }
}

static function AmmoRegen5(Pawn pawn)
{
    local KFHumanPawn human;
    Local Inventory Inv;

    human = KFHumanPawn(pawn);
    
    if (human != None)
    {
        for (Inv = human.Inventory; Inv != None; Inv = Inv.Inventory)
        {
            if (Inv != None)
            {
                if ( KFAmmunition(Inv) != None && (KFAmmunition(Inv).AmmoAmount < KFAmmunition(Inv).MaxAmmo) )
                {
                    
                   KFAmmunition(Inv).AmmoAmount = KFAmmunition(Inv).AmmoAmount + 2;
                }
            }
        }
    }
}

static function AmmoRegen6(Pawn pawn)
{
    local KFHumanPawn human;
    Local Inventory Inv;

    human = KFHumanPawn(pawn);
    
    if (human != None)
    {
        for (Inv = human.Inventory; Inv != None; Inv = Inv.Inventory)
        {
            if (Inv != None)
            {
                if ( KFAmmunition(Inv) != None && (KFAmmunition(Inv).AmmoAmount < KFAmmunition(Inv).MaxAmmo) )
                {
                    
                   KFAmmunition(Inv).AmmoAmount = KFAmmunition(Inv).AmmoAmount + 1;
                }
            }
        }
    }
}

defaultproperties
{
     GroupName="KF-SnebbersAmmoRegen"
     FriendlyName="SnebbersAmmoRegen"
     Description="Ammo regeneration over time"
}
(Please mind the name, they said to call it that, so I did, by no measure do I care for the name)

However I hit the wall of being unable to call an instance function into a static function and have no idea how to call timers into each of the different functions (Let alone get the mutator to read from the .ini file to realise which weapon fits into which category.

If someone could point me into the right direction I would appreciate it. It's an awful big task though.

Also the ini

Code:
; Groups are as follows:
; Group 0 is exclusively for the 9mm, and it is infinite ammo regardless.
; Group 1 is for weapons that regenerate 1% of the players MaxAmmo every 2 seconds.
; Group 2 is for power weapons, like the crossbow that regenerate 1 ammo(bullet, bolt, whatever) every 8 seconds.
; Group 3 is for Dual wield weapons and regenerate a clip every 15 seconds.
; Group 4 is for most shotguns and regenerate 1 shell every 3 seconds.
; Group 5 is for the husk gun, the ammo regen is 2 fuel every second.
; Group 6 is for the Law, HRL-1, RPG-1 and M99 and regenerates 1 bullet every 12 seconds.
AmmoRegen=1:ScrnBalanceSrv.ScrnChainsaw
AmmoRegen=2:ScrnBalanceSrv.ScrnCrossbuzzsaw
AmmoRegen=0:ScrnBalanceSrv.ScrnSingle
AmmoRegen=1:ScrnBalanceSrv.ScrnMagnum44
AmmoRegen=1:ScrnBalanceSrv.ScrnMK23
AmmoRegen=1:ScrnBalanceSrv.ScrnDeagle
AmmoRegen=3:ScrnBalanceSrv.ScrnDualies
AmmoRegen=3:ScrnBalanceSrv.ScrnDual44Magnum
AmmoRegen=3:ScrnBalanceSrv.ScrnDualMK23
AmmoRegen=3:ScrnBalanceSrv.ScrnDualDeagle
AmmoRegen=3:ScrnBalanceSrv.ScrnDual44MagnumLaser
AmmoRegen=3:ScrnBalanceSrv.ScrnDualMK23Laser
AmmoRegen=1:KFMod.GoldenDeagle
AmmoRegen=3:KFMod.GoldenDualDeagle
AmmoRegen=1:KFMod.FlareRevolver
AmmoRegen=3:KFMod.DualFlareRevolver
AmmoRegen=1:Cz75Laser.Cz75Laser
AmmoRegen=1:FNComboWPMut.P57LLI
AmmoRegen=4:ScrnBalanceSrv.ScrnShotgun
AmmoRegen=4:ScrnBalanceSrv.ScrnBoomStick
AmmoRegen=4:ScrnBalanceSrv.ScrnNailGun
AmmoRegen=4:ScrnBalanceSrv.ScrnKSG
AmmoRegen=4:ScrnBalanceSrv.ScrnBenelli
AmmoRegen=4:ScrnBalanceSrv.ScrnAA12
AmmoRegen=4:KFMod.GoldenAA12
AmmoRegen=4:KFMod.SPShotgun
AmmoRegen=4:KFMod.Trenchgun
AmmoRegen=4:KFMod.GoldenBenelli
AmmoRegen=4:ScrnWeapons.Saiga12c
AmmoRegen=2:Rem870ECMut.Rem870EC
AmmoRegen=4:Moss12Mut.Moss12
AmmoRegen=4:ProtectaMut.Protecta
AmmoRegen=1:ScrnBalanceSrv.ScrnWinchester
AmmoRegen=2:KFMod.Crossbow
AmmoRegen=3:ScrnBalanceSrv.ScrnSPSniper
AmmoRegen=1:ScrnBalanceSrv.ScrnM14EBR
AmmoRegen=6:ScrnBalanceSrv.ScrnM99
AmmoRegen=1:ScrnWeapons.VSSDT
AmmoRegen=1:ScrnWeapons.SVDc
AmmoRegen=1:JS_L85A2.L85A2
AmmoRegen=1:Weapon_M44Beta.M44
AmmoRegen=1:L96AWPLLImut.L96AWPLLI
AmmoRegen=1:BDHuntingRifleFinal.Hunting_Rifle
AmmoRegen=1:SV98.SV98
AmmoRegen=1:ScrnBalanceSrv.ScrnBullpup
AmmoRegen=1:ScrnBalanceSrv.ScrnAK47
AmmoRegen=1:KFMod.MKb42
AmmoRegen=1:ScrnBalanceSrv.ScrnM4
AmmoRegen=1:KFMod.Thompson
AmmoRegen=1:ScrnBalanceSrv.ScrnSPThompson
AmmoRegen=1:ScrnBalanceSrv.ScrnThompsonDrum
AmmoRegen=1:ScrnBalanceSrv.ScrnSCARMK17
AmmoRegen=1:ScrnBalanceSrv.ScrnFNFAL_ACOG_
AmmoRegen=1:KFMod.GoldenAK47
#AmmoRegen=4:KFMod.KrissM
AmmoRegen=4:ScrnBalanceSrv.ScrnM4203
AmmoRegen=1:ScrnWeapons.Thompson
AmmoRegen=1:ScrnWeapons.AKC74
AmmoRegen=1:ScrnWeapons.VALDT
AmmoRegen=1:ScrnWeapons.HK417
AmmoRegen=0:KFPortalTurret.PTurret
AmmoRegen=1:FNComboWPMut.P90DT
AmmoRegen=1:KFPPSHMut.PPSH
AmmoRegen=1:FX-G36C.G36C
AmmoRegen=1:AUG_A1ARMut.AUG_A1AR
AmmoRegen=1:M249Mut.M249
AmmoRegen=1:XMV850.XMV850
AmmoRegen=7:ScrnBalanceSrv.ScrnPipeBomb
AmmoRegen=2:KFMod.M79
AmmoRegen=2:KFMod.GoldenM79
AmmoRegen=8:KFMod.SPGrenade
AmmoRegen=2:ScrnBalanceSrv.ScrnM4203
AmmoRegen=2:ScrnBalanceSrv.ScrnM32
AmmoRegen=6:ScrnBalanceSrv.ScrnHRL
AmmoRegen=6:ScrnBalanceSrv.ScrnLAW
AmmoRegen=6:KFMod.SealSqueal
AmmoRegen=2:KFMod.SeekerSix
AmmoRegen=2:ScrnWeapons.HopMineL
AmmoRegen=6:ScrnWeapons.RPG
#AmmoRegen=6:ScrnWeapons.M202A2
AmmoRegen=1:ScrnBalanceSrv.ScrnMAC10
AmmoRegen=1:ScrnBalanceSrv.ScrnThompsonInc
AmmoRegen=1:ScrnBalanceSrv.ScrnFlareRevolver
AmmoRegen=3:ScrnBalanceSrv.ScrnDualFlareRevolver
AmmoRegen=1:ScrnBalanceSrv.ScrnFlameThrower
AmmoRegen=4:ScrnBalanceSrv.ScrnTrenchgun
AmmoRegen=2:ScrnBalanceSrv.ScrnM79Inc
AmmoRegen=1:KFMod.Thompson
AmmoRegen=1:KFMod.GoldenFT
#AmmoRegen=6:ScrnWeapons.M202A1
AmmoRegen=6:Coctel02.Molotov
AmmoRegen=1:TommygunInc.ThompsonInc
AmmoRegen=1:ScrnBalanceSrv.ScrnMP7M
AmmoRegen=1:ScrnBalanceSrv.ScrnMP5M
AmmoRegen=1:ScrnBalanceSrv.ScrnKrissM
AmmoRegen=1:ScrnBalanceSrv.ScrnM7A3M
AmmoRegen=1:ScrnBalanceSrv.ScrnM79M
AmmoRegen=1:ScrnBalanceSrv.ScrnM4203M
AmmoRegen=1:KFMod.BlowerThrower
AmmoRegen=4:WhiskyMediShot.WMediShot
AmmoRegen=1:KFMod.ZEDMKII

Yes that does indeed look like the layout from marco's serverperks, the list was sent to me for all the weapon classes and it seemed like common sense to just find and replace.
 
Last edited:
For all the weapons? Husk launcher would be overpowered in that case.

EDIT: I suppose I could put several if's and else if's and an else, but I was hoping I could get it to read from the ini for easy editing, rather than having to recompile the mutator every time.

For the weapons? Then make globalconfig arrays and set the mutator to class config(FileNameOfINI);. Set the different arrays to how you want the mutator to effect them.
 
Upvote 0
For the weapons? Then make globalconfig arrays and set the mutator to class config(FileNameOfINI);. Set the different arrays to how you want the mutator to effect them.

Thanks that's a step in the right direction :)

EDIT: For good measure I'll probably release the source and the compiled up with credits to Glider and marco for snippets of code that fit this and anybody that helps. That's not a "hey guis help me and u get creds." I just know I wouldn't have been able to do it without their examples to work from.

Found out that I could implement the timers by using things like

Code:
SetTimer(<Time>, <True/False>, <FunctionToCall>)
However, upon trying to compile it is saying bad ',' or missing ')'
 
Last edited:
Upvote 0
Found out that I could implement the timers by using things like

Code:
SetTimer(<Time>, <True/False>, <FunctionToCall>)
However, upon trying to compile it is saying bad ',' or missing ')'

in unreal 2.5 there are only 2 parameter for setTimer(Time,bLoop) and you can also have only one timer per class.
unreal 3 provides multiple timers i think but unreal 2.5 doesn't.
 
Upvote 0
in unreal 2.5 there are only 2 parameter for setTimer(Time,bLoop) and you can also have only one timer per class.
unreal 3 provides multiple timers i think but unreal 2.5 doesn't.
That would explain a lot..

The only problem I have right now is the timers, I believe I just sorted out my ini linking etc. Of course every function for ammoregen requires a different timer. Perhaps make different classes for each of the ammo regen types? Would that work?
 
Last edited:
Upvote 0
Try this: In orange are the parts you have to configure
Code:
class SnebbersAmmoRegen extends Mutator
     config([COLOR=DarkOrange]YourConfigFile[/COLOR]);

var config array<int> AmmoRegenTime;  //Define your Invertalls for the AmmoRegen Functions
var int Counter;

event PreBeginPlay()
{
    SetTimer(1 ,true);
}

function Timer()
{
    local Controller C;
    
    Counter++;    

    for (C = Level.ControllerList; C != None; C = C.NextController)
    {
        if(C.bIsPlayer && C.Pawn !=None)
        {
               if(Counter % AmmoRegen[0] == 0)
                     AmmoRegen0(pawn);
               if(Counter % AmmoRegen[1] == 0)
                     AmmoRegen1(pawn);
               if(Counter % AmmoRegen[2] == 0)
                     AmmoRegen2(pawn);
               if(Counter % AmmoRegen[3] == 0)
                     AmmoRegen3(pawn);
               if(Counter % AmmoRegen[4] == 0)
                     AmmoRegen4(pawn);
               if(Counter % AmmoRegen[5] == 0)
                     AmmoRegen5(pawn);
               if(Counter % AmmoRegen[6] == 0)
                     AmmoRegen6(pawn);
        }
    }
}

static function AmmoRegen0(Pawn pawn)
{
    local KFHumanPawn human;
    Local Inventory Inv;

    human = KFHumanPawn(pawn);
    
    if (human != None)
    {
        for (Inv = human.Inventory; Inv != None; Inv = Inv.Inventory)
        {
            if (Inv != None)
            {
                if ( KFAmmunition(Inv) != None && (KFAmmunition(Inv).AmmoAmount < KFAmmunition(Inv).MaxAmmo) )
                {
                   KFAmmunition(Inv).AmmoAmount = KFAmmunition(Inv).MaxAmmo;
                }
            }
        }
    }
}

static function AmmoRegen1(Pawn pawn)
{
    local KFHumanPawn human;
    Local Inventory Inv;

    human = KFHumanPawn(pawn);
    
    if (human != None)
    {
        for (Inv = human.Inventory; Inv != None; Inv = Inv.Inventory)
        {
            if (Inv != None)
            {
                if ( KFAmmunition(Inv) != None && (KFAmmunition(Inv).AmmoAmount < KFAmmunition(Inv).MaxAmmo) )
                {
                    KFAmmunition(Inv).AmmoAmount = KFAmmunition(Inv).AmmoAmount + (KFAmmunition(Inv).MaxAmmo*0.01);
                }
            }
        }
    }
}

static function AmmoRegen2(Pawn pawn)
{
    local KFHumanPawn human;
    Local Inventory Inv;

    human = KFHumanPawn(pawn);
    
    if (human != None)
    {
        for (Inv = human.Inventory; Inv != None; Inv = Inv.Inventory)
        {
            if (Inv != None)
            {
                if ( KFAmmunition(Inv) != None && (KFAmmunition(Inv).AmmoAmount < KFAmmunition(Inv).MaxAmmo) )
                {
                   KFAmmunition(Inv).AmmoAmount = KFAmmunition(Inv).AmmoAmount + 1;
                }
            }
        }
    }
}

static function AmmoRegen3(Pawn pawn)
{
    local KFHumanPawn human;
    Local Inventory Inv;

    human = KFHumanPawn(pawn);
    
    if (human != None)
    {
        for (Inv = human.Inventory; Inv != None; Inv = Inv.Inventory)
        {
            if (Inv != None)
            {
                if ( KFAmmunition(Inv) != None && (KFAmmunition(Inv).AmmoAmount < KFAmmunition(Inv).MaxAmmo) )
                {
                   KFAmmunition(Inv).AmmoAmount = KFAmmunition(Inv).AmmoAmount + KFWeapon(Inv).MagCapacity;
                }
            }
        }
    }
}

static function AmmoRegen4(Pawn pawn)
{
    local KFHumanPawn human;
    Local Inventory Inv;

    human = KFHumanPawn(pawn);
    
    if (human != None)
    {
        for (Inv = human.Inventory; Inv != None; Inv = Inv.Inventory)
        {
            if (Inv != None)
            {
                if ( KFAmmunition(Inv) != None && (KFAmmunition(Inv).AmmoAmount < KFAmmunition(Inv).MaxAmmo) )
                {
                    
                   KFAmmunition(Inv).AmmoAmount = KFAmmunition(Inv).AmmoAmount + 1;
                }
            }
        }
    }
}

static function AmmoRegen5(Pawn pawn)
{
    local KFHumanPawn human;
    Local Inventory Inv;

    human = KFHumanPawn(pawn);
    
    if (human != None)
    {
        for (Inv = human.Inventory; Inv != None; Inv = Inv.Inventory)
        {
            if (Inv != None)
            {
                if ( KFAmmunition(Inv) != None && (KFAmmunition(Inv).AmmoAmount < KFAmmunition(Inv).MaxAmmo) )
                {
                   KFAmmunition(Inv).AmmoAmount = KFAmmunition(Inv).AmmoAmount + 2;
                }
            }
        }
    }
}

static function AmmoRegen6(Pawn pawn)
{
    local KFHumanPawn human;
    Local Inventory Inv;

    human = KFHumanPawn(pawn);
    
    if (human != None)
    {
        for (Inv = human.Inventory; Inv != None; Inv = Inv.Inventory)
        {
            if (Inv != None)
            {
                if ( KFAmmunition(Inv) != None && (KFAmmunition(Inv).AmmoAmount < KFAmmunition(Inv).MaxAmmo) )
                {
                   KFAmmunition(Inv).AmmoAmount = KFAmmunition(Inv).AmmoAmount + 1;
                }
            }
        }
    }
}

defaultproperties
{
     AmmoRegenTime(0)=[COLOR=DarkOrange]TimeInSeconds[/COLOR]
     AmmoRegenTime(1)=[COLOR=DarkOrange]TimeInSeconds[/COLOR]
     AmmoRegenTime(2)=[COLOR=DarkOrange]TimeInSeconds[/COLOR]
     AmmoRegenTime(3)=[COLOR=DarkOrange]TimeInSeconds[/COLOR]
     AmmoRegenTime(4)=[COLOR=DarkOrange]TimeInSeconds[/COLOR]
     AmmoRegenTime(5)=[COLOR=DarkOrange]TimeInSeconds[/COLOR]
     AmmoRegenTime(6)=[COLOR=DarkOrange]TimeInSeconds[/COLOR]
     GroupName="KF-SnebbersAmmoRegen"
     FriendlyName="SnebbersAmmoRegen"
     Description="Ammo regeneration over time"
}
 
Last edited:
Upvote 0
I cannot read, so edited

Code:
D:\Program Files (x86)\Steam\SteamApps\common\KillingFloor\Test\Classes\Test.uc(
22) : Error, Bad or missing expression after '%'
Compile aborted due to errors.
Failure - 1 error(s), 0 warning(s)
I like the idea though, I tend to make things too complex, and I have very limited knowledge of unreal, I'm a bit more HTML and CSS myself.

Don't worry I changed all the mutator specifics to Test, and replicated the .ini too.

Like this:

Code:
class Test extends Mutator
     config(Test);

var config array<int> AmmoRegenTime;  //Define your intervals for the AmmoRegen Functions
var int Counter;

event PreBeginPlay()
{
    SetTimer(1 ,true);
}

function Timer()
{
    local Controller C;
    
    Counter++;    

    for (C = Level.ControllerList; C != None; C = C.NextController)
    {
        if(C.bIsPlayer && C.Pawn !=None)
        {
               if(Counter % AmmoRegen[0] == 0)
                     AmmoRegen0(pawn);
               if(Counter % AmmoRegen[1] == 0)
                     AmmoRegen1(pawn);
               if(Counter % AmmoRegen[2] == 0)
                     AmmoRegen2(pawn);
               if(Counter % AmmoRegen[3] == 0)
                     AmmoRegen3(pawn);
               if(Counter % AmmoRegen[4] == 0)
                     AmmoRegen4(pawn);
               if(Counter % AmmoRegen[5] == 0)
                     AmmoRegen5(pawn);
               if(Counter % AmmoRegen[6] == 0)
                     AmmoRegen6(pawn);
        }
    }
}

static function AmmoRegen0(Pawn pawn)
{
    local KFHumanPawn human;
    Local Inventory Inv;

    human = KFHumanPawn(pawn);
    
    if (human != None)
    {
        for (Inv = human.Inventory; Inv != None; Inv = Inv.Inventory)
        {
            if (Inv != None)
            {
                if ( KFAmmunition(Inv) != None && (KFAmmunition(Inv).AmmoAmount < KFAmmunition(Inv).MaxAmmo) )
                {
                   KFAmmunition(Inv).AmmoAmount = KFAmmunition(Inv).MaxAmmo;
                }
            }
        }
    }
}

static function AmmoRegen1(Pawn pawn)
{
    local KFHumanPawn human;
    Local Inventory Inv;

    human = KFHumanPawn(pawn);
    
    if (human != None)
    {
        for (Inv = human.Inventory; Inv != None; Inv = Inv.Inventory)
        {
            if (Inv != None)
            {
                if ( KFAmmunition(Inv) != None && (KFAmmunition(Inv).AmmoAmount < KFAmmunition(Inv).MaxAmmo) )
                {
                    KFAmmunition(Inv).AmmoAmount = KFAmmunition(Inv).AmmoAmount + (KFAmmunition(Inv).MaxAmmo*0.01);
                }
            }
        }
    }
}

static function AmmoRegen2(Pawn pawn)
{
    local KFHumanPawn human;
    Local Inventory Inv;

    human = KFHumanPawn(pawn);
    
    if (human != None)
    {
        for (Inv = human.Inventory; Inv != None; Inv = Inv.Inventory)
        {
            if (Inv != None)
            {
                if ( KFAmmunition(Inv) != None && (KFAmmunition(Inv).AmmoAmount < KFAmmunition(Inv).MaxAmmo) )
                {
                   KFAmmunition(Inv).AmmoAmount = KFAmmunition(Inv).AmmoAmount + 1;
                }
            }
        }
    }
}

static function AmmoRegen3(Pawn pawn)
{
    local KFHumanPawn human;
    Local Inventory Inv;

    human = KFHumanPawn(pawn);
    
    if (human != None)
    {
        for (Inv = human.Inventory; Inv != None; Inv = Inv.Inventory)
        {
            if (Inv != None)
            {
                if ( KFAmmunition(Inv) != None && (KFAmmunition(Inv).AmmoAmount < KFAmmunition(Inv).MaxAmmo) )
                {
                   KFAmmunition(Inv).AmmoAmount = KFAmmunition(Inv).AmmoAmount + KFWeapon(Inv).MagCapacity;
                }
            }
        }
    }
}

static function AmmoRegen4(Pawn pawn)
{
    local KFHumanPawn human;
    Local Inventory Inv;

    human = KFHumanPawn(pawn);
    
    if (human != None)
    {
        for (Inv = human.Inventory; Inv != None; Inv = Inv.Inventory)
        {
            if (Inv != None)
            {
                if ( KFAmmunition(Inv) != None && (KFAmmunition(Inv).AmmoAmount < KFAmmunition(Inv).MaxAmmo) )
                {
                    
                   KFAmmunition(Inv).AmmoAmount = KFAmmunition(Inv).AmmoAmount + 1;
                }
            }
        }
    }
}

static function AmmoRegen5(Pawn pawn)
{
    local KFHumanPawn human;
    Local Inventory Inv;

    human = KFHumanPawn(pawn);
    
    if (human != None)
    {
        for (Inv = human.Inventory; Inv != None; Inv = Inv.Inventory)
        {
            if (Inv != None)
            {
                if ( KFAmmunition(Inv) != None && (KFAmmunition(Inv).AmmoAmount < KFAmmunition(Inv).MaxAmmo) )
                {
                   KFAmmunition(Inv).AmmoAmount = KFAmmunition(Inv).AmmoAmount + 2;
                }
            }
        }
    }
}

static function AmmoRegen6(Pawn pawn)
{
    local KFHumanPawn human;
    Local Inventory Inv;

    human = KFHumanPawn(pawn);
    
    if (human != None)
    {
        for (Inv = human.Inventory; Inv != None; Inv = Inv.Inventory)
        {
            if (Inv != None)
            {
                if ( KFAmmunition(Inv) != None && (KFAmmunition(Inv).AmmoAmount < KFAmmunition(Inv).MaxAmmo) )
                {
                   KFAmmunition(Inv).AmmoAmount = KFAmmunition(Inv).AmmoAmount + 1;
                }
            }
        }
    }
}

defaultproperties
{
     AmmoRegenTime(0)=1
     AmmoRegenTime(1)=2
     AmmoRegenTime(2)=8
     AmmoRegenTime(3)=15
     AmmoRegenTime(4)=3
     AmmoRegenTime(5)=1
     AmmoRegenTime(6)=12
     GroupName="KF-Test"
     FriendlyName="Test"
     Description="Ammo regeneration over time"
}
 
Last edited:
Upvote 0