Hi there! You are currently browsing as a guest. Why not create an account? Then you get less ads, can thank creators, post feedback, keep a list of your favourites, and more!
Test Subject
Original Poster
#1 Old 7th Sep 2014 at 2:24 PM Last edited by justJones : 6th May 2018 at 11:19 PM.
Default How to change the simulation clock speed by changing maxis scripts
Hello everybody! This is going to be a quick tutorial on how to change the clock speed of the simulation by changing the built-in maxis scripts.

You will need...
  • Python v3.3.3
  • The Sims 4
  • A text editor (I use Notepad++, but you can use notepad or anything)
  • This python script
  • A little bit of magic, and a drop of imagination

Installing & Configuring Python
Once you've downloaded the python release, the first step is to install it. For the purposes of this tutorial, I'm going to assume you've installed it to C:\Python33\. When it's completely installed, you should add an entry to your system's path variable. To do this, follow the steps below.
  1. Open the start menu and search for the word "environment"
  2. Click on "Edit environment variables for your account"
  3. Under "System Variables," look for the entry named "Path"
  4. Click it, then click on "Edit..."
  5. It should look something like this: "C:\folder1\;C:\otherfolder\;C:\blabla;"
  6. Just add another entry pointing to your installation directory. Once you've done that it should look something like "C:\folder1\;C:\otherfolder\;C:\blabla;C:\Python33\"
  7. Click OK, then OK.
Now that your python environment is configured, we can begin with the decompiling.

Decompiling the Scripts
For this tutorial, I'm gonna create a folder called "TS4 modding". Copy the .zip files in the game's "Data\Simulation\Gameplay\" folder into your TS4 modding folder, and extract each of them into their own folders. You should now have three sub folders, one called "base," "core," and "simulation".

Next, you should place the unpyc3.py file into this TS4 modding folder. Create a .bat file too with the following contents:
Code:
@echo off
for /r %%i in (*) do unpyc3.py "%%i" > %%i.py


Now, run the .bat file. You'll see some errors, but that's okay. It may take a while depending on the speed of your computer, but it should proceed to decompile all of the .pyo files so that you can edit them later on. Once it's finished, you can move on to the next step.

Editing the Scripts
So, we want to change the simulation's clock speed. The script that controls this is called "clock.pyo". It's in the "simulation" folder. Open the newly created "clock.pyo.py" file in your text editor and move to line 265, where you'll find this code.
Code:
    def _clock_speed_to_scale(self, clock_speed):
        if clock_speed == ClockSpeedMode.PAUSED:
            return self.PAUSED_SPEED_MULTIPLIER
        if clock_speed == ClockSpeedMode.NORMAL:
            return self.NORMAL_SPEED_MULTIPLIER
        if clock_speed == ClockSpeedMode.SPEED2:
            return speed_two_multiplier(self.clock_speed_multiplier_type)
        if clock_speed == ClockSpeedMode.SPEED3:
            if services.get_super_speed_three_service().super_speed_three_active:
                return ClockSpeedMultipliers.super_speed_three_multiplier(self.clock_speed_multiplier_type)
            return ClockSpeedMultipliers.speed_three_multiplier(self.clock_speed_multiplier_type)
        if clock_speed == ClockSpeedMode.INTERACTION_STARTUP_SPEED:
            return ClockSpeedMultipliers.get_interaction_startup_speed_multiplier()

I'm not going to go into detail as to what this does or what it changes, as it's pretty self evident. We want to change this so that it looks like this
Code:
    def _clock_speed_to_scale(self, clock_speed):
        if clock_speed == ClockSpeedMode.PAUSED:
            return self.PAUSED_SPEED_MULTIPLIER
        if clock_speed == ClockSpeedMode.NORMAL:
            return self.NORMAL_SPEED_MULTIPLIER
        if clock_speed == ClockSpeedMode.SPEED2:
            return 5
        if clock_speed == ClockSpeedMode.SPEED3:
            return 10
        if clock_speed == ClockSpeedMode.INTERACTION_STARTUP_SPEED:
            return 20

Once you've done that, save the file. Now, we have to compile it and deploy it into the game.

Recompiling and Deploying the edit
Open up your command line (Windows Key + R and type in "cmd", or search for "cmd"), and type in
Code:
cd (path to your TS4 Modding directory)

This will change the directory before the > character to your TS4 modding directory. Now type in
Code:
cd simulation

and then
Code:
python -m py_compile "clock.pyo.py"

This will compile the script and place a sub-folder called "__pycache__" inside of the \simulation\ folder. Inside this folder is where you'll find the compiled script, named "clock.cpython-33.pyc". To actually deploy this into the game, open the game's simulation.zip file and delete the already existing "clock.pyo" file inside of it. Then, rename "clock.cpython-33.pyc" to just "clock.pyc", and copy this into the simulation.zip file. Now when you run the game, the 2 and 3 speeds will be much faster.

