Changing weapon characteristics
This guide is intended to give users the ability to modify existing weapons with minimal knowledge of UnrealScript. It is written from the point of view of changing the attributes of standard weapons from a single-player mutator, namely:
class AlteredWeaponMut extends Mutator;
function PostBeginPlay()
{
class'Single'.default.ItemName = "Handgun";
}
defaultproperties
{
GroupName="KFAlteredWeaponMut"
FriendlyName="Altered Weapon Mutator"
Description="Пример мутатора, который демонстрирует, как изменить существующее оружие."
}
This guide covers most of the essential attributes that can be changed.
Class semantics
I’d like to focus on what the different classes used for inventory items in general mean and how they relate to each other:
Weapon is a weapon class in the inventory that contains general information. For example, when an item should appear in inventory, its name and weight. Contains relevant references to the WeaponPickup, WeaponAttachment and FireMode classes. This class is also responsible for how weapons will be displayed from 1st person. An example of this class is ‘Single’.
WeaponPickup – The displayed weapon model when it (the weapon) is located somewhere in the game world, outside the player’s inventory (this also applies to the merchant). Contains information about the name of the weapon, how much ammunition (and its quantity) is consumed when firing, etc. An example of this class is ‘SinglePickup’.
WeaponAttachment – Responsible for how the weapon is displayed from the 3rd person (and how other players from the side will see it). An example of this class is ‘SingleAttachment’.
FireMode - The class is responsible for what fire mode the weapon has, what ammunition it uses, what damage it does, and similar related things. A weapon can have two fire modes and not necessarily one of them can be offensive (for example, the alt fire of a Beretta 9mm (by default it is RMB) includes a flashlight). An example of this class is ‘SingleFire’.
Ammo - The class is responsible for how much ammo the weapon can carry, how much it initially contains, and how much ammo you receive when you pick up an ammo box. An example of this class is ‘SingleAmmo’.
AmmoPickup – Used to indicate how much ammo a particular type of ammo box picks up (for example, 9mm ammo lying on the ground). An example of this class is ‘SingleAmmoPickup’.
Projectile - Used to indicate the type of ammunition used by the weapon (shot, crossbow bolt, rocket, etc.), and also describes the speed of the projectile, the damage it causes, and other information. An example of this class is ‘CrossbowArrow’.
Weapon name change
In order to rename a weapon, you need to change several variables located in different places:
- Weapon display name in HUD:
class'Single'.default.ItemName = "9mm Tactical";
9mm Tactical will be the name of the weapon that is displayed in the HUD.
- Purchase panel in the store:
class'SinglePickup'.default.ItemName = "9mm Pistol";
9mm Pistol will be the name of the weapon that will be displayed in the store.
- Inventory panel in the store. This should be a short version of the weapon name:
class'SinglePickup'.default.ItemShortName = "9mm Pistol";
9mm Pistol will be the short name of the weapon that will be displayed in the player’s inventory (including the store).
Shooting modes
Switch between semi-automatic and automatic firing modes. Everything depends on changing the variable responsible for this (true=semi-automatic, false=automatic):
class'SingleFire'.default.bWaitForRelease = true;
If the value is set to true, then to shoot you will need to press the button, otherwise (value flase) - just hold down the button to shoot.
Damage
Damage is determined depending on what type of charge the weapon uses - an instant shot (for example, a shot from any pistol) or a projectile (for example, a shot from a crossbow):
- If the type of charge is an instant shot (for example, in the case of pistols):
class'SingleFire'.default.DamageMax = 32;
32 – maximum damage indicator (excluding multipliers).
- If the type of charge is a projectile (for example, a crossbow bolt or a L.A.W rocket):
class'CrossbowArrow'.default.Damage = 300;
300 is a constant damage indicator (i.e. without taking into account multipliers).
- Projectiles that are derivatives of ShotgunBullet:
class'BoomStickBullet'.default.HeadShotDamageMult = 1.5;
1.5 – damage multiplier from a shot hitting the head.
- Crossbow Bolt uses the same variable, but is not a derivative of ShotgunBullet:
class'CrossbowArrow'.default.HeadShotDamageMult = 6.0;
6.0 – damage multiplier for head bolt hits.
- For other weapons, the head damage multiplier is determined by the class itself:
class'DamTypeM14EBR'.default.HeadShotDamageMult = 2.0;
2.0 – headshot damage multiplier, specified by the DamTypeM14EBR class.
Fire rate
Consists of two variables that you can change:
- Rate of fire. This is essentially the delay between shots (value 0.5 = 2 shots per second):
class'SingleFire'.default.FireRate = 0.5;
- Speed value for shooting animation. Used as a multiplier for the default shooting animation speed (0.5 - 2 times less speed, 1 - normal speed, 2 - double speed):
class'SingleFire'.default.FireAnimRate = 1.5;
1.5 indicates that the speed is higher than normal, but not double.
Recoil
If you change the rate of fire, then also pay attention to changing the recoil value:
- Recoil frequency (i.e. the speed of the recoil received). The value must be less than the rate of fire (see spoiler above, point 1):
class'SingleFire'.default.RecoilRate = 0.07;
- Maximum value of the vertical recoil angle:
class'SingleFire'.default.MaxVerticalRecoilAngle = 300;
The higher the value, the more recoil can push the scope upward.
- Maximum value of the horizontal recoil angle. Typically less than the vertical recoil angle:
class'SingleFire'.default.MaxHorizontalRecoilAngle = 50;
The higher the value, the more the sight will move to the sides when shooting.
Accuracy
Two variables affect a weapon’s accuracy. In KF, the bullet spread is designed so that the first shot is always very accurate:
- Basic spread value. Bullet spread value at the start of shooting:
class'SingleFire'.default.Spread = 0.015;
0.015 - spread value of the first bullet.
- Maximum spread. Affects the limit value that the spread can reach. After each subsequent shot, at 0.5 second intervals, the specified value divided by 6 is added to the current spread value. In other words, if you fire 6 shots and the time interval between them (shots) is 0.5 seconds, then you will reach the maximum spread value:
class'SingleFire'.default.MaxSpread = 0.12;
Basically, this value does not change for each weapon (as it is set in the base class) and applies to all weapons (however, there are weapons that can calculate the maximum spread value using their own formula, ignoring the value of this variable)
Aiming
You can aim from absolutely any weapon (through the front sight or through the built-in/attached sight). The following variables affect the intensity of the crosshair (that is, the effective ability of the crosshair to move closer to the screen and the ability to change the power of the crosshair):
- Will the weapon be able to increase the magnification of the sight:
class 'single'.default.bHasAimingMode = true;
If the value is true, then it is possible to adjust the sight magnification. Otherwise (i.e. the value is false) this option will not exist.
- How the weapon will be displayed in your hands if you don’t aim. The higher the value, the farther the weapon in the player’s hands will be visually displayed from the player’s camera, and this variable is also the default FOV (Field Of View) angle value:
class 'single'.StandardDisplayFOV = 70.0;
- The intensity value of the sight (how far you can zoom the sight) is also defined as the FOV angle. A low value of this variable leads to an increase in the scope’s magnification:
class 'single'.ZoomedDisplayFOV = 65.0;
- How the weapon will be displayed when aiming. Again, defined as the FOV angle. It’s better to leave this value as it is, you won’t lose anything from it:
class 'single'.PlayerIronSightFOV = 75.0;
Ammunition
Several variables are used to determine ammunition capacity:
- How much ammunition can be carried for a weapon at one time:
class 'SingleAmmo'.default.MaxAmmo = 240;
- The initial value of a weapon’s ammunition when appearing with it/purchasing it in a store (without additional purchase of ammunition for the weapon):
class 'SingleAmmo'.default.InitialAmount = 120;
- The number of refilled cartridges when lifting the ammunition box:
class 'SingleAmmo'.default.AmmoPickupAmount = 30;
- Number of ammo refilled when picking up a box with a specific type of ammunition (for example, a box of missiles or a bag of bolts):
class 'SingleAmmo'.default.AmmoAmount = 20;
Selection message
This message appears when you pick up a weapon lying on the map:
class 'SingleAmmo'.default.PickupMessage = You got another 9mm Handgun.
When picking up a weapon, the following text will appear at the bottom middle of the screen - You got another 9mm Handgun.
Merchant
Here is a list of important variables used in the store (trader menu):
- Amount required to purchase a weapon:
class'SinglePickup'.default.Cost = 1000;
1000 - the cost of a certain weapon.
- Cost of one clip:
class'SinglePickup'.default.AmmoCost = 10;
- Size of purchased clip:
class'SinglePickup'.default.BuyClipSize = 30;
In addition, there are three variables showing the statistics of weapons in the store (maximum value is 100). It is important to remember that weapon statistics may not be accurate and may not correspond to reality:
4.1) Weapon power - what damage the weapon does:
class'SinglePickup'.default.PowerValue = 20;
4.2) Rate of fire - how often the weapon can fire:
class'SinglePickup'.default.SpeedValue = 50;
4.3) Firing range:
class'SinglePickup'.default.RangeValue = 35;
Inventory information
Even though these are far from the most important variables, it wouldn’t hurt to write about them:
- The relationship of the subject to a specific group:
class'Single'.default.InventoryGroup = 2;
Typically, different categories contain items with similar parameters: 1 - Melee weapons; 2 - Pistols; 3 - Main weapon; 4 - Special (often quite powerful and heavy); 5 - Tools at hand (things that are not always used as weapons for destruction, but find their use to support the team); When creating a weapon, try to choose a category so that during the game it will be convenient to get it (the weapon) and does not cause confusion in the players’ inventory.
- Priority of weapons in inventory. Which weapons from a certain group will be taken out of the inventory earlier than others:
class'Single'.default.Priority = 3;
3 indicates that this weapon will be awarded third in its category.
- Overall item priority (not to be confused with the variable above). Will the weapon in hand change to the one picked up? If the priority of the item being picked up is higher than the priority of the item in hand, then the item being picked up will replace the one that was in hand at the time of selection. For example, if you pick up a Desert Eagle while holding a knife, the knife will change to Desert Eagle (since the Desert Eagle has a higher overall priority value than the knife):
class'Single'.default.GroupOffset = 1;
1 - General priority of a given item.
- Weight. Typically, a weapon such as a knife has zero weight:
class'Single'.default.Weight = 0;
0 indicates that the weight of the item is zero.
- Possibility of selling/throwing an item out of inventory. By default, standard equipment items (knife, gun, syringe and welding machine) cannot be dropped or sold:
class'Single'.default.bKFNeverThrow = true;
If value = true, then the item cannot be thrown away or sold. Otherwise (i.e. = false) - it can be sold or thrown away.
---
This guide is a free translation of an article by Benjamin, to whom many thanks are due.
Author: Kiyo