Ability Lua Tutorial 2: Registering and Testing Ability - Elfansoer/dota-2-lua-abilities GitHub Wiki
Time to make the dream come true.
Valve actually made their own tutorial on how to create custom abilities using lua. Well, "giving examples" is more accurate, but still it's very useful. The tutorial is an addon (custom game) named ability_lua_example.
To play the addon, simply open Dota 2, then on your console (make sure you enabled it first), put:
dota_launch_custom_game lua_ability_example hero_demo_main
Go with the flow, (e.g. pick Lina), and voila: it looks like a hero demo! Go play with her and everything seems normal, except for the fact that she has 5 abilities.
If you still didn't notice it, here's the hint: all of her abilities are written in Lua, and you may see (also edit) the script file(s).
The addon files are located on:
<YourSteamLibrary>/dota 2 beta/game/dota_addons/lua_ability_example/
The lua scripts were stored in scripts/vscripts within the folder.
Excited? Go explore them. Confused? Let's go on.
Here, I'll explain folders and files that will be important in this tutorial.
scripts/npc/herolist.txt
This is the file where you can enable/disable heroes during the custom game.
To add more heroes, simply add the hero's technical name as the key (remember it?), and "1" as its value.
scripts/npc/npc_heroes_custom.txt
Currently, you don't actually create heroes; you override existing heroes. For example, you can override Lina's ablilities.
To replace her abilities, simply change the value of Ability1 (or 2,3,4) with your ability's technical name.
scripts/npc/npc_abilities_custom.txt
Looks familiar? This is where the custom game lists all of its custom abilities. If you want your ability be playable, register it here.
resource/addon_english.txt
This is where you would store your ability's actual name, its description, lore, etc. The game made a separate file for those kind of things so that the descriptions may be displayed differently in other language.
resource/flash3/images/spellicons
This is where you store your ability icons. Follow the format, okay?
Okay, I assume that you already fill the ability form for your own ability.
In my case, I have filled the form for Antimage's Spell Shield.
First of all, make sure you place your script files in the correct folder. In the ability's .txt above, I've set the script file as
"lua_abilities/antimage_spell_shield_lua/antimage_spell_shield_lua".
So, the .txt file and main lua's file path should be
".../lua_ability_example/scripts/vscripts/lua_abilities/antimage_spell_shield_lua/antimage_spell_shield_lua.lua".
The rest of supporting files should be within the same folder. You may store in different folder, but make sure you set it correctly on the ability form, okay?
Next step is registering the ability form into npc_abilities_custom.txt. Simply add the .txt path file like this, the one with #base at the bottom of the file.
Now that the ability has been registered, let the engine know that Lina will have that ability. Open npc_heroes_custom.txt, and change the value of Ability1 to the ability's technical name, antimage_spell_shield_lua, like this.
Technically, your ability has been registered. One small step is to add the ability's icon, but this is optional.
To do that, go to spellicons folder specified above, store the icon there, then rename it as what you write on .txt file. In my case, the ability icon has been prepared for use.
Finally, go ahead and run the addon again. Lina's first ability should have changed and when you play her, you may test the ability.
I think it's time to stop. Next time, we'll create an actual Dota 2 ability, Antimage's Spell Shield, step-by-step. This ability is very simple if you don't include its aghanims upgrade (which is nasty in-game, by the way). See you later!
To test the ability, you may want to use cheat mode and summon an enemy Lina.
Enter sv_cheats 1 in your console, then put -createhero lina enemy on the chatbox to summon an enemy Lina at your cursor's location.
Level up Spell Shield on your Lina and LSA on enemy Lina. Then, let enemy Lina to cast LSA at yours.
You may also want -wtf on chatbox to spam LSA.