Left 4 Dead 2

Left 4 Dead 2

229 ratings
[Obsolete] RNG made simple
By Ellie
This Guide contains everything about RNG but made more simple : it provides VERY simple and up to date instructions to implement RNG textures in your addons. If you are a modder and want to add a nice touch to one of your addons, you're at the right place :D
   
Award
Favorite
Favorited
Unfavorite
RNG in 10 seconds
You want to add RNG in your mod very quickly ? Read this instead !
https://steamoss.com/sharedfiles/filedetails/?id=2389582650
⛔️ WARNING ⛔️


RNG is now included in the very powerful SYS System that brings new features and updated code.
https://steamoss.com/sharedfiles/filedetails/?id=2303221834 https://steamoss.com/sharedfiles/filedetails/?id=2309371158
[General Information]
Difficulty :

Short description : Allows Modders to make it so that (at least) each map, the texture on a specific model will be different and randomly selected among the ones contained in the different frames of a VTF (texture) file.

Time to implement : From 10 seconds to 5 minutes

Required before starting
  1. An already set up mod with all its VMT and VTF
  2. A VTF with multiple frames that are all the skins for the corresponding VMT
  3. The VTFEdit software
Minimal skills :
  • Knowing what a VMT and VTF file is
  • Knowing how to edit a VMT file
  • Knowing how to create a VTF with multiple frames
Recommanded skills :
  • Basic knowledge of a standard graphics software (Photoshop, Gimp, Substance painter)
What is RNG ?
RNG stands for "Random Number Generation". It basically allows you to make the texture of an item change every map (or for every Infected / Survivor). Needless to say it brings interesting stuff into the game :). There are a lot of mods for L4D2 that uses that, you can check mines here

http://steamoss.com/sharedfiles/filedetails/?id=485028778
Starting Questions
The goal of this section is to identify what sections you'll need to do in order to implement RNG Textures. Proceed in order and answer these questions :

Question 0 :
Do you know how to create a VTF with Multiple Frames and set it as your $basetexture? (these will be all the different skins for your RNG mod)
YesDo that and proceed to the next question
No ▶ Go read my guide on the subject (Animated Textures, Step 1-5)

Question 1 :
Do you want RNG on a Melee weapon ?
Yes ▶ Proceed to the next question but do #MELEE-START at the very start and #MELEE-END at the very end
No ▶ Proceed to the next question

Question 2 :
Are you already annoyed by these questions?
Yes ▶ DO #3
No ▶ Proceed to the next question

Question 3 :
Do you have multiple different $bumpmap?
Yes ▶ Proceed to the next question, but remember to do #5 at the very end
No / Don't know what this is ▶ Proceed to the next question

Question 4 :
Do you want to make a RNG Mod for a survivor or an infected (original charger/tank excepted)? OR You are making a mod (any infected) using мяFunreal's Seperated Attire Material: Infected mod ?
Yes ▶ DO #1
No ▶ Proceed to the next question

Question 5 :
Do you want to have more than 30 different skins ?
Yes ▶ Proceed to the next question, but remember to do #4 at the end.
No ▶ Proceed to the next question.

Question 6 :
Do you want to minimize the blinking and feel able to make a division on a calculator?
Yes ▶ Proceed to the next question, but remember to do #4 at the end.
No ▶ Proceed to the next question.

Question 7 :
Can you carry/take/use the thing you want to RNG (gun / jerrycan / item / melee weapon etc.) ?
Yes ▶ Proceed to the next question.
No (+Charger/Tank) ▶ DO #3

Question 8 :
Do you want multiple skins within the same map but with no match between the one you pick and the one you get?
Yes ▶ DO #RR and do NOT do #4
No ▶ Proceed to next question

Question 9 :
Do you feel able to do very easy code edit?
Yes ▶ DO #0 and do NOT do #4
No ▶ DO #2
#MELEE-START
See that thing in your VMT ? Delete it
Proxies { BloodyHands { resultVar $detailAmount } Equals { srcVar1 $detailAmount resultVar $detailblendfactor } }


