Ir para conteúdo

Featured Replies

Postado

Alguem poderia me ajudar? Estou criando um sistema e preciso que o npc guard ataque players com a skull 1...  Estou com um script que ataca , mas ele nao perde o target ate mata-lo....se perde a range da tela ele fica parado... porém se ele mata ele reseta sua posição e ai sim ele vai atras de outro target....
 

lib

Guard = {

    config = {              

        attackspeed = 1000,

    },

    combat = {type = COMBAT_PHYSICALDAMAGE, min = 100, max = 200}

}


function Guard:new()

        local ret = {}

        setmetatable({}, {__index = self.combat})

        setmetatable(ret, {__index = self})

        return ret

end


function Guard:reset()

    self.config = Guard.config

    self.target = 0

    selfFollow(0)

    doTeleportThing(self.id, self.position)

end



function Guard:updateTarget()

    if self.target ~= 0 then

        return

    end


    local creatures = getSpectators(getThingPosition(self.id), self.range, self.range, false)

    for i = 1, #creatures do

        local target = creatures

        if isCreature(target) and not isNpc(target) and getCreatureSkull(target) == 1 then

            if not getTilePzInfo(getThingPosition(target)) then

                if selfFollow(target) then

                    selfSay("I don't tolerate people like you, ".. getCreatureName(target))

                    self.target = target

                    self:attack()

                    break

                end

            end

        else

            self:reset()

        end

    end

end


function Guard:attack()

    if self.target == 0 then

        self:reset()

        return

    end


    self.time = self.time or os.clock()

    if self.time < os.clock() then

        if getDistanceBetween(getThingPosition(self.id), getThingPosition(self.target)) == 1 then

            doTargetCombatHealth(self.id, self.target, self.combat.type, -self.combat.min, -self.combat.max, CONST_ME_DRAWBLOOD)

        end

        self.time = self.time + (self.config.attackspeed/1000)

    end

end

 

 

npc

local Guard = Guard:new()


function onCreatureAppear(cid)

    if cid == getNpcId() then

        Guard.id = getNpcId()

        Guard.target = 0

        Guard.position = getNpcPos()

    end

end


function onCreatureDisappear(cid)

    if cid == Guard.target then

        Guard:reset()

    end

end


function onCreatureSay(cid, type, msg)

    return false

end


function onThink()

    Guard:updateTarget()

    if Guard.target ~= 0 then

        if isCreature(Guard.target) then

            Guard:attack()

        else

            Guard:reset()

        end

    else

        Guard:reset()

    end

end

Participe da conversa

Você pode postar agora e se cadastrar mais tarde. Se você tem uma conta, faça o login para postar com sua conta.

Visitante
Responder

Quem Está Navegando 0

  • Nenhum usuário registrado visualizando esta página.

Estatísticas dos Fóruns

  • Tópicos 96.9k
  • Posts 519.7k

Informação Importante

Confirmação de Termo