Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- --------------------------
- -- AI DEDICATED TO "AI_PET"
- -- --------------------------
- -- AI_PET Mod is a sample of what can be done.
- -- The base idea will be that the summoned pet is
- -- not aggressive toward owner. Whenever it has nothing to
- -- do, it will attempt to follow its master.
- -- Othervise, it will try to attack the master s target.
- print( " * Loading AI_PET functions" )
- -- This is what happen when a pet has a target
- function AI_PET_has_target(monster, target)
- local master = GetChaHost(monster)
- -- If target is friendly, change target. Othervise, attack it !
- if (isFriendly(monster, target) == true) then
- clear_target(monster)
- else
- local skill_id = select_skill(monster)
- ChaUseSkill(monster, target, skill_id)
- if(math.random(1,20) == 5)then
- ChaSay(master,monster,"Master, "..GetChaDefaultName(target).." starts to piss me off #13!")
- end
- if(IsPlayer(target) == 0)then
- local heal = GetChaAttr(target,ATTR_MXHP)
- local attack = GetChaAttr(monster,ATTR_BMXATK)
- local hp_percent = math.ceil( (Hp (target) / Mxhp (target)) * 100)
- if hp_percent < 30 or heal < attack then
- clear_target(monster)
- ChaSay(master,monster,""..GetChaDefaultName(target).." is too weak for me , Or his hp is too low for my attack")
- else
- ChaSay(master,monster,"Im attacking "..GetChaDefaultName(target).." with "..math.random(GetChaAttr(monster , ATTR_BMNATK) ,GetChaAttr(monster , ATTR_BMXATK )).."!")
- local dmg = GetChaAttr(monster,ATTR_BMXATK)
- local R = math.random(1,10)
- local RX = R * 10
- local dmgx = dmg + RX
- local damage = -1* dmg + RX
- SetChaAttr(target,ATTR_MXHP,GetChaAttr(target,ATTR_MXHP)+damage)
- PlayEffect(target,101)
- end
- end
- end
- end
- -- This is what happen when a pet has no target
- function AI_PET_no_target(monster)
- local master = GetChaHost(monster)
- -- No target and no master, switch to aggressive mode
- if (master == nil) then
- SetChaAIType(monster, AI_ATK)
- return
- end
- local cha_map = GetChaMapName (master)
- local distance_to_master = get_distance(master,monster)
- -- Lets Teleport to our Master
- local rand_chat = math.random(1,4)
- if distance_to_master > 1200 then
- local x,y = GetChaPos (master)
- GoTo(monster,math.floor (x/100),math.floor (y/100),cha_map)
- if rand_chat == 1 then
- ChaSay(master,monster,"You ran away , So i teleported to you #07!")
- elseif rand_chat == 2 then
- ChaSay(master,monster,"Master Stop making me teleport to you #04!")
- elseif rand_chat == 3 then
- ChaSay(master,monster,"Stop running too fast! #03")
- elseif rand_chat == 4 then
- ChaSay(master,monster,"You can't get away master #05!")
- end
- end
- -- Nothing todo Go to our Master
- local distance_to_master = get_distance(monster, master)
- if distance_to_master > 400 then
- local hx, hy = GetChaPos(master)
- local rx = 200 - Rand(400)
- local ry = 200 - Rand(400)
- ChaMove(monster, hx + rx, hy + ry)
- -- Lets make our Pet talk a bit xD
- if 5 >= Rand(1000) then
- ChaSay(master,monster,"Hey, Master wait for me #15!!")
- end
- if 3 >= Rand(1000) then
- ChaSay(master,monster,"don't run away master #03")
- if(math.random(1,30) == 5)then
- ChaSay(master,monster,"Master , I love you more than anything in that world #01")
- end
- end
- end
- end
- -- This is what happen everytime
- function AI_PET_tick(monster)
- local master = GetChaHost(monster)
- local name = GetChaDefaultName(master)
- local randomVal = 6;
- if (randomVal <= 5) then
- SetChaAIType(monster, AI_ATK)
- BickerNotice(master, "Ouch, your pet is getting angry")
- end
- if(IsChaLiving(master) ~= 1)then
- KillCha(monster)
- end
- -- If Master is not alive
- if isAlive(master) == false then
- KillCha(monster)
- end
- -- No target and no master, switch to aggressive mode
- if (master == nil) then
- SetChaAIType(monster, AI_ATK)
- return
- end
- if(GetChaTarget(monster) == nil)then
- local master_target = GetChaTarget(master)
- local ChaList = {}
- local Rand = math.random(2,12)
- 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)
- if(ChaList[Rand] ~= nil and ChaList[Rand] ~= master and GetChaHost(ChaList[Rand]) ~= master )then
- SetChaTarget(monster, ChaList[Rand])
- local heal = GetChaAttr(target,ATTR_MXHP)
- local attack = GetChaAttr(monster,ATTR_BMXATK)
- local hp_percent = math.ceil( (Hp (target) / Mxhp (target)) * 100)
- if hp_percent < 30 or heal < attack then
- clear_target(monster)
- else
- SetChaTarget(monster, ChaList[Rand])
- end
- end
- end
- end
Add Comment
Please, Sign In to add comment