Skip to content

Scripts

Greg edited this page Feb 29, 2024 · 3 revisions

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)

Screenshot 2024-02-21 202918 Screenshot 2024-02-21 203331

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

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.

Screenshot 2024-02-21 204100

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.

Screenshot 2024-02-21 204136

Now your script is ready and will automatically be picked up by the game engine the next time you run the game server.

Script functions

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 -> }
Clone this wiki locally