Skip to content

Scripts

Greg edited this page Nov 24, 2025 · 10 revisions

Scripts are the backbone of content in Void they allow you to easily attach code to events that occur within the game engine. A script is any Kotlin class within the game module that implements the Script interface.

Anything registered in init is called when the server starts.

Example

class Cows : Script {
    init {
        npcSpawn("cow") {
            softTimers.start("eat_grass")
        }
    }
}

Note

See Event Handlers to learn about npcSpawn and other ways to write content.

Creating a script

In IntelliJ right click the directory where you'd like to place to create a kotlin file (Shortcut: Alt + Insert)

Screenshot 2024-02-21 204031

Enter the class name and select the Class option

image

A class will be created:

image

Now you can extend the Script interface and add an init function

image

Now you can write your content using event handlers // TODO

That's it! Scripts are discovered automatically next time your run the server.

Next up: adding event handlers

Notes

  • Keep scripts focused to one entity or one behaviour if an entity has a lot of options
  • Make sure scripts are located in the content. package (unless otherwise specified in properties)
  • Scripts are organised by location first, by type second

Troubleshooting

It's possible script detection fails and a deleted or moved script can't be found. If this occurs you'll see a startup error like this:

ERROR [ContentLoader] Failed to load script: content.area.misthalin.lumbridge.farm.Cow
java.lang.ClassNotFoundException: content.area.misthalin.lumbridge.farm.Cow
	at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:641)
	at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188)
	at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:525)
	at java.base/java.lang.Class.forName0(Native Method)
	at java.base/java.lang.Class.forName(Class.java:413)
	at java.base/java.lang.Class.forName(Class.java:404)
	at ContentLoader.loadScript(ContentLoader.kt:54)
	at ContentLoader.load(ContentLoader.kt:26)
	at Main.preload(Main.kt:102)
	at Main.main(Main.kt:56)
ERROR [ContentLoader] If the file exists make sure the scripts package is correct.
ERROR [ContentLoader] If the file has been deleted try running 'gradle cleanScriptMetadata'.
ERROR [ContentLoader] Otherwise make sure the return type is written explicitly.

You can fix this by running

gradle collectSourcePaths
./gradlew collectSourcePaths

Or manually deleting the scripts.txt file in game/src/main/resources/

Clone this wiki locally