Guest User

Untitled

a guest
Jul 21st, 2018
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.58 KB | None | 0 0
  1. -- --------------------------
  2. -- AI DEDICATED TO "AI_PET"
  3. -- --------------------------
  4. -- AI_PET Mod is a sample of what can be done.
  5. -- The base idea will be that the summoned pet is
  6. -- not aggressive toward owner. Whenever it has nothing to
  7. -- do, it will attempt to follow its master.
  8. -- Othervise, it will try to attack the master s target.
  9.  
  10. print( " * Loading AI_PET functions" )
  11.  
  12. -- This is what happen when a pet has a target
  13. function AI_PET_has_target(monster, target)
  14. local master = GetChaHost(monster)
  15. -- If target is friendly, change target. Othervise, attack it !
  16. if (isFriendly(monster, target) == true) then
  17. clear_target(monster)
  18. else
  19. local skill_id = select_skill(monster)
  20. ChaUseSkill(monster, target, skill_id)
  21. if(math.random(1,20) == 5)then
  22. ChaSay(master,monster,"Master, "..GetChaDefaultName(target).." starts to piss me off #13!")
  23. end
  24. if(IsPlayer(target) == 0)then
  25. local heal = GetChaAttr(target,ATTR_MXHP)
  26. local attack = GetChaAttr(monster,ATTR_BMXATK)
  27. local hp_percent = math.ceil( (Hp (target) / Mxhp (target)) * 100)
  28. if hp_percent < 30 or heal < attack then
  29. clear_target(monster)
  30. ChaSay(master,monster,""..GetChaDefaultName(target).." is too weak for me , Or his hp is too low for my attack")
  31. else
  32. ChaSay(master,monster,"Im attacking "..GetChaDefaultName(target).." with "..math.random(GetChaAttr(monster , ATTR_BMNATK) ,GetChaAttr(monster , ATTR_BMXATK )).."!")
  33. local dmg = GetChaAttr(monster,ATTR_BMXATK)
  34. local R = math.random(1,10)
  35. local RX = R * 10
  36. local dmgx = dmg + RX
  37. local damage = -1* dmg + RX
  38.  
  39.  
  40. SetChaAttr(target,ATTR_MXHP,GetChaAttr(target,ATTR_MXHP)+damage)
  41. PlayEffect(target,101)
  42. end
  43. end
  44. end
  45. end
  46.  
  47.  
  48. -- This is what happen when a pet has no target
  49. function AI_PET_no_target(monster)
  50.  
  51. local master = GetChaHost(monster)
  52.  
  53. -- No target and no master, switch to aggressive mode
  54. if (master == nil) then
  55. SetChaAIType(monster, AI_ATK)
  56. return
  57. end
  58.  
  59. local cha_map = GetChaMapName (master)
  60. local distance_to_master = get_distance(master,monster)
  61. -- Lets Teleport to our Master
  62. local rand_chat = math.random(1,4)
  63. if distance_to_master > 1200 then
  64. local x,y = GetChaPos (master)
  65. GoTo(monster,math.floor (x/100),math.floor (y/100),cha_map)
  66. if rand_chat == 1 then
  67. ChaSay(master,monster,"You ran away , So i teleported to you #07!")
  68. elseif rand_chat == 2 then
  69. ChaSay(master,monster,"Master Stop making me teleport to you #04!")
  70. elseif rand_chat == 3 then
  71. ChaSay(master,monster,"Stop running too fast! #03")
  72. elseif rand_chat == 4 then
  73. ChaSay(master,monster,"You can't get away master #05!")
  74. end
  75. end
  76. -- Nothing todo Go to our Master
  77. local distance_to_master = get_distance(monster, master)
  78. if distance_to_master > 400 then
  79. local hx, hy = GetChaPos(master)
  80. local rx = 200 - Rand(400)
  81. local ry = 200 - Rand(400)
  82. ChaMove(monster, hx + rx, hy + ry)
  83. -- Lets make our Pet talk a bit xD
  84. if 5 >= Rand(1000) then
  85. ChaSay(master,monster,"Hey, Master wait for me #15!!")
  86. end
  87. if 3 >= Rand(1000) then
  88. ChaSay(master,monster,"don't run away master #03")
  89. if(math.random(1,30) == 5)then
  90. ChaSay(master,monster,"Master , I love you more than anything in that world #01")
  91. end
  92. end
  93. end
  94. end
  95.  
  96. -- This is what happen everytime
  97. function AI_PET_tick(monster)
  98. local master = GetChaHost(monster)
  99. local name = GetChaDefaultName(master)
  100. local randomVal = 6;
  101. if (randomVal <= 5) then
  102. SetChaAIType(monster, AI_ATK)
  103. BickerNotice(master, "Ouch, your pet is getting angry")
  104. end
  105.  
  106. if(IsChaLiving(master) ~= 1)then
  107. KillCha(monster)
  108. end
  109. -- If Master is not alive
  110. if isAlive(master) == false then
  111. KillCha(monster)
  112. end
  113.  
  114. -- No target and no master, switch to aggressive mode
  115. if (master == nil) then
  116. SetChaAIType(monster, AI_ATK)
  117. return
  118. end
  119.  
  120.  
  121. if(GetChaTarget(monster) == nil)then
  122. local master_target = GetChaTarget(master)
  123. local ChaList = {}
  124. local Rand = math.random(2,12)
  125. ChaList[2] , ChaList[3] , ChaList[4] , ChaList[5] , ChaList[6] , ChaList[7] , ChaList[8] , ChaList[9] , ChaList[10] , ChaList[11] , ChaList[12] = GetChaSetByRange ( monster , 0 ,0 ,600 , 0)
  126. if(ChaList[Rand] ~= nil and ChaList[Rand] ~= master and GetChaHost(ChaList[Rand]) ~= master )then
  127. SetChaTarget(monster, ChaList[Rand])
  128. local heal = GetChaAttr(target,ATTR_MXHP)
  129. local attack = GetChaAttr(monster,ATTR_BMXATK)
  130. local hp_percent = math.ceil( (Hp (target) / Mxhp (target)) * 100)
  131. if hp_percent < 30 or heal < attack then
  132. clear_target(monster)
  133. else
  134. SetChaTarget(monster, ChaList[Rand])
  135. end
  136. end
  137. end
  138. end
Add Comment
Please, Sign In to add comment