Left 4 Dead 2

Left 4 Dead 2

63 ratings
Ubihazard’s Skin Randomizer
   
Award
Favorite
Favorited
Unfavorite
Game Content: Scripts
File Size
Posted
Updated
67.883 KB
12 Sep, 2022 @ 7:22pm
5 Jul, 2024 @ 8:17am
2 Change Notes ( view )

Subscribe to download
Ubihazard’s Skin Randomizer

Description
Local Host and Single Player only. The required addon is required.

Skin Randomizer is a VScript library addon which helps to implement True RNG weapon skins in Left 4 Dead as much realistic as possible: weapons spawn with random skins throughout the map and the skin in your hands will match the skin of the gun you picked up from the ground. And that weapon skin will also carry over to the next map, persisting across level transitions (unless you died).
  • The player who is hosting the game will benefit from all VScript-enhanced features.
  • Everyone else will use fallback RNG code: a single random skin per map restart*.

This new RNG approach is two-part: a VScript library providing enhanced features, and special RNG skins programmed to use these features. Skin Randomizer is one part of the new RNG system. In order to actually try it out, you would also need the new RNG weapon skins themselves. Only weapon skins with RNG materials specifically coded for use with Skin Randomizer will work**. For starters, two examples of such RNG skins are made available:

Technical Notes
Skin Randomizer generates random skins as you move certain distance through the level and encodes them in a console variable cl_buy_favorite_quiet. This console variable is decoded by RNG-enabled skins and a correct skin is displayed depending on weapon class.

Weapon skins made for use with Skin Randomizer use sophisticated coding to distinguish between weapon in your hands (view model), a gun on the ground (world model), and guns in other players hands. When you pick up a gun, your choice is recorded in a second console variable cl_buy_favorite_nowarn, which is also preserved across map changes. This allows to apply different skins in each case, and especially to the view model.

SR console variables are 8-digit numbers that use decimal encoding scheme for different weapon classes. Using 13584672 as an example, the encoding is as follows (from right to left):

Part
Meaning
№ of variants
2
Primary weapon (rifle, shotgun, etc.)
10 (0-9)
7
Secondary weapon (pistols, melee)
10
46
Throwables (molotov, pipe bomb, vomit jar)
100 (0-99)
58
Recovery consumables (pain pills, adrenaline)
100
3
Medkit and ammo upgrades
6 (0-5)
1
Toggle Skin Randomizer
1 or 0

This means that a primary weapon can have up to 10 skins maximum, and it’s currently using the third skin (2). The limit is much higher for throwables and consumables (100), and a medkit can have up to 6 skin variants. This is down to nature of a number format used by Left 4 Dead 2 engine internally for console variables, which is a 32-bit float, – therefore the maximum integer value is 16777215 (24-bit).

Switching Skins Manually
You can change the skin of the weapon in your hands by manually setting the cl_buy_favorite_nowarn ConVar. Using the previous example, changing 13584672 to 13584673 will result in your primary weapon using the 4th skin, provided the total number of skins it has is at least four.

Known Issues
  • Very rarely the skin in your hands will flicker when moving fast across some stairs. This is because the VMT code that distinguishes between view and world models depends on proximity values reported by the game engine, and the calculations cannot be made 100% accurate.
  • Very rarely the weapon that you obtained through cheats (give commands) will fail to change its skin through cl_buy_favorite_nowarn.

Notes
Built using excellent VSLU by Sw1ft. Also using VSLib by Rayman1103 for persistence.

*This addon is automatically disabled in survival and split-screen coop game modes, which means all RNG skins that depend on this addon will use fallback RNG, including player hosting the game.

**Skin Randomizer is incompatible with SYS (Select Your Skin) by Ellie because they both share the same ConVar.

Ubihazard on GitHub
Other Left 4 Dead and Source related stuff:
3 Comments
Random Mercerency 13 Jan, 2024 @ 8:43pm 
does it work with RNG models as well or just textures?
SabinyAK-19 19 Jan, 2023 @ 1:48pm 
afaik this only works for skins with alternate skins as in skins that already have a RNG sub-skin system, fox.
Luvv, Lucy 8 Jan, 2023 @ 7:28pm 
does this work with mods as well?
(will a modded skin show up)