• 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/

how to specify ammo amounts

Take a look at this:

Code:
class NoKarmaMut extends Mutator;
simulated function PostBeginPlay()
{
 local KActor K;
 ForEach DynamicActors(Class'KActor',K)
 {
  K.Destroy();
  if( K==None )
   Continue;
  K.SetPhysics(PHYS_None);
  K.SetCollision(False);
  K.bHidden = True;
  K.bScriptInitialized = true;
  K.Disable('Tick');
  K.RemoteRole = ROLE_None;
 }
}
 
Defaultproperties
{
 GroupName = "KF-NoKarma"
 FriendlyName = "No Karma Decorations"
 Description = "Remove all those buggy karma decorations from the maps."
 RemoteRole=ROLE_SimulatedProxy
 bAlwaysRelevant=True
}
A very basic "class" or mutator in this case, that deletes all KActors.(Objects that can be pushed and/or shot around the room.)


Code:
class AdvArena extends Mutator;
var() config array<string> WeaponClassNames;
var() config bool   bRandomPickOne;
var() config bool   bRandomPerSpawn;
var   array<class<weapon> > WeaponClasses;
simulated function PostBeginPlay()
{
 local ShopVolume S;
 foreach AllActors(Class'ShopVolume',S)
  S.bAlwaysClosed = true;
 Destroy();
}
function PreBeginPlay ()
{
 local int i;
 local class<weapon> W;
 super.PreBeginPlay();
 if (bRandomPickOne)
  DefaultWeaponName = WeaponClassNames[Rand(WeaponClassNames.length)];
 for (i=0;i<WeaponClassNames.length;i++)
 {
  W = class<weapon>(DynamicLoadObject(WeaponClassNames[i],class'Class'));
  if (W != None)
   WeaponClasses[WeaponClasses.length] = W;
 }
}
function ModifyPlayer(Pawn Other)
{
 local int i;
 local byte LP;
 local class<weapon> W;
 Super.ModifyPlayer(Other);
 if (bRandomPerSpawn)
 {
  W = WeaponClasses[Rand(WeaponClasses.length)];
  SpawnWeapon(W, Other);
  SpawnAmmo(W.default.FireModeClass[0].default.AmmoClass, Other);
  if (W.default.FireModeClass[1].default.AmmoClass != None && W.default.FireModeClass[0].default.AmmoClass != W.default.FireModeClass[1].default.AmmoClass)
   SpawnAmmo(W.default.FireModeClass[1].default.AmmoClass, Other);
  Other.Controller.ClientSwitchToBestWeapon();
  KFHumanPawn(Other).RequiredEquipment[0] = string(W);
  return;
 }
 if (bRandomPickOne)
  return;
 for (i=0;i<WeaponClasses.length;i++)
 {
  SpawnWeapon(WeaponClasses[i], Other);
  if (WeaponClasses[i].default.Priority > LP)
  {
   LP = WeaponClasses[i].default.Priority;
   KFHumanPawn(Other).RequiredEquipment[0] = string(WeaponClasses[i]);
  }
  if (KFHumanPawn(Other) != None)
  {
   SpawnAmmo(WeaponClasses[i].default.FireModeClass[0].default.AmmoClass, Other);
   if (WeaponClasses[i].default.FireModeClass[0].default.AmmoClass != WeaponClasses[i].default.FireModeClass[1].default.AmmoClass)
    SpawnAmmo(WeaponClasses[i].default.FireModeClass[1].default.AmmoClass, Other);
  }
 }
 Other.Controller.ClientSwitchToBestWeapon();
}
function class<Weapon> MyDefaultWeapon()
{
 if (!bRandomPickOne || bRandomPerSpawn)
  return None;
 return super.MyDefaultWeapon();
}
function string GetInventoryClassOverride(string InventoryClassName)
{
 return Super(Mutator).GetInventoryClassOverride(InventoryClassName);
}
function ItemPickedUp(Pickup Other);
function ItemChange(Pickup Other);
static function SpawnWeapon(class<weapon> newClass, Pawn P)
{
 local Weapon newWeapon;
    if( (newClass!=None) && P != None && (P.FindInventoryType(newClass)==None) )
    {
        newWeapon = P.Spawn(newClass,,,P.Location);
        if( newWeapon != None )
            newWeapon.GiveTo(P);
    }
}
static function SpawnAmmo(class<Ammunition> newClass, Pawn P, optional float Multiplier)
{
 local Ammunition Ammo;
 if (P==None || newClass == None)
  return;
 Ammo = Ammunition(P.FindInventoryType(newClass));
 if(Ammo == None)
    {
  Ammo = P.Spawn(newClass);
  P.AddInventory(Ammo);
    }
 if(Ammo == None)
  return;
    if (Multiplier > 0)
  Ammo.AddAmmo(Ammo.InitialAmount*Multiplier);
    else
  Ammo.AddAmmo(Ammo.InitialAmount);
 Ammo.GotoState('');
}
function bool CheckReplacement( Actor Other, out byte bSuperRelevant )
{
 local int i;
 bSuperRelevant = 0;
 if (Weapon(Other) != None)
 {
  for (i=0;i<WeaponClasses.length;i++)
   if (WeaponClasses[i] == Other.class)
    return true;
  return false;
 }
 else if (KFHumanPawn(Other) != None)
 {
  KFHumanPawn(Other).RequiredEquipment[0] = "";
  KFHumanPawn(Other).RequiredEquipment[1] = "";
  return true;
 }
 else if (WeaponPickup(Other) != None && Other.Owner == None)
 {
  return false;
 }
 
 return Super.CheckReplacement( Other, bSuperRelevant );
}
defaultproperties
{
     ConfigMenuClassName="ArenaMut.ArenaMenu"
     FriendlyName="Advanced Weapon Arena"
     GroupName="KF-AdvArena"
     Description="A highly advanced weapon arena"
}

A very advanced advanced mutator (class) that is configurable and has a menu you can open and edit. This mutator basically makes it so you can only add specific guns to the arena instead of the default ones and pickups. The class for the config menu is a seperate class and is refered to in this class several times. Due to its length I cannot post it on here.
Don't bother trying to decipher or understand it because its for the advanced coders, such as my self :D
 
Last edited:
Upvote 0
you mean the barrakets after the word then the ;
Example: K.Destroy();

Local K KActor replaces the name of the class KActor with k so it easy to write the code and saves time and space. Its much easier to type instead of KActor everytime it is called.

K=KActor
Destroy(); = Calls the function to destroy the class KActor if it exists in the current map.
We can do this with other objects too!

This destroys all "KFWeaponPickup" (The pickup of a weapon you see when you toss it or see one on the ground.)


Code:
simulated function PostBeginPlay()
{
local KFWeaponPickup K;
ForEach DynamicActors(Class'KFWeaponPickup',K)
{
K.Destroy();
if( K==None )
Continue;
K.SetCollision(False);
K.bHidden = True;
K.RemoteRole = ROLE_None;
}
}
 
Last edited:
Upvote 0