Ir para conteúdo

Guarda Avançado[ataca monstros e com opções] [TFS 1.x]


kaleudd

Posts Recomendados

Autor:Printer

 

Aqui é um NPC, que irá proteger a cidade de invasores!

<?xml version="1.0" encoding="UTF-8"?><npc name="Guard" script="guard.lua" walkinterval="0" speed="0" floorchange="0">    <health now="100" max="100" />    <look type="139" head="20" body="39" legs="45" feet="7" addons="0" /></npc>local keywordHandler = KeywordHandler:new()local npcHandler = NpcHandler:new(keywordHandler)NpcSystem.parseParameters(npcHandler)function onCreatureAppear(cid)              npcHandler:onCreatureAppear(cid)            endfunction onCreatureDisappear(cid)           npcHandler:onCreatureDisappear(cid)         endfunction onCreatureSay(cid, type, msg)      npcHandler:onCreatureSay(cid, type, msg)    endlocal 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}}local targetId = 0local 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())) 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    endendfunction onThink()    local npc = Npc()    local target = Creature(targetId)    -- 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_FIREDAMAGE, -config.damageValue.min, -config.damageValue.max, CONST_ME_HITBYFIRE)    npcPosition:sendDistanceEffect(targetPosition, CONST_ANI_FIRE)    doNpcSetCreatureFocus(targetId)    npcHandler:onThink()                    end

 

Editado por DarkWore
Link para o comentário
Compartilhar em outros sites

To tentando passar o script dos monstros se atacando pra 1.x, cheguei nesse script aí, mas não ta ajudando mt :X

 

Consegui fazer eles se atacarem, mas não tiram hp =/

Link para o comentário
Compartilhar em outros sites

  • Quem Está Navegando   0 membros estão online

    • Nenhum usuário registrado visualizando esta página.
×
×
  • Criar Novo...