It should be easy enough to figure out where everything else is hiding in the scripts and edit them. You can also create entirely new scripts and put the compiled file into one of the .zip files. The game will still run them.

Happy scripting!
4 users say thanks for this. (Who?)
Advertisement
Test Subject
#2 Old 7th Sep 2014 at 4:15 PM Last edited by Kodek : 7th Sep 2014 at 5:03 PM.
Hey jcgurango, thanks for tutorial, it will help a lot of people to understand how to decompile and compile python files.
If someone have empty files after decompilation, make sure you are using Python 3.3.3, newer versions may haves issues.

BTW, I recommend to use Shift+RMB in directory and open console instead of use 'cd' commands in console, it's a little bit quicker.
Test Subject
#3 Old 7th Sep 2014 at 5:10 PM
There is a problem on the speed change ...

There's something related with the clock-speed and the simulation speed sincronism..

If u're not using the default speeds ... then this sincronism keep getting far and far away.... and at some point .... the game goes crazy because of that ... which means that u get stucked on super-speed events (like work or sleeping)

If you don't change it by tunning (how it is supposed to be done) the math of the rates simulation/clock gets wrong resulting in this bug at some point....

I'm pretty sure its because of the sincronism... because when i've used the speed of 60... the bug happend REALLY fast... (the simulation on speed 60, after turning back to regular speed(1), caused the clock to go back half or or soo)...

Same thing happend to lower speeds ... but it took a few game days....

I'm looking for a way to avoid this bug ... but ... i'm not finding any...
Test Subject
#4 Old 8th Sep 2014 at 4:51 AM
I'm getting a "no such file or directory" error when I'm trying to recompile. What am I doing wrong?
Test Subject
#5 Old 9th Sep 2014 at 5:24 AM
I'm using python 3.3.3 and the decompiled files come up with "USAGE: C:\Users\bilba_000\Desktop\TS4 modding\unpyc3.py <filename.pyc>" in Word. Am I doing something wrong? I followed the instructions as much as I could. I've done this 10 times already...
Test Subject
#6 Old 9th Sep 2014 at 1:30 PM Last edited by Simser der Deutschen : 9th Sep 2014 at 2:25 PM.
I've done and installed all like you've described it, but I got the error in the cmd "Access denied" and the created *.pyo.py files are empty. Nothing more happens.

