{-Scripting-}
By kChris
Scripting is the most programatically interesting and intriguing part of the Toribash experience, especially for someone with a nack for programming.
Throughout this tutorial, I'm going to attempt to get you on the right tracks for writing your very own scripts.
» Part One «
Understanding LUA
Understanding LUA's syntax is the most important, and complicated part to this entire endeavour.
The syntax isn't complicated, but compared to everything else, it's the most complicated.
Get started at
https://www.lua.org/manual/5.3/manual.html.
» Part Two «
A Scripts Context
A script is ran alongside the game, and loaded when a player loads them.
They are run alongside a LUA library written by the creators and developers of Toribash, with a multitude of methods available at our disposal to get information about the current game, players, and everything in between, including firing code when certain things happen.
We will be going over these different functions later.
» Part Three «
Getting Started
To get yourself started, I'm going to introduce you to one of the many functions Toribash will allow you to utilize;
echo().
This function allows us to print text to the chat that only the player running the script will see.
To get started, create a new file, name it (name of your script).lua, and open it up in your favorite editor (I use IntelliJ).
Simply write
echo("Hello, world!"), save it to your "script" folder, go in game, and load your script with /ls.
You should now see "Hello, world!" in chat!
» Part Four «
The Many Functions Of The Toribash SDK
There are a lot of functions you can utilize.
Inside of the "script" folder in your Toribash, there's a folder named "sdk".
Every file name in there represents a function you can use, and inside of it, contains examples of how to use it.
Feel free to copy and paste their usage into your own script, and see what happens!
If there's enough feedback asking, I'll write a Github page with all of the functions with a more in depth descripton.
» Part Five «
Hooks
Hooks are the grandaddy meat of a script.
If you want to run code when certain things happen, like the game ending, or a command being ran, this is is what you need.
Pretty much, when an event is fired and there's a hook for it, those hooks call the methods that are attached to them, sort of like Spigot's event system if you ever written a Minecraft plugin before.
Here is a list of all of the hooks, and below will be how to use them.
new_game
new_mp_game
enter_frame
end_game
leave_game
enter_freeze
exit_freeze
match_begin
key_up
key_down
mouse_button_up
mouse_button_down
mouse_move
player_select
joint_select
body_select
draw2d
draw3d
play
camera
console
bout_mouse_down
bout_mouse_up
bout_mouse_over
bout_mouse_outside
spec_mouse_down
spec_mouse_up
spec_mouse_over
spec_mouse_outside
command
unload
Alright! You now have access to all the hooks... now what?
I'll provide a quick, simple example of how to use a hook.