This article relates to the game "Dota 2". Click here for more information.
This article relates to the SDK/Workshop Tools for "Dota 2 Workshop Tools". Click here for more information.
This article's documentation is for Source 2. Click here for more information.

Getting Started

From Valve Developer Community
Jump to: navigation, search
English (en)Русский (ru)
Edit

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.

Tip.pngTip:You can reload script files at runtime using the console command 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.

Tip.pngTip:When creating an addon for the first time a very simple script file will be placed in your addon in the appropriate place, you can use that as a starting point for new addons

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

Warning: Display title "Getting Started" overrides earlier display title "Dota 2 Workshop Tools/Scripting/Getting Started".