Welcome to the Sims 4's API Documentation.
This is a work in progress...
Recent Changes
How to compile ts4script files Manually
ts4script files are nothing more than simple archives containing compiled python 3.7 files.
How to compile python 3.7 files
python.exe -m py_compile path_to_your_python_file.py
Packaging your ts4script file
Compile your python file (or don't, sims recognizes python files if they're packaged).
Use archive software to create a zip file containing your python file.
Rename your archive to yourmodname.ts4script
Move yourmodname.ts4script to you Sims 4 mods folder.
How to compile ts4script files Automatically
This guide assumes that you're using Matroska's Mod Compiler.
Installing MMC
Make sure python 3.7 is installed and set as default.
pip install virtualenv colorama
python mmc.py (or) mmc.exe
Creating and Compiling a Mod
Create a new mod using the C command.
Give your mod a name, then press enter.
Enter your Mod's number, then press enter.
Installing other Modules
MMC has the ability to "patch" python modules to make them compatibile with Sims 4
[This is done automatically when compiling the mod]
Initiate Virtualenv with the M command.
Enter your mod's number.
pip install any modules.
Use the exit command to return to the main menu.
Installing other Modules
MMC has the ability to "patch" python modules to make them compatibile with Sims 4.
Initiate Virtualenv with the M command.
Enter your mod's number.
pip install any modules.
Use the exit command to return to the main menu.
Compiling your mod
Use the C command to compile your mod.
Run The Sims 4 to test it. No need to move any files around.
Debug Mode
Debug can be used if you want to add your source code files to the mod.
This is mainly for testing reasons.
You can enable debug mode with the D command.
Hello World
from sims4.commands import Command, CommandType, CheatOutput
@Command('hello', command_type=CommandType.Live)
def sayhello(_connection=None):
output = CheatOutput(_connection)
output('Hello, world!')
Running Threaded (looping) Mods
Sometimes a mod needs run in a loop. This is a real issue for The Sims 4,
and often ends with headaches on loading screen/game boot loops.
Thankfully, Sims 4 has a built-in threading module.
Here's how to use it properly.
(Credit:
MatroSka ,
Pollyetta )
from threading import Thread
# Import sims' threading module
def looping_function():
"""
Any code you want to run in a loop
should be placed here
"""
pass
x = Thread(target=looping_function)
"""
create a new thread object, the target
should be the looping function.
"""
x.setDaemon(True)
"""
Setting your thread object as a daemon
is the most important part.
This ensures that it closes when sims closes,
Preventing any boot loops.
"""
x.start()
# finally, start your thread.