Tava sem nada para fazer e inspirado no WoW resolvi fazer um NPC que ataca membros da facção (guilda) rival. Ou seja, irá atacar sempre membros que não são da guilda que você escolher.
Funciona para as versões mais novas da SVN, tanto 8.1 quanto 8.2.
--------------------------------------------------------------------------------------------------------------------------------------------- Guild Guardian 0.1 (por Chose) ------------------------------------------------------------------------------------------------------------------------------------------- -- Configuração -- Digite o nome da guilda que o guarda irá proteger local guildName = "Exodar Masters" ------------------------------------------------------------------------------------------------------------------------------------------- local target = 0 local prevTarget = 0 local maxChaseDistance = 20 local origPos = {} local lastAttack = 0 local followTimeout = 10 function goToOrigPos() target = 0 lastAttack = 0 selfFollow(0) doTeleportThing(getNpcCid(), origPos) end function updateTarget() if (isPlayer(target) == FALSE) then goToOrigPos() elseif (getPlayerGuildName(target) == guildName) then selfSay("Welcome sir.") end if (target == 0) then local list = getSpectators(getNpcPos(), 8, 8, false) for i = 1, #list do local _target = list[i] if (_target ~= 0) then if ((isPlayer(_target) == TRUE) and (getPlayerGuildName(_target) ~= guildName)) then if (selfFollow(_target)) then target = _target if (target ~= prevTarget) then selfSay("We do not like people like you! Get out!") end prevTarget = target break end end end end end end function onCreatureAppear(cid) if (cid == getNpcCid()) then origPos = getCreaturePosition(cid) end end function onCreatureDisappear(cid) if (target == cid) then goToOrigPos() end end function onCreatureMove(creature, oldPos, newPos) -- end function onThink() updateTarget() if (target == 0) then return end local playerPos = getCreaturePosition(target) local myPos = getNpcPos() if (myPos.z ~= playerPos.z) then goToOrigPos() return end if ((math.abs(myPos.x - origPos.x) > maxChaseDistance) or (math.abs(myPos.y - origPos.y) > maxChaseDistance)) then selfSay("I'll catch you next time.") goToOrigPos() return end if (lastAttack == 0) then lastAttack = os.clock() end if (os.clock() - lastAttack > followTimeout) then selfSay("You got me this time, but just wait.") goToOrigPos() return end if ((math.abs(playerPos.x - myPos.x) <= 1) and (math.abs(playerPos.y - myPos.y) <= 1)) then doTargetCombatHealth(getNpcCid(), target, COMBAT_LIFEDRAIN, -300, -400, CONST_ME_BLOCKHIT) lastAttack = os.clock() end end
Se quiser absolver guildas aliadas (inspiração do Ragnarok), podemos fazer assim:
Coloque a seguinte função:
function isInArrayEx(arr, arg) local x, y for x, y in pairs(arr) do if (y == arg) then return true, x end end return false end
Uma matriz no começo do código (remova a variável guildName)
local guildsAndAllys = {"Exodar", "Stormwind", "Ogrinmar"}
E troque:
elseif (getPlayerGuildName(target) == guildName) then
por:
elseif (isInArrayEx(guildsAndAllys, getPlayerGuildName(target))) then
troque também:
if ((isPlayer(_target) == TRUE) and (getPlayerGuildName(_target) ~= guildName)) then
por:
if ((isPlayer(_target) == TRUE) and (isInArrayEx(guildsAndAllys, getPlayerGuildName(target)) == false)) then
Com esse pequeno path você poderá selecionar as guildas que não serão atacadas pelo guarda.
Bom, por hoje é só pessoal.