Pet AI Scripting

Pet AI scripts can execute as server scripts when saved in project_folder/ServerScripts with the file name Hello.lua.

pet: Represents the unit (ScriptUnit) of the pet.
ai: Represents the action(ScriptPetUnitAI) to be performed.
event: Identifies the logic to be executed.
AI_INIT(-1) : Runs when pet AI is first initialized, AI_UPDATE (0): Executes every 2 seconds.

Example) Server script - Setting Pet AI

Server.SetPetAI( 21, --the index of pet function(pet,ai,event) --executes on first PetAI initialization if(event == AI_INIT) then ai.customData.timer = 1; end --executes every 2 seconds if(event == AI_UPDATE) then --If distance value becomes 200, follows master. --If distance value becomes 400, teleports to master. --ai.SetFollowMaster(true,200,400) --If no target, follows master. if(ai.GetTargetUnit() == nil) then ai.SetFollowMaster(true,200,400) end --basic 100,200 --ai.SetFollowMaster(true) --sets the target as the closest enemy unit ai.SetNearTarget(2,200) --Uses skill if target of pet exists --Skills are fired towards the target by default. if(ai.GetTargetUnit() ~= nil) then --Stops tracking when targets are set ai.SetFollowMaster(false) ai.StopMove() --moves to target and attack once target is set ai.MoveToPosition(ai.GetTargetUnit().x,ai.GetTargetUnit().y) --adds buff to master ai.AddMasterBuff(15) -- fires in the direction of the target ai.UseSkill(23) -- Sets firing from the pet's master position to the target ai.UseSkill( 22 ,nil ,Point(ai.GetMasterUnit().x,ai.GetMasterUnit().y)) end --Acquires nearby dropped items once every 6 seconds using the custom data timer ai.customData.timer = ai.customData.timer + 1; if(ai.customData.timer == 3) then -- Obtain a drop item within a radius of 100 ai.AcquireNearDropItem(100) ai.customData.timer = 0; end end end )

SUPERCAT Inc. All Rights Reserved.