A Source SDK 2013 fork with automatically generated bindings for Python 3. The aim of these bindings is to have a (semi) safe Python environment of Source Engine to play around with. For a better idea of what these bindings offer, check out the examples directory.
These automatic bindings were originally made for Lambda Wars mod. Also see the Python folder of this for more examples of what is possible (most game code is written in Python!).
Please let me know if you have any issues. Pull requests are welcome too!
Currently tested on Windows (VS2013 Community Update 5) and OSX (XCode 7.3) only:
-
Open games.sln or games.xproj and compile. For OSX, you might need to change the projects sdk.
-
Start mp/game/PySource and load a map
-
Test Python by entering one of the following commands:
spy print('Hello Source') spy print(UTIL_PlayerByIndex(1).GetPlayerName())
Examples can be found in the Python game directory examples. These examples cover the Your First Entity page from VDC among others.
spy - Evaluates a Python string on the server
cpy - Evaluates a Python string on the client
PySource makes use of castxml, pygccxml and pyplusplus to generate Boost Python bindings. You can find instructions in mp/src/srcpypp.
Open mp/src/srcpypp/settings.py and uncomment the unwanted modules. Then run in the same folder:
python3 generatemods.py -a
An updated vpc file will be generated, so after this step you need to rebuild your project files.
Most of the modules can be disabled, but the example modules will fail to import. Also the srcbuiltins module exposes Msg and Warning functions to Python, which is used to redirect stdout and stderr.
- _animation: Exposed functions from - animation.h
- _entities: Exposes most base entity classes (CBaseEntity, CBaseAnimating, etc)
- _entitiesmisc: Exposes miscellaneous bindings related to entities, like the entity list
- _gamerules: Exposes Gamerules classes. Allows creating and installing custom Gamerules on the fly.
- _gameinterface: Exposes game engine interface, user messages, ConCommands and ConVars among others.
- _input: Exposes client IInput interface and key defines.
- materials: Exposes materials related functions.
- _ndebugoverlay: Exposes NDebugOverlay functions.
- _particles: Exposed Particle system related functions, like DispatchParticleEffect.
- _physics: Exposed IPhysicsObject and related.
- _sound: Exposes sound engine interface and related.
- srcbuiltins: Exposes debug Msg functions, used for redirecting output of Python
- _steam: Exposes steam api related classes.
- _te: Exposes temporary effects/entities, client side effects and FX_ functions
- _utils: Exposes utils functions and related (e.g. UTIL_TraceLine)
- _vgui: Exposes client VGUI related classes and functions.
- _vguicontrols: Exposes client VGUI base Panel classes.
- _vmath: Exposes mathlib
- vprof: Exposes VProfiling
Note: Most of these modules are complemented by Python modules (e.g. entities)