Serious Sam 4

Serious Sam 4

Not enough ratings
Universal Ammo Counter
   
Award
Favorite
Favorited
Unfavorite
File Size
Posted
Updated
22.917 MB
1 Feb, 2023 @ 8:56am
9 Feb, 2023 @ 12:49am
2 Change Notes ( view )

Subscribe to download
Universal Ammo Counter

Description
[Content/SeriousSam4/Scripts/CustomWorldScripts/Script_UniversalAmmoCounter.lua]
[Content/SeriousSam4/Databases/Items/Weapons/HeavyLaserGun/HeavyLaserGunHeat_Generic.ep]

This mod provides the TLH digital ammo counter script and mesh for modders to use for their own custom weapons. The Heavy Laser Gun from TLH is also included as an example.

Adding an ammo counter to your custom weapons should be easier with this mod since the included TLH ammo counter script will automatically handle all the logic for displaying the ammo count. It's also been updated to work properly with weapons that reload as well as SS4's dual-wielding system too, so all you really need to do is add the included ammo counter mesh to your weapon viewmodel, following the instructions written below.

HOW TO USE
The ammo counter mesh (Content/SeriousSam4/Models/Weapons/AmmoCounter/Geometry/AmmoCounter_Digital_R.bmf) needs to be directly in the mesh tab of the .mdl that's set as the weapon's first-person viewmodel in your custom weapon .ep's Model parameter. There's two types of First-Person model used by SS4's weapons; the first type is the gun model directly such as the Grenade Launcher while the second type is the Arms model (usually called WeaponName_Arms.mdl) which loads the actual gun in the attachments such as the Assault Rifle.

Setting up the ammo counter is easy for the first type. Just open AmmoCounter_Digital_R.bmf, copy its polygons, then paste it in your custom weapon's .bmf via the Mesh Editor and position it to where you want it to be, and that's it. Its sole Weight Map's name is R_Weapon so if that's not the main Weight Map used by your gun mesh's body, then rename it to whatever your main gun body Weight Map is called.

It's a bit more complicated for the second type, which is the Arms type used by the Heavy Laser Gun included in this mod. This is because the Arms model doesn't have anything in its mesh config (the Mesh parameter in the model's config in the Model Editor); both the Arms model and the gun model are loaded as attachments, but the script can only access the shader modifier of the mesh in that .mdl and not any of its attachments. However, the way to implement it is more or less the same as the first type, just with the following extra steps:

1. Load AmmoCounter_Digital_R.bmf in your custom weapon's Arms model's mesh parameter.
2. Save that AmmoCounter_Digital_R.bmf under another name (for example, AmmoCounter_YourWeaponName_R.bmf) in your custom weapon model's folder so that the original AmmoCounter_Digital_R.bmf is not overwritten when you reposition the polygons later.
3. Add an attachment named FakeCounter with R_Weapon set as its Target Bone and AmmoCounter_Digital_R.mdl set as its Model Instance.
4. Select the FakeCounter attachment from the bottom right dropdown of the Model Editor viewport.
5. Move the FakeCounter attachment to where you want it to be on the gun. Make sure no animations are currently being played or else the position coordinates will be wrong later.
6. With the FakeCounter attachment selected, press Q to go into the Tools panel and copy its XYZ (position) and HPB (rotation) coordinates. If you've also changed the attachment's size, copy its Width and Height values too.
7. Go into the Mesh Editor and select the Ammo Counter polygons and open the Tools panel with Q .
8. Paste the XYZ and HPB and Width/Height values you copied from the FakeCounter attachment to here. Note that the HPB values here will always be displayed as 0 even if it's correctly changed, which is troublesome if you want to adjust its rotation again later.
9. Go back to Model Editor and tick the Hidden flag in the FakeCounter attachment's Flags parameter to make it disappear and not display alongside the real ammo counter.

If everything is done right, the ammo counter should be animated along with the weapon itself when you play an animation in the Model Editor.

This mod also supports left-hand viewmodels for dual-wielding. For custom weapons of the first type, there's usually no left-handed viewmodel specified in the weapon .ep's Left Hand Model parameter so the game will automatically use the right-handed viewmodel and mirror it. This would normally mean that the left-hand model will end up having its ammo counter mirrored, but thankfully the script gets around this by automatically mirroring the ammo counter digits for left-hand weapons so they'll display correctly.

For custom weapons of the second type, there's usually a separate left-handed viewmodel specified in the weapon .ep's Left Hand Model parameter (usually called WeaponName_Arms_L.mdl). Since it's another Arms model, you will need to set up the Ammo Counter mesh directly in the Mesh parameter of the model following the same 9 steps from above. The only difference this time is that instead of using AmmoCounter_Digital_R.bmf, you should use AmmoCounter_Digital_L.bmf so that the ammo counter digits will display correctly when the script automatically mirrors it. AmmoCounter_Digital_L.bmf's Weight Map name is L_Weapon so that it's animated correctly by the L_Weapon bone, but you should still use R_Weapon as the Target Bone for the FakeCounter attachment in the Arms_L.mdl because the L_Weapon bone is rotated weirdly and the mesh won't appear correctly if you copy and paste the XYZHPB values from a FakeCounter attachment that's using L_Weapon as its Target Bone. As with before, make sure the first thing you do is resave AmmoCounter_Digital_L.bmf to AmmoCounter_YourWeaponName_L.bmf in your custom weapon model's folder so that the original AmmoCounter_Digital_L.bmf is not overwritten later.

Note that this mod only supports ammo type that have a max ammo capacity of up to 999 because it can only display up to 3 digits. This means the ammo counter will display ammo count incorrectly for weapons that can have 4-digit ammo count like SS4's Minigun which has a max ammo count of 1000.



Credits
Croteam - Ammo Counter script and assets from TLH, Heavy Laser Gun assets from TLH