local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
function onCreatureAppear(cid) npcHandler:onCreatureAppear(cid) end
function onCreatureDisappear(cid) npcHandler:onCreatureDisappear(cid) end
function onCreatureSay(cid, type, msg) npcHandler:onCreatureSay(cid, type, msg) end
local config = {
attackRadius = {x = 7, y = 5},
attackPK = {value = true, skulls = {SKULL_WHITE, SKULL_RED}},
attackMonster = {value = true, ignore = {"Rat", "Cave Rat"}},
damageValue = {min = 10, max = 20},
VOC_ID = 9,10,11,12,25,26,27,28
}
local targetId = 0
local function searchTarget()
for _, spectator in ipairs(Game.getSpectators(Npc():getPosition(), false, false, config.attackRadius.x, config.attackRadius.x, config.attackRadius.y, config.attackRadius.y)) do
if not spectator:isNpc() then
if ((spectator:isPlayer() and not spectator:getGroup():getAccess()) and config.attackPK.value and isInArray(config.attackPK.skulls, spectator:getSkull())) or ((spectator:isPlayer()) and (spectator:getVocation():getId() ~= config.VOC_ID)) then
targetId = spectator:getId()
elseif spectator:isMonster() and config.attackMonster.value and not isInArray(config.attackMonster.ignore, spectator:getName()) then
targetId = spectator:getId()
end
end
end
end
function onThink()
local npc = Npc()
local target = Creature(targetId)
local vocs = 8
-- If we have not a target, then we shall search for one
if not target then
searchTarget(npc)
return
end
-- Let's get target offset position
local npcPosition = npc:getPosition()
local targetPosition = target:getPosition()
local offsetX = npcPosition.x - targetPosition.x
local offsetY = npcPosition.y - targetPosition.y
-- Target is out of reach, search for new one
if math.abs(offsetX) > config.attackRadius.x or math.abs(offsetY) > config.attackRadius.y then
targetId = 0
searchTarget(npc)
return
end
-- If target is found
doTargetCombatHealth(npc:getId(), targetId, COMBAT_ICEDAMAGE, -config.damageValue.min, -config.damageValue.max, CONST_ME_ICEATTACK)
npcPosition:sendDistanceEffect(targetPosition, CONST_ANI_ICE)
doNpcSetCreatureFocus(targetId)
npcHandler:onThink()
end