Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- ***********************************
- -- Sample AI handling system
- -- By Matt @serverdev.net
- -- ***********************************
- -- --------------------------
- -- Set of functions which might be useful to all AI
- -- But does not exists in standard
- -- --------------------------
- print( " * Loading Lib functions" )
- -- Return true is the unit is friendly, false othervise
- -- A unit is considered friendly if:
- -- * the target is the host of the source monster
- -- * the target belongs to the same party as the sources host
- -- * the target belongs to the same guild as the sources host
- function isFriendly(source, target)
- local source_host = GetChaHost(source)
- local target_host = GetChaHost(target)
- -- Target is in hosts team
- local sourceTeamID = GetChaTeamID(source_host)
- if (sourceTeamID ~= 0 and sourceTeamID == GetChaTeamID(target)) then
- return true
- end
- -- Target is in hosts guild
- local sourceGuildID = GetChaGuildID(source_host)
- if (sourceGuildID ~= 0 and sourceGuildID == GetChaGuildID(target)) then
- return true
- end
- -- Target is in hosts side
- local sourceSideID = GetChaSideID(source_host)
- if (sourceSideID ~= 0 and sourceSideID == GetChaSideID(target)) then
- return true
- end
- local team = is_teammate(source_host, target)
- if (team == 1) then
- return true
- end
- local map_type = GetChaMapType(source)
- if(map_type == 0)then -- PVP is OFF
- if(IsPlayer(target) == 1) then
- return true
- end
- if(target_host ~= nil)then
- if(IsPlayer(target_host) == 1) then
- return true
- end
- end
- end
- --[[ if(target_host ~= nil)then
- if(is_teammate(source_host, target_host) == 1)then
- return true
- end
- print("yes")
- end ]]--
- return false
- end
- function isAlive(source)
- if source == nil or source == 0 then
- return false
- end
- if Hp(source) <= 0 then
- return false
- end
- if IsChaLiving(source) ~= 1 then
- return false
- end
- return true
- end
- function npc_move(cha,range,id)
- local move_flag = Rand(20)
- if move_flag > 1 then return end --Only 1 / 18 chance of random movement, limiting the frequency of random movement
- x, y = npclooplist[id].x,npclooplist[id].y
- rx = x + range - Rand(range * 2)
- ry = y + range - Rand(range * 2)
- if is_pos_valid(cha, x, y)==0 then return end --Illegal destination for this character, then stop
- ChaMove(cha, rx, ry)
- end
- function isSealed(cha)
- local magic_seal = GetChaStateLv ( cha , STATE_JNJZ )
- local phsic_seal = GetChaStateLv ( cha , STATE_GJJZ )
- if magic_seal >= 1 then
- return true
- end
- if phsic_seal >= 1 then
- return true
- end
- return false
- end
- -- This happens when the opponent is a Champion
- function target_is_champ(monster,target)
- -- Maybe he is luring us,but what if his hp is low?
- local hp_percent = math.ceil( (Hp (target) / Mxhp (target)) * 100)
- if hp_percent <= 30 then
- ChaSay(target,monster,"Haha Champion! You are trying to lure me , but your hp is pretty low! I shall kill you")
- SetChaTarget(monster,target)
- else
- -- Champion will be mostly trying to luring us so we search for a new target^^
- clear_target(monster)
- end
- end
- -- This happens when the opponent is a Crus
- function target_is_crus(monster,target)
- local rand = Percentage_Random(0.8)
- -- Whats the weak spot of a Crus? Melee! We will seal him xD
- local sklv = GetSkillLv( monster , 105 ) -- Lets Check if our Boss got the Seal Skill
- local R = math.random(1,5)
- if sklv ~= 0 then
- -- Lets Check if he is sealed already
- local seal = GetChaStateLv ( target ,STATE_GJJZ )
- -- Use the skill only if the character is not sealed!
- if seal == 0 and rand == 1 and R == 2 then
- ChaUseSkill(monster, target, 105)
- ChaSay(target,monster,"Crusader huh?,Time to seal!")
- end
- end
- local skill_id = select_skill(monster)
- ChaUseSkill(monster, target, skill_id)
- end
- -- This happens when the opponent is a Cleric
- function target_is_cleric(monster,target)
- local Maxsp = Mxsp(target)
- local sp = Sp(target)
- local r = Percentage_Random(0.3)
- if (r==1) then
- ChaSay(target,monster,"Cleric! You chose to aid those venturers who try to kill me! I shall remove all your SP!")
- Sp_Red(target,Maxsp)
- end
- end
- -- This happens when the opponent is a Seal Master
- function target_is_sm(monster,target)
- local x,y = GetChaPos(target)
- local map_type = GetChaMapType(target)
- local now_tick = GetChaParam(monster,1)
- local rand = Percentage_Random(0.1)
- local target_map = GetChaMapName(target)
- local away = get_distance(monster, target)
- local statelevel = 10
- local statetime = math.random(3,7)
- local hp = Mxhp(target)
- local kill = hp* 2
- if away > 1000 and (map_type ~= 0) then
- ChaSay(target,monster,"Im coming to kill you lovely Seal Master,Prepare im teleporting in 5 seconds")
- BickerNotice(target,""..GetChaDefaultName(monster).." is coming to you , Prepare")
- if math.mod(now_tick, 5) == 0 and now_tick > 0 then
- GoTo(monster,math.floor(x/100),math.floor(y/100),target_map)
- if rand == 1 then
- BickerNotice(target,"Powerfull teleport , Drained your whole hp!")
- SetChaAttr(target,ATTR_MXHP,-1)
- elseif rand ~= 1 then
- BickerNotice(target,"Teleport damage, "..statetime.." seconds stun!")
- AddState ( monster , target , STATE_XY , statelevel , statetime )
- PlayEffect(monster,132)
- end
- end
- end
- end
- -- This happens when the opponent is a Voyager
- function target_is_voy(monster,target)
- local ra = Percentage_Random(0.5)
- local sklv = GetSkillLv( monster , 105 ) -- Lets Check if our Boss got the Seal Skill
- local R = math.random(1,5)
- if sklv ~= 0 then
- -- Lets Check if he is sealed already
- local seal = GetChaStateLv ( target ,STATE_GJJZ )
- -- Use the skill only if the character is not sealed!
- if seal == 0 and ra == 1 and R == 2 then
- ChaSay(target,monster,"Voyager, I see! I will not let you use your skills!")
- ChaUseSkill(monster, target, 105)
- end
- end
- if math.mod(now_tick,4) == 0 and now_tick > 0 then
- Sp_Red(target,500)
- end
- end
- function target_is_ss(monster,target)
- -- Since ss use ranged attacks lets teleport him near us
- if(math.random(1,5) = 5)then
- BickerNotice(target,"Come here SS , I wont let you able to attack me")
- local x,y = GetChaPos(monster)
- local map = GetChaMapName(monster)
- GoTo(target,math.floor(x/100),math.floor(y/100),map)
- end
- local skill_id = select_skill(monster)
- ChaUseSkill(monster, target, skill_id)
- end
Add Comment
Please, Sign In to add comment