Note : If you DON'T see that thing in your VMT, you are not working on a Melee Weapon, therefore, do NOT do #MELEE-END.


#RR
Step 1 : Copy this in the VMT(s) that needs to have RNG
Proxies { EntityRandom { scale "@@" resultVar "$frame" } // [###] }
Step 2 : Replace the @@ by the number of different designs that you have. You have 10 different skins ? Put 10 instead of @@
#0
Step 1 : Copy this in the VMT(s) that needs to have RNG
$stock 1000 $fh 500 $rand 0 $zero 0 Proxies { EntityRandom { scale "@@" resultVar "$rand" } LessOrEqual { LessEqualVar "$stock" greaterVar "$rand" srcVar1 "$stock" srcVar2 "$fh" resultVar "$stock" } LessOrEqual { LessEqualVar "$frame" greaterVar "$stock" srcVar1 "$stock" srcVar2 "$zero" resultVar "$frame" } // [###] }
Step 2 : Replace the @@ by the number of different designs that you have. You have 10 different skins ? Put 10 instead of @@
#1
Step 1 : Copy this in the VMT(s) that needs to have RNG
$rand 0 $zero 0 Proxies { EntityRandom { scale "@@" resultVar "$rand" } LessOrEqual { LessEqualVar "$frame" greaterVar "$rand" srcVar1 "$rand" srcVar2 "$zero" resultVar "$frame" } // [###] }
Step 2 : Replace the @@ by the number of different designs that you have. You have 10 different skins ? Put 10 instead of @@
#2
Copy this in the VMT(s) that needs to have RNG
Click here[pastebin.com] for PasteBin Mirror of the Code
$one 1 $zero 0 $mo "-1" $fh 500 $timestop 1000 $randstop 0 $storeframe 1000 $weareinstoretime 0 $wecanstore 0 $dostore 0 $rngtime 0 $rngtimeinvert 0 $rngtimecorr 0 $realrngtime 0 $er 0 ////////////////////////////////////////////////////////////////////////////////////////// // MMA RNG ($basetexture) ////////////////////////////////////////////////////////////////////////////////////////// Proxies { MaterialModifyAnimated { animatedtexturevar "$basetexture" animatedtextureframenumvar "$frame" animatedtextureframerate "30" } UniformNoise { minVal "0" maxVal "1" resultVar "$randstop" } LessOrEqual { LessEqualVar "$timestop" greaterVar "$randstop" srcVar1 "$timestop" srcVar2 "$fh" resultVar "$timestop" } EntityRandom { scale "1" resultVar "$er" } LinearRamp { rate "1" resultVar "$rngtime" } Multiply { srcVar1 "$mo" srcVar2 "$rngtime" resultVar "$rngtimeinvert" } LessOrEqual { LessEqualVar "$rngtimeinvert" greaterVar "$rngtimecorr" srcVar1 "$er" srcVar2 "$zero" resultVar "$rngtimecorr" } Add { srcVar1 "$rngtime" srcVar2 "$rngtimecorr" resultVar "$realrngtime" } LessOrEqual { LessEqualVar "$zero" greaterVar "$one" srcVar1 "$realrngtime" srcVar2 "$timestop" resultVar "$weareinstoretime" } LessOrEqual { LessEqualVar "$zero" greaterVar "$one" srcVar1 "$storeframe" srcVar2 "$fh" resultVar "$wecanstore" } Multiply { srcVar1 "$wecanstore" srcVar2 "$weareinstoretime" resultVar "$dostore" } LessOrEqual { LessEqualVar "$storeframe" greaterVar "$frame" srcVar1 "$dostore" srcVar2 "$zero" resultVar "$storeframe" } LessOrEqual { LessEqualVar "$frame" greaterVar "$storeframe" srcVar1 "$weareinstoretime" srcVar2 "$zero" resultVar "$frame" } // [###] }
#3
Copy this in the VMT(s) that needs to have RNG
Click here[pastebin.com] for PasteBin Mirror of the Code
$one 1 $zero 0 $mo "-1" $fh 500 $timestop 1000 $randstop 0 $storeframe 1000 $weareinstoretime 0 $wecanstore 0 $dostore 0 $rngtime 0 $rngtimeinvert 0 $rngtimecorr 0 $realrngtime 0 $pos "[0 0 0]" $poscheck "[0 0 0]" ////////////////////////////////////////////////////////////////////////////////////////// // MMA RNG ($basetexture) ////////////////////////////////////////////////////////////////////////////////////////// Proxies { MaterialModifyAnimated { animatedtexturevar "$basetexture" animatedtextureframenumvar "$frame" animatedtextureframerate "30" } UniformNoise { minVal "0" maxVal "1" resultVar "$randstop" } LessOrEqual { LessEqualVar "$timestop" greaterVar "$randstop" srcVar1 "$timestop" srcVar2 "$fh" resultVar "$timestop" } PlayerPosition { scale "1" resultVar "$pos" } Abs { srcVar1 "$pos" resultVar "$poscheck" } LinearRamp { rate "1" resultVar "$rngtime" } Multiply { srcVar1 "$mo" srcVar2 "$rngtime" resultVar "$rngtimeinvert" } LessOrEqual { LessEqualVar "$rngtimeinvert" greaterVar "$rngtimecorr" srcVar1 "$poscheck" srcVar2 "$zero" resultVar "$rngtimecorr" } Add { srcVar1 "$rngtime" srcVar2 "$rngtimecorr" resultVar "$realrngtime" } LessOrEqual { LessEqualVar "$zero" greaterVar "$one" srcVar1 "$realrngtime" srcVar2 "$timestop" resultVar "$weareinstoretime" } LessOrEqual { LessEqualVar "$zero" greaterVar "$one" srcVar1 "$storeframe" srcVar2 "$fh" resultVar "$wecanstore" } Multiply { srcVar1 "$wecanstore" srcVar2 "$weareinstoretime" resultVar "$dostore" } LessOrEqual { LessEqualVar "$storeframe" greaterVar "$frame" srcVar1 "$dostore" srcVar2 "$zero" resultVar "$storeframe" } LessOrEqual { LessEqualVar "$frame" greaterVar "$storeframe" srcVar1 "$weareinstoretime" srcVar2 "$zero" resultVar "$frame" } // [###] }
#4
See this part of the code at the beginning ?
UniformNoise { minVal "0" maxVal "1" resultVar "$randstop" }
Modify the "1" into your number of designs divided by 28

Example : You have 64 designs, 64/28 = 2.285, put 2.285 between the brackets, like this :
UniformNoise { minVal "0" maxVal "2.285" resultVar "$randstop" }
#5
See that thing at the end of your code ?
// [###]
Replace it with this :
Equals { srcVar1 "$frame" resultVar "$bumpframe" }
#MELEE-END
WARNING ▶ This step is to add the "Blood" effect when you kill zombies with your Melee Weapon. Ignore this step (even if you had to do it) if you do not want blood on your melee weapon. (Of if it's too hard for you)

Step 1 : See that thing at the end of your VMT ?
// [###]

Replace it with this
BloodyHands { resultVar $detailAmount } Equals { srcVar1 $detailAmount resultVar $detailblendfactor }
Note : If you replaced the [###] already because you did #5, just put that below what you just copied when you did #5.

Step 2 : Look at the top part of the VMT, where there are all the variables (things with $) Do you see this somewhere ? If no, ADD it.
$detail "models/infected/hunter/hunter_01_detail.vtf" $detailscale "1.75" $detailblendfactor .001 $detailblendmode 0 $detailAmount 0

Below, here's an example to see where the code above should be, as well as the proxies block :


Step 3 : If you have another VMT for your melee weapon, that has no RNG, make sure you have this (add it if you have not) in it :
$detail "models/infected/hunter/hunter_01_detail.vtf" $detailscale "1.75" $detailblendfactor .001 $detailblendmode 0 $detailAmount 0 Proxies { BloodyHands { resultVar $detailAmount } Equals { srcVar1 $detailAmount resultVar $detailblendfactor } }

Help ! I have a problem.
Troubleshooting 1 :
Does your game crashes to Desktop when you approach the thing you used RNG on ?
Yes ▶ You needed to do #3, redo the thing using #3

Troubleshooting 2 :
Sometimes, I see an all-black thing that persists even if I wait 10sec ?
Yes ▶ You did #RR, #0 or #1 and put a too high number when you replaced the @@

Troubleshooting 3 :
Sometimes, I see the texture blinking
Yes ▶ Do #4 if you haven't already done it

Troubleshooting 4 :
The designs keep changing at a fast pace
Yes ▶ You probably did #2 on something that doesn't support it, redo it but use #3 instead.

Troubleshooting 5 :
The different parts of my object do not snychronise together
Yes ▶ Do #0
If it crashes the game, there's no "simple" fix for that, contact me.

Troubleshooting 6 :
My object is "invisible" (I only see white edges of it)
Yes ▶ You replaced the whole VMT with the code instead of putting the code in the VMT, OR the first word in your VMT is "LightMappedGeneric" where it should be "VertexLitGeneric"

Troubleshooting 7 :
I have another problem
Yes ▶ Come and ask your question in a new topic here, I'd be happy to help you about it.
Alternatively ▶ DO #3 instead and see if it works
85 Comments
AEA- 27 Nov, 2023 @ 6:26am 
weapon rng night light not work image help
Pyrex Picasso 5 Jun, 2022 @ 6:57pm 
is there a way to use phong exponent textures with these?
฿ØⱠ₮Ø₭¹⁷³ึ 21 Apr, 2021 @ 8:38pm 
I just found out that I can change it with SYS, I'm going to try
Ellie  [author] 21 Apr, 2021 @ 10:56am 
@bonnie : All these techniques do not require model edits. Although, I recommend you check the updated versions of the codes here : https://steamoss.com/sharedfiles/filedetails/?id=2389582650 . For map objects, 🔶 should be used. If you see the textures changing, try setting $distancePerFrame higher. If you want to use the techniques in this Guide here, you need #0.
Ellie  [author] 21 Apr, 2021 @ 10:52am 
@฿ØⱠ₮Ø₭¹⁷³ : Sadly no, not as far as I know. The only way is this "Model RNG" thing.
HAPPY KEEPSMILE 20 Apr, 2021 @ 11:00pm 
Hi, I was wondering if one of these methods work for literal textures, like the ones you put on brushes? I'm making my own campaign and I wanna do some randomized billboards, signs, buildings, graffiti, etc. but I don't want to create or edit models. Is that possible using these techniques?
฿ØⱠ₮Ø₭¹⁷³ึ 20 Apr, 2021 @ 10:45pm 
is there a way to randomize survivor bodygroups and make it work online? like how to make the hat change to another?
Matakomi 27 Feb, 2021 @ 3:09pm 
Thanks a lot, Ellie! If I make it, I'll give you credits in the mod's page! ^_^.
Ellie  [author] 27 Feb, 2021 @ 12:16pm 
@Matakomi: Maybe try to reverse engineer this mod: https://steamoss.com/sharedfiles/filedetails/?id=1741257473 x), it's that RNG Music tank mod I had seen years ago.
Matakomi 26 Feb, 2021 @ 12:58pm 
Thanks for your reply, Ellie! ^_^ Working locally would do for me, since is a concert mod I want to make, adding more than the 4 tracks played, with about 10 tracks.