https://medium.com/swlh/the-sims-4-modern-python-modding-project-1-random-pitch-2371b79c0bcc

Python has the ability to replace code with other code. This is an important and often easy skill that is frequently overlooked. It allows you to alter existing code in a way that wouldn’t be possible without replacing it which comes in handy with modding. This tutorial shows you how to do exactly that.

It’s worth noting that anytime you make a mod that replaces code with other code you need to tell players who download your mod about that. Replacing code means 2 mods cannot replace the same code without creating issues so players need to know this. It’s a very powerful and simple modding technique though so I urge everybody to try it out at least once.

What we’re going to do

So I began browsing through the files looking through what I want to do for this tutorial and I initially landed upon “Create A Sim” and was like, you know, I want to make some kind of Create a Sim scripted mod but after more digging I couldn’t really find what I wanted. Eventually my CAS search lead me to decide on making a voice mod and from there a voice pitch mod.

Now you can already change the voice pitches up with the tuning files, I wanted to do something you couldn’t do in tuning files so I settled on pitch randomization. It was perfect for python, next I was hoping it would be simple.

Make sure you start at part 1

The projects here assume your up-to-speed on how to mod for the Sims 4 using python scripting which I already covered in part 1 & part 2.

I needed to track down which file to hook into

Exactly which file and code was it that I needed to work with? What code control the voice pitch for each of the sims? Tracking it down wasn’t easy as it normally isn’t.

My first guess was audio.voice.voice_pitch because it makes the most sense and actually wasted about 3 hours before I realized the file isn’t the right file. I went through a ton of debugging and frustration figuring that out. I’m not sure what the file is used for, all I know is the code inside the file is never called or I never witnessed it being called.

Eventually I went back to the drawing board and did some more digging around and that’s when my discovery lead to some interesting results. distributor.ops.

I don’t fully understand it but when the game needs to do stuff it forwards whatever that is to the “distributor” which acts like a message board from what I can tell. Code sends “messages” all over the place to the “message board” and the “message board” intelligently sorts everything out, prioritizes it, and makes it happen. This could be anything from a sim speaking, to music, to light color, and even certain sim states like sleeping.

Now I might have misunderstood some parts of it, this is just a working hypothesis. Another thing I noticed is code is only called for each sim on the lot generally only once for efficiency reasons which was interesting and also not very message board like.

Getting our own copy of the code

The file is huge with many classes but inside the file is one particular class called “SetVoicePitch” which I’m presuming represents the ability for code to set or change the pitch of something or to use a certain pitch when playing speech.