Advertisement
Guest User

Untitled

a guest
Dec 11th, 2016
501
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.31 KB | None | 0 0
  1. Dota Bot Scripting
  2. Contents [hide]
  3. 1 Overview
  4. 1.1 Team Level
  5. 1.2 Mode Level
  6. 1.3 Action Level
  7. 2 Directory Structure
  8. 2.1 Complete takeover
  9. 2.2 Mode Override
  10. 2.3 Ability and Item usage
  11. 2.4 Item Purchasing
  12. 2.5 Team Level Desires
  13. 2.6 Hero Selection
  14. 3 API Reference
  15. 3.1 Global
  16. 3.2 Unit-Scoped
  17. 3.3 Editing in Progress
  18. Overview
  19.  
  20. Bot scripting in Dota is done via lua scripting. This is done at the server level, so there's no need to do things like examine screen pixels or simulate mouse clicks; instead scripts can query the game state and issue orders directly to units. Scripts have full have access to all the entity locations, cooldowns, mana values, etc that a player on that team would expect to. The API is restricted such that scripts can't cheat -- units in FoW can't be queried, commands can't be issued to units the script doesn't control, etc.
  21.  
  22. In addition to lua scripting, the underlying C++ bot code still exists, and scripts can decide how much or little of the underlying bot structure to use.
  23.  
  24. Bots are organized into three levels of evaluation and decisionmaking:
  25.  
  26. Team Level
  27. This is code that determines how much the overall team wants to push each lane, defend each lane, farm each lane, or kill Roshan. These desires exist independent of the state of any of the bots. They are not authoritative; that is, they do not dictate any actions taken by any of the bots. They are instead just desires that the bots can use for decisionmaking.
  28.  
  29. Mode Level
  30. Modes are the high-level desires that individual bots are constantly evaluating, with the highest-scoring mode being their currently active mode. Examples of modes are laning, trying to kill a unit, farming, retreating, and pushing a tower.
  31.  
  32. Action Level
  33. Actions are the individual things that bots are actively doing on a moment-to-moment basis. These loosely correspond to mouse clicks or button presses -- things like moving to a location, or attacking a unit, or using an ability, or purchasing an item.
  34.  
  35. The overall flow is that the team level is providing top-level guidance on the current strategy of the team. Each bot is then evaluating their desire score for each of its modes, which are taking into account both the team-level desires as well as bot-level desires. The highest scoring mode becomes the active mode, which is solely responsible for issuing actions for the bot to perform.
  36.  
  37. Directory Structure
  38.  
  39. All in-development bot scripts live in the game/dota/scripts/vscripts/bots directory within your Dota 2 install. When you upload your bot script to the workshop, it will upload the contents of this directory. Downloaded scripts live in their own location within your Steam install.
  40.  
  41. The bot scripting API is structured such that there are multiple elements that can be independently implemented by bot scripts. What logic is overriden is determined by which functions you implement and the files in which they are implemented.
  42.  
  43. Each of the following scripting elements has its own script scope.
  44.  
  45. Complete takeover
  46. If you'd like to completely take over control of a hero, you can implement a Think() function in a file called bot_generic.lua, which is called every frame in lieu of the normal bot thinking code. This will completely take over all bots -- no team-level or mode-level thinking will happen. You will be responsible for issuing all action-level commands to all bots. If you'd like to just take over a specific hero's bot, for example Lina, you can implement a Think() function in a file called bot_lina.lua.
  47.  
  48. Bots that have been completely taken over still respect the difficulty modifiers (see Appendix B), and still calculate their estimated damage.
  49.  
  50. Mode Override
  51. If you'd like to work within the existing mode architecture but override the logic for mode desire and behavior, for example the Laning mode, you can implement the following functions in a mode_laning_generic.lua file:
  52.  
  53. GetDesire() - Called every frame, and needs to return a floating-point value between 0 and 1 that indicates how much this mode wants to be the active mode.
  54. OnStart() - Called when a mode takes control as the active mode.
  55. OnEnd() - Called when a mode relinquishes control to another active mode.
  56. Think() - Called every frame while this is the active mode. Responsible for issuing actions for the bot to take.
  57. You can additionally just override the mode logic for a specific hero, such as Lina, with a mode_laning_lina.lua file. Please see Appendix A for implementation details if you'd like to chain calls from a hero-specific mode override back to a generic mode override.
  58.  
  59. The list of valid bot modes to override are:
  60.  
  61. laning
  62. attack
  63. roam
  64. retreat
  65. secret_shop
  66. side_shop
  67. rune
  68. push_tower_top
  69. push_tower_mid
  70. push_tower_bot
  71. defend_tower_top
  72. defend_tower_mid
  73. defend_tower_bottom
  74. assemble
  75. team_roam
  76. farm
  77. defend_ally
  78. evasive_maneuvers
  79. roshan
  80. item
  81. ward
  82. Ability and Item usage
  83. If you'd like to just override decisionmaking around ability and item usage, you can implement the following functions in an ability_item_usage_generic.lua file:
  84.  
  85. ItemUsageThink() - Called every frame. Responsible for issuing item usage actions.
  86. AbilityUsageThink() - Called every frame. Responsible for issuing ability usage actions.
  87. CourierUsageThink() - Called every frame. Responsible for issuing commands to the courier.
  88. BuybackUsageThink() - Called every frame. Responsible for issuing a command to buyback.
  89. If any of these functions are not implemented, it will fall back to the default C++ implementation.
  90.  
  91. You can additionally just override the ability/item usage logic for a single hero, such as Lina, with an ability_item_usage_lina.lua file. Please see Appendix A for implementation details if you'd like to chain calls from a hero-specific item/ability implementation back to a generic item/ability implementation.
  92.  
  93. Item Purchasing
  94. If you'd like to just override decisionmaking around item purchasing, you can implement the following function in an item_purchase_generic.lua file:
  95.  
  96. ItemPurchaseThink() - Called every frame. Responsible for purchasing items.
  97. You can additionally just override the item purchasing logic for a single hero, such as Lina, with an item_purchase_lina.lua file.
  98.  
  99. Team Level Desires
  100. If you'd like to supply team-level desires, you can implement the following functions in a team_desires.lua file:
  101.  
  102. UpdatePushLaneDesires() - Called every frame. Returns floating point values between 0 and 1 that represent the desires for pushing the top, middle, and bottom lanes, respectively.
  103. UpdateDefendLaneDesires() - Called every frame. Returns floating point values between 0 and 1 that represent the desires for defending the top, middle, and bottom lanes, respectively.
  104. UpdateFarmLaneDesires() - Called every frame. Returns floating point values between 0 and 1 that represent the desires for farming the top, middle, and bottom lanes, respectively.
  105. UpdateRoamDesire() - Called every frame. Returns a floating point value between 0 and 1 and a unit handle that represents the desire for someone to roam and gank a specified target.
  106. UpdateRoshanDesire() - Called every frame. Returns a floating point value between 0 and 1 that represents the desire for the team to kill Roshan.
  107. If any of these functions are not implemented, it will fall back to the default C++ implementation.
  108.  
  109. Hero Selection
  110. If you'd like to handle hero picking and lane assignment, you can implement the following functions in a hero_selection.lua file:
  111.  
  112. Think() - Called every frame. Responsible for selecting heroes for bots.
  113. UpdateLaneAssignments() - Called every frame prior to the game starting. Returns ten PlayerID-Lane pairs.
  114. API Reference
  115.  
  116. There are two basic levels at which the API is available: globally, and on individual units. The following is a list of functions available at each level.
  117.  
  118. Global
  119. (details WIP)
  120.  
  121. GetBot
  122. GetTeam
  123. GetTeamMember
  124. DotaTime
  125. GameTime
  126. RealTime
  127. GetUnitToUnitDistance
  128. GetUnitToLocationDistance
  129. GetWorldBounds
  130. IsLocationPassable
  131. GetHeightLevel
  132. GetLocationAlongLane
  133. GetNeutralSpawners
  134. GetItemCost
  135. IsItemPurchasedFromSecretShop
  136. IsItemPurchasedFromSideShop
  137. GetItemStockCount
  138. GetPushLaneDesire
  139. GetDefendLaneDesire
  140. GetFarmLaneDesire
  141. GetRoamDesire
  142. GetRoamTarget
  143. GetRoshanDesire
  144. int GetGameState()
  145. Returns the current game state [LINK HERE]
  146. float GetGameStateTimeRemaining()
  147. Returns how much time is remaining in the curren game state, if applicable
  148. int GetGameMode()
  149. Returns the current game mode [LINK HERE]
  150. int GetHeroPickState()
  151. Returns the current hero pick state [LINK HERE]
  152. IsPlayerInHeroSelectionControl
  153. SelectHero
  154. GetSelectedHeroName
  155. IsInCMBanPhase
  156. IsInCMPickPhase
  157. GetCMPhaseTimeRemaining
  158. GetCMCaptain
  159. SetCMCaptain
  160. IsCMBannedHero
  161. IsCMPickedHero
  162. CMBanHero
  163. CMPickHero
  164. RandomInt
  165. RandomFloat
  166. RandomYawVector
  167. RollPercentage
  168. Min
  169. Max
  170. Clamp
  171. RemapVal
  172. RemapValClamped
  173. DebugDrawLine
  174. DebugDrawCircle
  175. DebugDrawText
  176. Unit-Scoped
  177. Action_ClearActions
  178. Action_MoveToLocation
  179. Action_MoveToUnit
  180. Action_AttackUnit
  181. Action_AttackMove
  182. Action_UseAbility
  183. Action_UseAbilityOnEntity
  184. Action_UseAbilityOnLocation
  185. Action_UseAbilityOnTree
  186. Action_PickUpRune
  187. Action_PickUpItem
  188. Action_DropItem
  189. Action_PurchaseItem
  190. Action_SellItem
  191. Action_Buyback
  192. Action_LevelAbility
  193. GetDifficulty
  194. GetUnitName
  195. GetPlayer
  196. IsHero
  197. IsCreep
  198. IsTower
  199. IsBuilding
  200. IsFort
  201. IsIllusion
  202. CanBeSeen
  203. GetActiveMode
  204. GetActiveModeDesire
  205. GetHealth
  206. GetMaxHealth
  207. GetMana
  208. GetMaxMana
  209. IsAlive
  210. GetRespawnTime
  211. HasBuyback
  212. GetGold
  213. GetStashValue
  214. GetCourierValue
  215. GetLocation
  216. GetFacing
  217. GetGroundHeight
  218. GetAbilityByName
  219. GetItemInSlot
  220. IsChanneling
  221. IsUsingAbility
  222. GetVelocity
  223. GetAttackTarget
  224. GetLastSeenLocation
  225. GetTimeSinceLastSeen
  226. IsRooted
  227. IsDisarmed
  228. IsAttackImmune
  229. IsSilenced
  230. IsMuted
  231. IsStunned
  232. IsHexed
  233. IsInvulnerable
  234. IsMagicImmune
  235. IsNightmared
  236. IsBlockDisabled
  237. IsEvadeDisabled
  238. IsUnableToMiss
  239. IsSpeciallyDeniable
  240. IsDominated
  241. IsBlind
  242. HasScepter
  243. WasRecentlyDamagedByAnyHero
  244. WasRecentlyDamagedByHero
  245. TimeSinceDamagedByAnyHero
  246. TimeSinceDamagedByHero
  247. DistanceFromFountain
  248. DistanceFromSideShop
  249. DistanceFromSecretShop
  250. SetTarget
  251. GetTarget
  252. SetNextItemPurchaseValue
  253. GetNextItemPurchaseValue
  254. GetAssignedLane
  255. GetEstimatedDamageToTarget
  256. GetStunDuration
  257. GetSlowDuration
  258. HasBlink
  259. HasMinistunOnAttack
  260. HasSilence
  261. HasInvisibility
  262. UsingItemBreaksInvisibility
  263. GetNearbyHeroes
  264. GetNearbyTowers
  265. GetNearbyCreeps
  266. FindAoELocation
  267. GetExtrapolatedLocation
  268. GetMovementDirectionStability
  269. GetActualDamage
  270. Editing in Progress
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement