Applying Data Driven Modifiers from script

From Valve Developer Community
Jump to: navigation, search

It's possible to freely apply custom data-driven modifiers from VScript using the following function.

CDOTA_Item_DataDriven

Function Signature Description
ApplyDataDrivenModifier void ApplyDataDrivenModifier(handle source, handle target, string modifier_name, handle modifierArgs)

Hopefully you've noticed this function belongs to objects of the Item type. It's used along with a data-driven item definition containing your data-driven modifiers. This item decleration should go into scripts/npc/npc_items_custom.txt

	"item_modifier_master"
	{
		"ID"							"1010"

		// General
		//-------------------------------------------------------------------------------------------------------------
		"AbilityBehavior"				"DOTA_ABILITY_BEHAVIOR_NO_TARGET | DOTA_ABILITY_BEHAVIOR_IMMEDIATE"
		"BaseClass"						"item_datadriven"

		// Stats
		//-------------------------------------------------------------------------------------------------------------
		"AbilityCastRange"				"100"
		"AbilityCastPoint"				"0.0"
		
		// Item Info
		//-------------------------------------------------------------------------------------------------------------

		"Modifiers"
		{
			"modifier_custom"
			{
				"TextureName" "item_greater_salve"
				"EffectName" "particles/items_fx/healing_flask.vpcf"
				"EffectAttachType" "follow_origin"

				"Properties"
				{
					"MODIFIER_PROPERTY_ATTACKSPEED_BONUS_CONSTANT" "100"
				}
			}
		}
}

And the script:

local ModMaster = CreateItem("item_modifier_master", nil, nil) 
ModMaster:ApplyDataDrivenModifier(unit, unit, "modifier_custom", {duration = 3})