Getting Started
All of Dota 2 Workshop Tools scripting for addons is handled in Lua. If you're familiar writing script or code in another language then writing concepts in Lua will likely be fairly straight forward.
script_reload
.Required Files
The following file must be present to have it start running a script. This file must live in the /game
directory of the addon and is executed at run time when the addon loads.
../game/dota_addons/your_addon/scripts/vscripts/addon_game_mode.lua
This file is not optional and is restricted to the provided name. Additional files can be created and referenced from any point inside /vscripts
of course and can take on whatever organization method preferred.
Running Script Files
When loading an addon the addon_game_mode.lua
script file will be executed immediately. Additional script files can be loaded along with addon_game_mode.lua
by using
require( "lua_filename_here" )
Required Script Functions
There are some reserved function calls made in every addon that should be observed.
Precache
The Precache
function will load all required assets in advance of them being required by the game. The example below includes three types of resource precaching. A specific particle file, a particle folder which will load all particle files in that folder, and a specific item.
function Precache( context )
PrecacheResource( "particle", "particles/items2_fx/veil_of_discord.vpcf", context )
PrecacheResource( "particle_folder", "particles/frostivus_gameplay", context )
PrecacheItemByNameSync( "item_bag_of_gold", context )
end
Activate
The Activate
function is used to setup the game mode for the first time. It is run when the file is loaded and is generally used to setup classes for the game mode to utilize.
function Activate()
GameRules.holdOut = CHoldoutGameMode()
GameRules.holdOut:InitGameMode()
end