Skip to content

Modding

Ruthger Dijt edited this page Apr 6, 2022 · 9 revisions

Modding

Modding support has been added since version >=1.2, the main purpose of modding smce-gd at the moment is to add new environments without having to completely fork the project. While other things are possible, it's not recommended.

The basics

Mods are godot .pck files, to make a mod you have to create a new project with the godot editor and create a gdscript file in res://mods/your_mod_here.gd, inherting from Reference.

2 things are expected to be present in the class:

  1. mod_name variable of type String
  2. init function that takes a single parameter

Which translates to this:

extends Reference

var mod_name: String = "example"

func init(global) -> void:
	print("Hello World!")

Then create an export profile, but only export the pck Export PCK/Zip.

SMCE-gd looks for loadable pck files in {smce user_dir}/mods. For faster development it's suggested to directly export your mod to the mods folder.

you can find the user directory in these places:
Windows: %APPDATA%\Godot\app_userdata\SMCE
macOS: ~/Library/Application Support/Godot/SMCE
Linux: ~/.local/share/godot/SMCE

General warning

Mod loading works on the premise of overwriting the virtual filesystem of smce-gd, so be real careful of accidentally overwriting any native files with your mod. The best way of avoiding this is to put all your content inside a uniquely named folder.

Example project

https://github.com/RuthgerD/smcegd_mod_example

Making a custom environment

The parameters that gets passed to your mod's init function allows you to register new environments like this:

global.register_environment("example/Example", load("res://src/environments/example/Example.tscn"))

basically register_environment(name: String, scene: PackedScene).

Thats it, once registered the environment will be accesible for use in the profile menu (in a fresh profile open the top left menu, there you have a drop down to switch worlds).

Environment expectations

Camera position

When an evironment is loaded SMCE-gd checks if the root node has a function called init_cam_pos() -> Transform, if it does it will call it to query the initial position of where the camera is supposed to be.

It's suggested to put in a dummy camera into your scene and implement it like this:

func init_cam_pos() -> Transform:
	return $CamPosition.global_transform

Car spawn position (>=v1.3.3)

In the same way as the camera position, smce-gd will look for the get_spawn_position(hint: String) -> Transform method, This works the same as the camera position query, with a notable exception of the extra argument passed in; hint.

This hint string will allow you to differentiate between certain objects and can affect the spawn location you may want to return. example:

func get_spawn_position(hint: String) -> Transform:
	match hint:
		"debug_vehicle": return $DebugVehicleSpawn.global_transform
		_: return $VehicleSpawn.global_transform

If not defined Transform(Basis(),Vector(0,3,0)) will be used instead.

Custom vehicle (>=v1.3)

Vehicle modding works in the same way as a custom environement, you can register a vehicle with global.register_vehicle(name, scene).

See the example project for a template. and see here on how to use the custom vehicle.

TODO: write expectations