몬스터 AI 스크립팅
스크립트
설명
Server.SetMonsterAI(
22, --AI를 적용할 몬스터의 인덱스
function(enemy,ai,event,data)
-- 최초 몬스터 AI 등록 시 실행
if(event == AI_INIT) then
ai.customData.test = 1;
end
if (event == AI_UPDATE) then
--현재 필드의 유닛들 중에서 조건에 해당하는 유닛 반환
--예) 유닛 hp가 100보다 적은 적이 있을 시 가져온다
--ai.SetTargetUnit(
-- enemy.field.FindUnit(enemy.x, enemy.y, 200,
-- function(u)
-- return u.hp <= 100
-- end
--, 0,enemy))
--현재 필드의 유닛들 중에서 가장 작은 조건에 해당하는 유닛 반환
--예) 플레이어 유닛 중에서 hp가 가장 적은 적을 가져온다
--ai.SetTargetUnit(
-- enemy.field.FindMinimumUnit(enemy.x, enemy.y, 200,
-- function(u)
-- return u.hp
-- end
--, 0,enemy))
--현재 필드의 유닛들 중에서 가장 큰 조건에 해당하는 유닛 반환
--예) 플레이어 유닛 중에서 hp가 가장 많은 적을 가져온다
--ai.SetTargetUnit(
-- enemy.field.FindMaximumUnit(enemy.x, enemy.y, 200,
-- function(u)
-- return u.hp
-- end
--, 0,enemy))
--타깃이 정해지지 않았을 경우 가장 가까운 플레이어를 타깃으로 지정
if( ai.GetTargetUnit() == nil) then
ai.SetNearTarget(0,200)
end
--맵에 플레이어가 하나도 없을 경우 null로 세팅
if( enemy.field.playerCount <=0) then
ai.SetTargetUnit(nil)
--타깃이었던 플레이어가 맵을 나갈 경우 타깃 다시 지정
elseif(enemy.field.GetUnit(ai.GetTargetUnitID()) == nil) then
ai.SetNearTarget(0,200)
end
--타깃이 있을 경우 타깃 방향으로 공격
ai.UseSkill(22);
--왼쪽 공격
ai.UseSkill(22,Point(-1,0))
--오른쪽 공격
ai.UseSkill(22,Point(1,0))
--위쪽 공격
ai.UseSkill(22,Point(0,1))
--아래쪽 공격
ai.UseSkill(22,Point(0,-1))
--해당 위치로 공격
ai.UseSkillToPosition(24,Point(150,-150))
--타겟이 없을 경우 예외 처리
if(ai.GetTargetUnit() == nil) then
return
end
--타깃의 hp에 따른 추적 활성화/비활성화
if(ai.GetTargetUnit().hp <=150) then
ai.SetFollowTarget(false)
else
ai.SetFollowTarget(true)
end
end
if (event == AI_ATTACKED) then
enemy.Say('공격당했다. \n대미지: ' .. data.damage
.. '\n스킬ID: '..data.skillDataID
.. '\n크리티컬여부: '..(data.critical and 'true' or 'false'))
--공격한 유닛이 없을 경우 예외 처리
if(ai.GetAttackedUnit() == nil) then
return
end
--공격한 적의 hp를 확인하여 100보다 적을 경우 타깃 변경
if(ai.GetAttackedUnit().hp <= 100) then
ai.SetTargetUnit(ai.GetAttackedUnit())
end
end
if (event == AI_DEAD) then
Server.SendSay('사망')
--사망 후 특정 위치에서 부활
enemy.RespawnAt(150,-150)
end
end)Last updated