-
Notifications
You must be signed in to change notification settings - Fork 49
Scripts
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.
class Cows : Script {
init {
npcSpawn("cow") {
softTimers.start("eat_grass")
}
}
}Note
See Event Handlers to learn about npcSpawn and other ways to write content.
In IntelliJ right click the directory where you'd like to place to create a kotlin file (Shortcut: Alt + Insert)

Enter the class name and select the Class option
A class will be created:
Now you can extend the Script interface and add an init function
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
- 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
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 collectSourcePathsOr manually deleting the scripts.txt file in game/src/main/resources/