-
Notifications
You must be signed in to change notification settings - Fork 24
Scripts
Kotlin Scripts, .kts
files, are the starting point for quickly and easily writing content in Void. They remove the hassle of creating classes, functions and connecting them up with the rest of the game server code.
All scripts belong in the game
module under world.gregs.voidps.world
(unless otherwise specified in game.properties
)
In IntelliJ right click the directory where you'd like to place to create a kotlin file (Shortcut: Alt + Insert)
Select Kotlin script
from the list of options and enter a unique name for your script; it should start with an upper case and follow CamelCaseConventions.
Now your script is created you should add the package name to the top if it isn't there already, you might also get a prompt to add it automatically.
Now your script is ready and will automatically be picked up by the game engine the next time you run the game server.
There are a number of "helper functions" when writing scripts to make the process smoother, you can find examples of these all over the docs although a number of the basic one's can be found in Entities and Interactions.
For example if you want to send a message when a player logs in you can use playerSpawn
:
playerSpawn { player ->
player.message("Welcome to Void.", ChatType.Welcome)
}
or adding a boost when consuming an item use consume
:
consume("cup_of_tea") { player ->
player.levels.boost(Skill.Attack, 3)
}
It really depends on what content you want to write. It is recommended you look at existing scripts similar to the content you want to make in order to discover functions to use and get started quickly.
Here's a few common ones:
Function name | Example usage |
---|---|
Spawn |
worldSpawn {} , playerSpawn { player -> } , npcSpawn { npc -> }
|
Move |
move { player -> } , npcMove { npc -> }
|
Interface Option | interfaceOption("Open", "task_list", "task_system") {} |
Interface Opened | interfaceOpen("price_checker") { player -> } |
Interface Closed | interfaceClose("clan_chat_setup") { player -> } |
NPC Option |
npcOperate("Talk-to", "aubury") {} , npcApproach("Collect", "banker*") {}
|
Commands |
command("test") {} , modCommand("players") {} , adminCommand("master") {}
|
Timer Start |
timerStart("overload") { player: Player -> } , npcTimerStart("eat_grass") { npc -> }
|
Timer Tick |
timerTick("overload") { player: Player -> } , npcTimerTick("eat_grass") { npc -> }
|
Timer Stop |
timerStop("overload") { player: Player -> } , npcTimerStop("eat_grass") { npc -> }
|
Variable set | variableSet("attack_style", "long_range") { player -> } |
Item added | itemAdded("avas_*", EquipSlot.Cape, "worn_equipment") { player -> } |
Item removed | itemRemoved("staff_of_light*", EquipSlot.Weapon, "worn_equipment") { player -> } |
Item changed | itemChange(EquipSlot.Weapon, "worn_equipment", Priority.HIGH) { player -> } |
Combat Hit |
combatHit { player -> } , npcCombatHit { npc -> } , characterCombatHit { character -> }
|
Special attack | specialAttack("staff_of_light*") { player -> } |
Normally you should have no problems adding and removing scripts but sometimes you might see the message on startup:
DEBUG [ContentLoader] No auto-generated script file found, falling back to manual search.
This is not an issue however it will make startup slightly bit slower, it can be fixed by switching to the gradle builder or by adding a pre-build task to your build config:
File | Settings | Build, Execution, Deployment | Build Tools | Gradle
And change your build and run
executor from IntelliJ to Gradle.
This will automatically compile a list of scripts (found in game/src/main/resources/scripts.txt) each time you rebuild/run the game.
Edit your Main build configuration
Under Before launch
add a Run Gradle task
Select the :game
project and fill out the Tasks
field with the name "collectSourcePaths"
Click okay and drag the task before the Build
:
Apply and enter.
If the server crashes on startup with an error similar to this message:
ERROR [ContentLoader] Failed to load script: content.script.name.Broken
java.lang.ClassNotFoundException: content.script.name.Broken
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:526)
at java.base/java.lang.Class.forName0(Native Method)
at java.base/java.lang.Class.forName(Class.java:421)
at java.base/java.lang.Class.forName(Class.java:412)
at ContentLoader.loadScript(ContentLoader.kt:47)
at ContentLoader.load(ContentLoader.kt:28)
at Main.preload(Main.kt:86)
at Main.main(Main.kt:46)
ERROR [ContentLoader] Make sure the scripts package is correct.
It most likely means the script mentioned is missing a package content.ScriptName
as mentioned in Create a script.
If however this isn't the case then it's possible your scripts.txt file got out of sync. You can fix this by running
gradle collectSourcePaths
./gradlew collectSourcePaths
Or manually deleting the scripts.txt file in game/src/main/resources/
, /game/out/production/resources/
or /game/build/resources/main/