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.

Dota 2 Workshop Tools/Scripting/Creating a Tower Example

From Valve Developer Community
Jump to: navigation, search

Note.pngNote: This page is cross posted from /r/Dota2modding. [1]

Firstly

  • Create a npc_units_custom.txt in \dota 2 beta\dota_ugc\game\dota_addons\your_addon_name\scripts\npc. This file will allow you to setup and modify completely new units for use in your addon.

Secondly

  • Copy the content of the template and paste in your npc_units_custom.txt. *You now have a functional tower which you can use ingame.*
// Dota Units File
"DOTAUnits"
{
	"Version"	"1"	

	"npc_dota_tower_basedef"
		{
			// General
			//
			"BaseClass"					"npc_dota_tower"	// Class of entity of link to.
			"Model"						"models/props_structures/tower_good.vmdl"// Model.
			"SoundSet"					"Tower.Water"					// Name of sound set.
			"MinimapIcon"				""
			"MinimapIconSize"			"0"
			"Level"						"1"
			
			// Abilities
			//----------------------------------------------------------------
			
			"Ability1"					""			// Ability 1.
			"Ability2"					""			// Ability 2.
			"Ability3"					""			// Ability 3.
			"Ability4"					""			// Ability 4.
			"Ability5"					""			// Ability 5.
			"Ability6"					""			// Ability 6 - Extra.
			"Ability7"					""			// Ability 7 - Extra.
			"Ability8"					""			// Ability 8 - Extra.
	
			// Armor
			//----------------------------------------------------------------
			"ArmorPhysical"				"322"		// Physical protection.
			"MagicalResistance"				"0"			// Magical protection.
	
			// Attack
			//----------------------------------------------------------------
			"AttackCapabilities"		"DOTA_UNIT_CAP_RANGED_ATTACK"
			"AttackDamageMin"			"200"		// Damage range min.
			"AttackDamageMax"			"250"		// Damage range max.
			"AttackDamageType"			"DAMAGE_TYPE_ArmorPhysical"
			"AttackRate"				"0.25"			// Speed of attack.
			"AttackAnimationPoint"		"0.0"		// Normalized time in animation cycle to attack.
			"AttackAcquisitionRange"	"800"		// Range within a target can be acquired.
			"AttackRange"				"800"		// Range within a target can be attacked.
			"ProjectileModel"			"particles/base_attacks/ranged_tower_good.vpcf"		// Particle system model for projectile.
			"ProjectileSpeed"			"1250"		// Speed of projectile.
	
			// Attributes
			//----------------------------------------------------------------
			"AttributePrimary"			"DOTA_ATTRIBUTE_STRENGTH"
			"AttributeBaseStrength"		"0"			// Base strength
			"AttributeStrengthGain"		"0"			// Strength bonus per level.
			"AttributeBaseIntelligence"	"0"			// Base intelligence
			"AttributeIntelligenceGain"	"0"			// Intelligence bonus per level.
			"AttributeBaseAgility"		"0"			// Base agility
			"AttributeAgilityGain"		"0"			// Agility bonus per level.
	
			// Bounty
			//----------------------------------------------------------------
			"BountyXP"					"0"		// Experience earn.
			"BountyGoldMin"				"0"		// Gold earned min.
			"BountyGoldMax"				"0"		// Gold earned max.
	
			// Bounds
			//----------------------------------------------------------------
			"BoundsHullName"			"DOTA_HULL_SIZE_TOWER"			// Hull type used for navigation/locomotion.
			"ProjectileCollisionSize"	"50"
			"RingRadius"				"130"
			"HealthBarOffset"			"260"
	
			// Movement
			//----------------------------------------------------------------
			"MovementCapabilities"		"DOTA_UNIT_CAP_MOVE_NONE"			// Type of locomotion - ground, air
			"MovementSpeed"				"0"			// Speed
			"MovementTurnRate"			"1.0"			// Turning rate.
	
			// Status
			//----------------------------------------------------------------
			"StatusHealth"				"1337"		// Base health.
			"StatusHealthRegen"			"0"			// Health regeneration rate.
			"StatusMana"				"0"			// Base mana.
			"StatusManaRegen"			"0"			// Mana regeneration rate.
	
			// Team
			//----------------------------------------------------------------
			"TeamName"					"DOTA_TEAM_GOODGUYS"			// Team name.
			"CombatClassAttack"			"DOTA_COMBAT_CLASS_ATTACK_SIEGE"
			"CombatClassDefend"			"DOTA_COMBAT_CLASS_DEFEND_STRUCTURE"
			"UnitRelationshipClass"		"DOTA_NPC_UNIT_RELATIONSHIP_TYPE_BUILDING"
			
			// Vision
			//----------------------------------------------------------------
			"VisionDaytimeRange"		"1000"		// Range of vision during day light.
			"VisionNighttimeRange"		"1000"		// Range of vision at night time.
		}
}

Thirdly

I strongly suggest that you try your unit out ingame before you do any serious editing just to make sure it works properly.

  • Open your npc_units_custom.txt and look at the top for "npc_dota_tower_basedef".

You can change this and it can be whatever you want but for simplicity's sake name it "npc_dota_custom_tower". This will be used in the Hammer editor later. Save and exit.

  • Now start up your Dota 2 addon (NOTE it must be the same addon as the one you placed your npc_units_custom.txt file in) and open your map.
  • Select the Entity Tool (Shift+E) and change the Entity Class to the class of your unit which is "npc_dota_tower". This Class is what tells the game your unit is a tower.
  • Place the Entity somewhere where you can easily get to it when ingame, and while selected press (Alt + Enter) to bring up the Object Properties window.
  • To get this Entity to load your custom tower settings, you need to set its "Unit Name" to what you named your tower in the npc_units_custom.txt file. Scroll down to Unit Name and write "npc_dota_custom_tower" (without quotation marks). After this, scroll down to Team Number and set it to "Bad Guys" so that it will be hostile when you start the game as a radiant member.

Don't worry about the entity not having a model in Hammer. It will get loaded when the addon is run ingame.


Thats it!

Save your map and press F9 to bring up the Build Map window. Make sure everything is checked if it's your first time building the map, and make sure Build entities is checked if you have previously built the map (this shortens the build time).

When the game is loaded and done and you have picked a hero, first of all make sure the tower model is showing properly, and then get close to it to make sure it's attacking and showing proper particles etc.

If everything is working properly then go ahead and open up your npc_units_custom.txt again and start modifying values to suit your needs. Make sure to seek inspiration and information from other mods both in your dota_addons folder and on the net.


Notes

  • Repeat step 3 when you want to create more towers in the editor.
  • \dota 2 beta\dota_ugc\game\dota_addons\your_addon_name\resource\addon_english.txt can be used to give the unit a proper name when ingame.

Example:

      "lang"
    {
    	    "Language"		"English"
	    "Tokens"
	    {		
		    "npc_dota_tower_basedef"							"Tower"
	    }
    }