When creating cool new abilities or game mechanics you often run into issues with the lack of good API. While I admit the dota 2 has massive API, it seems to focus on few very odd things or mechanics not fully exposed by default game. (Runes, Spell Stealing, Illusions). To fix those issues you might want to expand it. Here is one method of doing so.
If you are using BMD's Barebones then you already have neatly exposed function
GameMode:OnHeroInGame(hero) in your
internal/gamemode.lua file. Otherwise you will want to listen to NPC spawning when initializing your game mode:
NOTE: Keep in mind your gamemode's function name. I used
CModDotaTutorialsGameMode. You should probably have something else. Now lets get back to topic. As you noticed we used
LinkLuaModifier. We should create file it points to in your vscripts folder
For this example we are tracking what is the last spell player has cast. This could be used potentially as the building blocks for recreating Rubick's spell steal.
If you are unfamiliar with lua modifiers here is the only essential part of your modifier:
Next we want to make sure the modifier is not disabled at any point:
Here is the meat of our function's purpose. Track when this hero casts a spell.
Now we get to the magic:
Because we assume every hero having this modifier its kinda useless to show it on the screen.
Now that we have our modifier done. We want some way of testing it. I decided to go with simple console command. Add following to your game init function.
Now the actual console command's function:
Now you should be able to use console command
mod_test_spells to print out the last spell every hero has used.
Next topic: Linken Sphere & Lotus Orb.