January 23, 2018

Ability Lua Tutorial 2: Registering and Testing Ability

Views: 1388 Elfansoer

Registering and Testing Ability

Time to make the dream come true.

EDIT: Some notes has been edited due to github repository change.

Dota 2 Addon: Ability Lua Example


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:
Code:
dota_launch_custom_game lua_ability_example hero_demo_main

Go with the flow (Lina recommended; she's hot), 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.

Random guy: Okay, now what?

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:
Code:
"<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.

Important Files


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 simplicity, in this tutorial I'll be using Lina as the main hero, and replace one of her abilities with a freshly created one. For melee hero, I'll use Phantom Assassin.
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?

Installing your custom ability


Okay, I assume that you already fill the ability form for your own ability.
In my case, I have filled the form for an ability created by ELF1N, Plague Doctor's Healing Shield. I also created the script files for the ability (without permission, sorry ELF1N), but you don't have to worry about this for now.
Here's the ability's form and script files. Let's integrate it.

EDIT: As the time flies, there's a change in GitHub repository and the abilities. So, I'll use the existing ability instead, Antimage's Spell Shield. Here's the script files.

Put on the correct folder


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 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?

Register at "npc_abilities_custom.txt"


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. Just search the ability name, and you'll find it.

Let Lina Drow have it


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.

Add icon for it


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.

Conclusion


I think it's time to stop. Questions, Comments and Critics are always welcomed.
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!

P.S


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.