Guest User

Untitled

a guest
Jul 21st, 2018
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.29 KB | None | 0 0
  1. -- ***********************************
  2. -- Sample AI handling system
  3. -- By Matt @serverdev.net
  4. -- ***********************************
  5.  
  6. -- --------------------------
  7. -- Set of functions which might be useful to all AI
  8. -- But does not exists in standard
  9. -- --------------------------
  10.  
  11. print( " * Loading Lib functions" )
  12.  
  13.  
  14. -- Return true is the unit is friendly, false othervise
  15. -- A unit is considered friendly if:
  16. -- * the target is the host of the source monster
  17. -- * the target belongs to the same party as the sources host
  18. -- * the target belongs to the same guild as the sources host
  19. function isFriendly(source, target)
  20. local source_host = GetChaHost(source)
  21. local target_host = GetChaHost(target)
  22.  
  23. -- Target is in hosts team
  24. local sourceTeamID = GetChaTeamID(source_host)
  25. if (sourceTeamID ~= 0 and sourceTeamID == GetChaTeamID(target)) then
  26. return true
  27. end
  28.  
  29. -- Target is in hosts guild
  30. local sourceGuildID = GetChaGuildID(source_host)
  31. if (sourceGuildID ~= 0 and sourceGuildID == GetChaGuildID(target)) then
  32. return true
  33. end
  34.  
  35. -- Target is in hosts side
  36. local sourceSideID = GetChaSideID(source_host)
  37. if (sourceSideID ~= 0 and sourceSideID == GetChaSideID(target)) then
  38. return true
  39. end
  40.  
  41. local team = is_teammate(source_host, target)
  42. if (team == 1) then
  43. return true
  44. end
  45.  
  46. local map_type = GetChaMapType(source)
  47. if(map_type == 0)then -- PVP is OFF
  48. if(IsPlayer(target) == 1) then
  49. return true
  50. end
  51. if(target_host ~= nil)then
  52. if(IsPlayer(target_host) == 1) then
  53. return true
  54. end
  55. end
  56. end
  57.  
  58. --[[ if(target_host ~= nil)then
  59. if(is_teammate(source_host, target_host) == 1)then
  60. return true
  61. end
  62. print("yes")
  63. end ]]--
  64.  
  65. return false
  66. end
  67.  
  68. function isAlive(source)
  69. if source == nil or source == 0 then
  70. return false
  71. end
  72. if Hp(source) <= 0 then
  73. return false
  74. end
  75. if IsChaLiving(source) ~= 1 then
  76. return false
  77. end
  78.  
  79. return true
  80. end
  81.  
  82. function npc_move(cha,range,id)
  83. local move_flag = Rand(20)
  84.  
  85. if move_flag > 1 then return end --Only 1 / 18 chance of random movement, limiting the frequency of random movement
  86.  
  87. x, y = npclooplist[id].x,npclooplist[id].y
  88. rx = x + range - Rand(range * 2)
  89. ry = y + range - Rand(range * 2)
  90. if is_pos_valid(cha, x, y)==0 then return end --Illegal destination for this character, then stop
  91. ChaMove(cha, rx, ry)
  92. end
  93.  
  94. function isSealed(cha)
  95. local magic_seal = GetChaStateLv ( cha , STATE_JNJZ )
  96. local phsic_seal = GetChaStateLv ( cha , STATE_GJJZ )
  97. if magic_seal >= 1 then
  98. return true
  99. end
  100. if phsic_seal >= 1 then
  101. return true
  102. end
  103.  
  104. return false
  105. end
  106.  
  107. -- This happens when the opponent is a Champion
  108. function target_is_champ(monster,target)
  109. -- Maybe he is luring us,but what if his hp is low?
  110.  
  111. local hp_percent = math.ceil( (Hp (target) / Mxhp (target)) * 100)
  112. if hp_percent <= 30 then
  113. ChaSay(target,monster,"Haha Champion! You are trying to lure me , but your hp is pretty low! I shall kill you")
  114. SetChaTarget(monster,target)
  115. else
  116. -- Champion will be mostly trying to luring us so we search for a new target^^
  117. clear_target(monster)
  118. end
  119. end
  120.  
  121. -- This happens when the opponent is a Crus
  122. function target_is_crus(monster,target)
  123. local rand = Percentage_Random(0.8)
  124. -- Whats the weak spot of a Crus? Melee! We will seal him xD
  125. local sklv = GetSkillLv( monster , 105 ) -- Lets Check if our Boss got the Seal Skill
  126. local R = math.random(1,5)
  127. if sklv ~= 0 then
  128. -- Lets Check if he is sealed already
  129. local seal = GetChaStateLv ( target ,STATE_GJJZ )
  130. -- Use the skill only if the character is not sealed!
  131. if seal == 0 and rand == 1 and R == 2 then
  132. ChaUseSkill(monster, target, 105)
  133. ChaSay(target,monster,"Crusader huh?,Time to seal!")
  134. end
  135. end
  136. local skill_id = select_skill(monster)
  137. ChaUseSkill(monster, target, skill_id)
  138. end
  139.  
  140. -- This happens when the opponent is a Cleric
  141. function target_is_cleric(monster,target)
  142. local Maxsp = Mxsp(target)
  143. local sp = Sp(target)
  144. local r = Percentage_Random(0.3)
  145. if (r==1) then
  146. ChaSay(target,monster,"Cleric! You chose to aid those venturers who try to kill me! I shall remove all your SP!")
  147. Sp_Red(target,Maxsp)
  148. end
  149.  
  150.  
  151.  
  152. end
  153.  
  154. -- This happens when the opponent is a Seal Master
  155. function target_is_sm(monster,target)
  156. local x,y = GetChaPos(target)
  157. local map_type = GetChaMapType(target)
  158. local now_tick = GetChaParam(monster,1)
  159. local rand = Percentage_Random(0.1)
  160. local target_map = GetChaMapName(target)
  161. local away = get_distance(monster, target)
  162. local statelevel = 10
  163. local statetime = math.random(3,7)
  164. local hp = Mxhp(target)
  165. local kill = hp* 2
  166. if away > 1000 and (map_type ~= 0) then
  167. ChaSay(target,monster,"Im coming to kill you lovely Seal Master,Prepare im teleporting in 5 seconds")
  168. BickerNotice(target,""..GetChaDefaultName(monster).." is coming to you , Prepare")
  169. if math.mod(now_tick, 5) == 0 and now_tick > 0 then
  170. GoTo(monster,math.floor(x/100),math.floor(y/100),target_map)
  171. if rand == 1 then
  172. BickerNotice(target,"Powerfull teleport , Drained your whole hp!")
  173. SetChaAttr(target,ATTR_MXHP,-1)
  174. elseif rand ~= 1 then
  175. BickerNotice(target,"Teleport damage, "..statetime.." seconds stun!")
  176. AddState ( monster , target , STATE_XY , statelevel , statetime )
  177. PlayEffect(monster,132)
  178. end
  179. end
  180. end
  181. end
  182. -- This happens when the opponent is a Voyager
  183. function target_is_voy(monster,target)
  184. local ra = Percentage_Random(0.5)
  185. local sklv = GetSkillLv( monster , 105 ) -- Lets Check if our Boss got the Seal Skill
  186. local R = math.random(1,5)
  187. if sklv ~= 0 then
  188. -- Lets Check if he is sealed already
  189. local seal = GetChaStateLv ( target ,STATE_GJJZ )
  190. -- Use the skill only if the character is not sealed!
  191. if seal == 0 and ra == 1 and R == 2 then
  192. ChaSay(target,monster,"Voyager, I see! I will not let you use your skills!")
  193. ChaUseSkill(monster, target, 105)
  194. end
  195. end
  196. if math.mod(now_tick,4) == 0 and now_tick > 0 then
  197. Sp_Red(target,500)
  198. end
  199.  
  200.  
  201. end
  202.  
  203. function target_is_ss(monster,target)
  204. -- Since ss use ranged attacks lets teleport him near us
  205. if(math.random(1,5) = 5)then
  206. BickerNotice(target,"Come here SS , I wont let you able to attack me")
  207. local x,y = GetChaPos(monster)
  208. local map = GetChaMapName(monster)
  209. GoTo(target,math.floor(x/100),math.floor(y/100),map)
  210. end
  211. local skill_id = select_skill(monster)
  212. ChaUseSkill(monster, target, skill_id)
  213. end
Add Comment
Please, Sign In to add comment