Is it possible, that you upload the decompiled Python files? (Or is this not allowed because of copyright, I don't know?)

[Update 1]
I got it work, I don't know why. It creates .py files and the cmd prints no errors. But now, the content of every .py file is the same as for decemberfriend:
USAGE: C:\TS4 Modding\unpyc3.py <filename.pyc>
[Update 2]
Now I got all work! @ decemberfriend
I thought, that maybe another program cause complications. So I tried the same way in an clean install virtual Windows 8.1 and it worked. So all of you, who got some errors: Try to execute the de-/compilation on another pc or a virtual pc. (I use Hyper-V)
Test Subject
#7 Old 9th Sep 2014 at 4:49 PM
Uihhh
I found a cool folder in the decompiled python scripts:

But it's an empty folder :/
Screenshots
Test Subject
#8 Old 12th Sep 2014 at 6:01 AM Last edited by Simsupermom : 12th Sep 2014 at 6:45 AM.
Back on track
followed up until I tried to click edit, it was gray, like it is refusing to allow?? Here is a screen shot.
.

UPDATE: So I had to go in another way, I had to
My Computer ‣ Properties ‣ Advanced ‣ Environment Variables
Then add the entry point! Not sure why but in case someone else is a newbie that was the issue. The other way just grays out the edit button. Back on track!
Hope I can do this!
Screenshots
Test Subject
#9 Old 12th Sep 2014 at 6:34 AM
Quote: Originally posted by Simsupermom
followed up until I tried to click edit, it was gray, like it is refusing to allow?? Here is a screen shot.


I think I know why it's grayed. It's because there are two environment variables menus:
The first can be edited without administrator rights, it's named "User Environment Variables" and it seems to be the same as your screenshot.
To open this one, you need to go to the Control Panel, "Useraccounts" and "Change own environment variables" (I'm from germany, the text may vary in english):


The second one is the "System Environment Variables" and needs administrator rights. They can be edited while going to the Control Panel, "System", "Advanced System Settings", "Environment Variables".
Now the "Edit" button is available.
Screenshots
Test Subject
#10 Old 20th Sep 2014 at 8:16 PM
Quote: Originally posted by Simser der Deutschen
[Update 2]
Now I got all work! @ decemberfriend
I thought, that maybe another program cause complications. So I tried the same way in an clean install virtual Windows 8.1 and it worked. So all of you, who got some errors: Try to execute the de-/compilation on another pc or a virtual pc. (I use Hyper-V)


just add 'python' to the bat file to fix this. The bat file will now look like this:

@echo off
for /r %%i in (*) do python unpyc3.py "%%i" > %%i.py

Also, I was getting a syntax error for *parent on line 1654. Besides setting up your Path environment variable, make sure windows is associating the right python.exe with .py extensions (Mine was pointing to python 2.7)
Test Subject
#11 Old 12th Apr 2015 at 12:37 AM
I don't know why but the .pyo files compile to an empty .py file. What's wrong? I followed every step.

Thanks in advance.

Edit: I found the solution .
Forum Resident
#12 Old 17th Apr 2015 at 3:51 AM
Putting the mod file into my game didn't work, if i loaded a lot it just bounced back to the world select.
Test Subject
#13 Old 18th May 2015 at 1:27 AM
Quote: Originally posted by simmythesim
Putting the mod file into my game didn't work, if i loaded a lot it just bounced back to the world select.
same thing happened to me. Hope to fix it somehow
Deceased
#14 Old 20th May 2015 at 6:28 AM
This is not the best way to be doing this - far better to inject or override just the method you are changing and put it in the mods folder than to recompile the entire script with changes and put it into the game's zip files. It will just get deleted everytime the game is updated or repaired.

Also, @simmythesim - I thought you had these changes working for you with the XML tuning? That should be the safest and most EA-update-proof method of doing this?
Forum Resident
#15 Old 20th May 2015 at 7:56 AM
Quote: Originally posted by scumbumbo
This is not the best way to be doing this - far better to inject or override just the method you are changing and put it in the mods folder than to recompile the entire script with changes and put it into the game's zip files. It will just get deleted everytime the game is updated or repaired.

Also, @simmythesim - I thought you had these changes working for you with the XML tuning? That should be the safest and most EA-update-proof method of doing this?

That was a LONG time ago a while before I made the other thread, unfortunately speeding up the time multipliers causes headaches for the game, and will cause time to desynchronise and move backward when you speed up.
Deceased
#16 Old 20th May 2015 at 4:42 PM
Quote: Originally posted by simmythesim
That was a LONG time ago a while before I made the other thread, unfortunately speeding up the time multipliers causes headaches for the game, and will cause time to desynchronise and move backward when you speed up.

Interesting. I've never tried either method and assumed the XML change would work fine. There must be a calculation somewhere in the Python script that is assuming the time multipliers don't change from the defaults. Does it drift continuously, or just "jump" backwards when the speed change takes place?
Forum Resident
#17 Old 20th May 2015 at 8:16 PM Last edited by simmythesim : 20th May 2015 at 8:39 PM.
Quote: Originally posted by scumbumbo
Interesting. I've never tried either method and assumed the XML change would work fine. There must be a calculation somewhere in the Python script that is assuming the time multipliers don't change from the defaults. Does it drift continuously, or just "jump" backwards when the speed change takes place?

What happens is that time works fine, fast even, but the sims, they also move fine, until they stop, they start talking then they stop, and do it repeatedly, and then when time finally goes back to normal speed the clock goes backward. It seems to be unfixable unfortunately, as it seems to happen with no mods on lots with lots of objects or sims.

EDIT: Now with video to demonstrate time travel!
Attached files:
File Type: zip  Video.zip (3.96 MB, 39 downloads) - View custom content
Deceased
#18 Old 21st May 2015 at 7:00 AM
Thanks for the video -- that really makes it clear what's happening. Interesting problem. Any reason I could offer for why that's happening would be just a guess, but it seems most likely that the server/ui thread is getting out of sync with the client thread (the native object-code server is able to run faster than the Python scripting can keep up). Have you tried smaller speed increments to see if there's a threshold for your system that starts causing the issues?

You also may want to bounce it off the gurus on the EA technical forum and see if they have an informed reason.
Forum Resident
#19 Old 21st May 2015 at 8:42 AM Last edited by simmythesim : 21st May 2015 at 9:58 AM.
Quote: Originally posted by scumbumbo
Thanks for the video -- that really makes it clear what's happening. Interesting problem. Any reason I could offer for why that's happening would be just a guess, but it seems most likely that the server/ui thread is getting out of sync with the client thread (the native object-code server is able to run faster than the Python scripting can keep up). Have you tried smaller speed increments to see if there's a threshold for your system that starts causing the issues?

You also may want to bounce it off the gurus on the EA technical forum and see if they have an informed reason.

There is no threshold where time starts rolling back as time worked fine even with the speed mod on one sim and a small lot. However even without the mod lots with lots of sims, (player controlled or npcs, doesn't matter) time rolls back even without changing the speed,

I think a better way Maxis could handle speed is by changing the speed by the amount of sims on the lot. So, with 1 sim only, speed 3 runs faster than TS2 speed 3, but with 20 sims it would run slower than default to process those sims properly. Perhaps another mod for me to try working on I guess.
EDIT: Yes! progress on the mod is going smoothly, we'll have faster speeds that don't break the game within the next weeks or so.
Back to top