Advertisement
Guest User

Untitled

a guest
Dec 11th, 2016
300
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.78 KB | None | 0 0
  1. Overview
  2.  
  3. 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.
  4.  
  5. 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.
  6.  
  7. Bots are organized into three levels of evaluation and decisionmaking:
  8. Team Level
  9.  
  10. 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.
  11. Mode Level
  12.  
  13. 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.
  14. Action Level
  15.  
  16. 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.
  17.  
  18. 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.
  19. Directory Structure
  20.  
  21. 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.
  22.  
  23. 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.
  24.  
  25. Each of the following scripting elements has its own script scope.
  26. Complete takeover
  27.  
  28. 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.
  29.  
  30. Bots that have been completely taken over still respect the difficulty modifiers (see Appendix B), and still calculate their estimated damage.
  31. Mode Override
  32.  
  33. 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:
  34.  
  35. 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.
  36. OnStart() - Called when a mode takes control as the active mode.
  37. OnEnd() - Called when a mode relinquishes control to another active mode.
  38. Think() - Called every frame while this is the active mode. Responsible for issuing actions for the bot to take.
  39.  
  40. 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.
  41.  
  42. The list of valid bot modes to override are:
  43.  
  44. laning
  45. attack
  46. roam
  47. retreat
  48. secret_shop
  49. side_shop
  50. rune
  51. push_tower_top
  52. push_tower_mid
  53. push_tower_bot
  54. defend_tower_top
  55. defend_tower_mid
  56. defend_tower_bottom
  57. assemble
  58. team_roam
  59. farm
  60. defend_ally
  61. evasive_maneuvers
  62. roshan
  63. item
  64. ward
  65.  
  66. Ability and Item usage
  67.  
  68. 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:
  69.  
  70. ItemUsageThink() - Called every frame. Responsible for issuing item usage actions.
  71. AbilityUsageThink() - Called every frame. Responsible for issuing ability usage actions.
  72. CourierUsageThink() - Called every frame. Responsible for issuing commands to the courier.
  73. BuybackUsageThink() - Called every frame. Responsible for issuing a command to buyback.
  74.  
  75. If any of these functions are not implemented, it will fall back to the default C++ implementation.
  76.  
  77. 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.
  78. Item Purchasing
  79.  
  80. If you'd like to just override decisionmaking around item purchasing, you can implement the following function in an item_purchase_generic.lua file:
  81.  
  82. ItemPurchaseThink() - Called every frame. Responsible for purchasing items.
  83.  
  84. You can additionally just override the item purchasing logic for a single hero, such as Lina, with an item_purchase_lina.lua file.
  85. Team Level Desires
  86.  
  87. If you'd like to supply team-level desires, you can implement the following functions in a team_desires.lua file:
  88.  
  89. 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.
  90. 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.
  91. 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.
  92. 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.
  93. UpdateRoshanDesire() - Called every frame. Returns a floating point value between 0 and 1 that represents the desire for the team to kill Roshan.
  94.  
  95. If any of these functions are not implemented, it will fall back to the default C++ implementation.
  96. Hero Selection
  97.  
  98. If you'd like to handle hero picking and lane assignment, you can implement the following functions in a hero_selection.lua file:
  99.  
  100. Think() - Called every frame. Responsible for selecting heroes for bots.
  101. UpdateLaneAssignments() - Called every frame prior to the game starting. Returns ten PlayerID-Lane pairs.
  102.  
  103. API Reference
  104.  
  105. 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.
  106. Global
  107.  
  108. (details WIP)
  109.  
  110. GetBot
  111. GetTeam
  112. GetTeamMember
  113.  
  114. DotaTime
  115. GameTime
  116. RealTime
  117.  
  118. GetUnitToUnitDistance
  119. GetUnitToLocationDistance
  120. GetWorldBounds
  121. IsLocationPassable
  122. GetHeightLevel
  123. GetLocationAlongLane
  124. GetNeutralSpawners
  125. GetItemCost
  126. IsItemPurchasedFromSecretShop
  127. IsItemPurchasedFromSideShop
  128. GetItemStockCount
  129.  
  130. GetPushLaneDesire
  131. GetDefendLaneDesire
  132. GetFarmLaneDesire
  133. GetRoamDesire
  134. GetRoamTarget
  135. GetRoshanDesire
  136.  
  137. int GetGameState()
  138. Returns the current game state [LINK HERE]
  139.  
  140. float GetGameStateTimeRemaining()
  141. Returns how much time is remaining in the curren game state, if applicable
  142.  
  143. int GetGameMode()
  144. Returns the current game mode [LINK HERE]
  145.  
  146. int GetHeroPickState()
  147. Returns the current hero pick state [LINK HERE]
  148.  
  149. IsPlayerInHeroSelectionControl
  150. SelectHero
  151. GetSelectedHeroName
  152.  
  153. IsInCMBanPhase
  154. IsInCMPickPhase
  155. GetCMPhaseTimeRemaining
  156. GetCMCaptain
  157. SetCMCaptain
  158. IsCMBannedHero
  159. IsCMPickedHero
  160. CMBanHero
  161. CMPickHero
  162.  
  163. RandomInt
  164. RandomFloat
  165. RandomYawVector
  166. RollPercentage
  167. Min
  168. Max
  169. Clamp
  170. RemapVal
  171. RemapValClamped
  172.  
  173. DebugDrawLine
  174. DebugDrawCircle
  175. DebugDrawText
  176.  
  177. Unit-Scoped
  178.  
  179. Action_ClearActions
  180. Action_MoveToLocation
  181. Action_MoveToUnit
  182. Action_AttackUnit
  183. Action_AttackMove
  184. Action_UseAbility
  185. Action_UseAbilityOnEntity
  186. Action_UseAbilityOnLocation
  187. Action_UseAbilityOnTree
  188. Action_PickUpRune
  189. Action_PickUpItem
  190. Action_DropItem
  191. Action_PurchaseItem
  192. Action_SellItem
  193. Action_Buyback
  194. Action_LevelAbility
  195.  
  196. GetDifficulty
  197. GetUnitName
  198. GetPlayer
  199. IsHero
  200. IsCreep
  201. IsTower
  202. IsBuilding
  203. IsFort
  204. IsIllusion
  205.  
  206. CanBeSeen
  207. GetActiveMode
  208. GetActiveModeDesire
  209. GetHealth
  210. GetMaxHealth
  211. GetMana
  212. GetMaxMana
  213. IsAlive
  214. GetRespawnTime
  215. HasBuyback
  216. GetGold
  217. GetStashValue
  218. GetCourierValue
  219. GetLocation
  220. GetFacing
  221. GetGroundHeight
  222. GetAbilityByName
  223. GetItemInSlot
  224. IsChanneling
  225. IsUsingAbility
  226. GetVelocity
  227. GetAttackTarget
  228. GetLastSeenLocation
  229. GetTimeSinceLastSeen
  230.  
  231. IsRooted
  232. IsDisarmed
  233. IsAttackImmune
  234. IsSilenced
  235. IsMuted
  236. IsStunned
  237. IsHexed
  238. IsInvulnerable
  239. IsMagicImmune
  240. IsNightmared
  241. IsBlockDisabled
  242. IsEvadeDisabled
  243. IsUnableToMiss
  244. IsSpeciallyDeniable
  245. IsDominated
  246. IsBlind
  247. HasScepter
  248.  
  249. WasRecentlyDamagedByAnyHero
  250. WasRecentlyDamagedByHero
  251. TimeSinceDamagedByAnyHero
  252. TimeSinceDamagedByHero
  253.  
  254. DistanceFromFountain
  255. DistanceFromSideShop
  256. DistanceFromSecretShop
  257.  
  258. SetTarget
  259. GetTarget
  260.  
  261. SetNextItemPurchaseValue
  262. GetNextItemPurchaseValue
  263.  
  264. GetAssignedLane
  265.  
  266. GetEstimatedDamageToTarget
  267. GetStunDuration
  268. GetSlowDuration
  269. HasBlink
  270. HasMinistunOnAttack
  271. HasSilence
  272. HasInvisibility
  273. UsingItemBreaksInvisibility
  274.  
  275. GetNearbyHeroes
  276. GetNearbyTowers
  277. GetNearbyCreeps
  278.  
  279. FindAoELocation
  280.  
  281. GetExtrapolatedLocation
  282. GetMovementDirectionStability
  283.  
  284. GetActualDamage
  285.  
  286. Editing in Progress
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement