The3vilM0nk3y

MobAI Controller

Apr 22nd, 2017
229
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.29 KB | None | 0 0
  1. #Flags for mobs:
  2. # .isMob = All hostile mobs should get this one
  3. # .isMonster = All basic hostiles that need basic targeting and pathing
  4. # .isBoss = For bosses that do stuff during update.
  5. # .basicIgnoreTargeting = Hostiles with this flag will be ignored by basic hostiles
  6. #
  7. # Runs repeatedly as the mobAI logic loop
  8. mobAI_task_logic:
  9. type: task
  10. debug: false
  11. script:
  12. #get all our custom mob npc's
  13. - event "mobai logic"
  14. - foreach <server.get_npcs_flagged[mobAI.doLogic]> {
  15. #logic loop for default mob AI tagged as .isMonster
  16. - if <def[value].is_spawned> && !<def[value].flag[mobAI.isMonster]> {
  17. #Tell it to attack/check its target
  18. - run mobAI_task_attack as:<def[value]> instantly
  19. #if it still doesn't have a target, resume pathing
  20. - if <def[value].flag[mobAI.target]||null> == null {
  21. - resume waypoints npc:%value%
  22. }
  23. - queue clear
  24. }
  25. #Check for another monstertype - boss
  26.  
  27. - run mobAI_task_logic delay:10t
  28.  
  29. # Chooses a nearby target
  30. mobAI_task_picktarget:
  31. type: task
  32. debug: false
  33. script:
  34. - ^flag npc mobAI.target:null
  35. - ^define entities <npc.location.find.npcs.within[<npc.flag[mobAI.trackingRange]>]>
  36. - ^define entity null
  37. - ^foreach %entities% {
  38. - if !<%value%.flag[mobAI.basicIgnoreTargeting]> {
  39. - define entities <def[entities].exclude[%value%]>
  40. }
  41. elseif <%value%.distance[<npc.flag[mobAI.spawnLocation]>]> > <npc.flag[mobAI.maxTrackingRange]> {
  42. - define entities <def[entities].exclude[%value%]>
  43. }
  44. elseif <%value%.is_player> {
  45. if <%value%.gamemode.id> != 0 {
  46. - define entities <def[entities].exclude[%value%]>
  47. }
  48. }
  49. }
  50. - ^foreach %entities% {
  51. - if <npc.can_see[%value%]> {
  52. - define entity %value%
  53. - foreach stop
  54. }
  55. }
  56. - ^flag npc mobAI.target:%entity%
  57. - event "mobai found_target" context:npc|<npc>|target|%entity%
  58.  
  59. # Makes a sentry NPC attack the target
  60. mobAI_task_attack:
  61. type: task
  62. debug: true
  63. script:
  64. #increment attack cooldown
  65. - ^flag npc mobAI.attackCooldown:<npc.flag[mobAI.attackCooldown].add[10].asint>
  66. #check if it's time to reset its attack cooldown and start attack
  67. - ^if <npc.flag[mobAI.attackCooldown]> >= <npc.flag[mobAI.attackRate]> {
  68. - flag npc mobAI.attackCooldown:0
  69. }
  70. else {
  71. - queue clear
  72. }
  73. #pick new target if it doesnt have one
  74. - ^if <npc.flag[mobAI.target]> == null {
  75. - ^inject mobAI_task_picktarget
  76. }
  77. #otherwise check if its current target is not valid anymore and get a new one
  78. else {
  79. - if !<util.entity_is_spawned[<npc.flag[mobAI.target]>]> || !<npc.can_see[<npc.flag[mobAI.target]>]||false> {
  80. - inject mobAI_task_picktarget
  81. - if <npc.flag[mobAI.target]> == null {
  82. - flag npc mobAI.lostTarget:true
  83. }
  84. }
  85. }
  86. #if still no target, end attack
  87. - ^if <npc.flag[mobAI.target]> == null {
  88. - if <npc.flag[mobAI.lostTarget]> == true {
  89. - event "mobai lost_target" context:npc|<npc>
  90. }
  91. - inject mobAI_task_pathfind
  92. - queue clear
  93. }
  94.  
  95. #get location of target and calculate if it's in attack range
  96. - ^define loc <npc.flag[mobAI.target].as_entity.location.add[0,0.33,0]>
  97. - if <npc.location.distance[%loc%]> < <npc.flag[mobAI.attackRange]> {
  98. - ^look %loc%
  99. - ^pause waypoints
  100. - event "mobai attack" context:npc|<npc>|target|<npc.flag[mobAI.target].as_entity>
  101.  
  102. mobAI_task_pathfind:
  103. type: task
  104. debug: false
  105. script:
  106. - if <npc.location.distance[<npc.flag[mobAI.spawnLocation]>]> > <npc.flag[mobAI.wanderDistance]> {
  107. - walk <npc.flag[mobAI.spawnLocation]> speed:<npc.flag[mobAI.speed]> lookat:<npc.flag[mobAI.spawnLocation]>
  108. - queue clear
  109. }
  110. - if <npc.flag[lastPathfind]> > 0 {
  111. - flag npc mobAI.lastPathfind:<npc.flag[mobAI.lastPathfind].sub[10]>
  112. - queue clear
  113. }
  114. - walk <npc.flag[mobAI.spawnLocation]> speed:<npc.flag[mobAI.speed]> lookat:<npc.flag[mobAI.spawnLocation]> radius:lookat:<npc.flag[mobAI.wanderDistance]>
  115. mobAI_attack:
  116. type: task
  117. debug: false
  118. script:
  119. #get fail chance
  120. - if <npc.has_flag[attackFailChance]> == true {
  121. - if <util.random.int[1].to[100]> <= <npc.flag[attackFailChance]> {
  122. - queue clear
  123. }
  124. #get base damage
  125. - if <npc.has_flag[mobAI.damage]> == true {
  126. - flag npc mobAI.currentDmg:<npc.flag[mobAI.damage]>
  127. }
  128. else {
  129. - flag npc mobAI.currentDmg:<yaml[mobAI_mobs].read[default.damage]>
  130. }
  131. #critical
  132. - if <npc.has_flag[criticalChance]> == true {
  133. - if <util.random.int[1].to[100]> <= <npc.flag[criticalChance]> {
  134. - flag npc mobAI.critBonus:<npc.flag[mobAI.currentDmg].mul[<npc.flag[mobAI.criticalPercent].div[100]>]>
  135. }
  136. }
  137. #condition effects
  138. #armor calculations for players
  139. - if <npc.flag[mobAI.target].is_player> == true {
  140. #base values
  141. #slashing
  142. #crushing
  143. #shattering
  144. #piercing
  145. }
  146. mobAI_task_removearrow:
  147. type: task
  148. debug: false
  149. script:
  150. - if %hit_entities% == li@ remove %shot_entities%
Advertisement
Add Comment
Please, Sign In to add comment