• TibiaFace

    Tibiaface | Una comunidad Open Tibia donde encontras : mapas, scripts, Otserver, npc y amigos etc ...

    .
    demo menumenu

    Afiliados



    Votar:

    Npc que ataca monstruos y/o players 8.6

    Compartir:

    Ver el tema anterior Ver el tema siguiente Ir abajo  Mensaje (Página 1 de 1.)

    1Npc que ataca monstruos y/o players 8.6 Empty Npc que ataca monstruos y/o players 8.6 Vie Jul 14, 2017 6:07 pm

    Invitado

    Anonymous
    Invitado
    Hola gente de Tibiaface! hoy les traigo un script de un npc que si ve a un monstruo lo comenzara a atacar.

    Version: 8.6
    Tfs: 0.4

    En npc/scripts/ crea un archivo y dentro pega esto:
    Código:
    local keywordHandler = KeywordHandler:new()
    local npcHandler = NpcHandler:new(keywordHandler)
    NpcSystem.parseParameters(npcHandler)

    function onCreatureAppear(cid)
    npcHandler:onCreatureAppear(cid)
    lastDamage = os.time()
    origenPos = getNpcPos()

     ---Configuracion---
     criticalDamagesEnabled = true --Daños Criticos Activados
     criticalHitChance = 20 --Chance entre x/100
     sendDistanceEffect = true --Mostrar efecto de disparo
     criticalText = "Critico!" --Texto cuando haga un critico
     criticalTextColor = 210 --Color del texto cuando haga el critico
     
     AttackPlayers = false --Si quieres trollear players activalo, los atacara xD.

     attackInterval = 1 --En segundos, es la velocidad de ataque, -1 es el valor minimo.
     damageMin = 130 --Minimo de Ataque.
     damageMax = 500 --Maximo de Ataque
     distanceToDamage = 2 --Distancia a la que tiene que estar para hacer daño
     
     sayAtTargetDeath = true --Esto depende de si quieres que el npc diga algo cuando mate al objetivo
     leaveCombatTexts = {"Toma eso!", "Espero no volverte a ver", "No vuelvas por aqui!", "Creo que no te gusto eso HAHAHA!"} --Que dira al matar a sus rivales
     
     combat = COMBAT_DEATHDAMAGE --Tipo de Daño
     distEffect = CONST_ANI_SUDDENDEATH --Efecto de lo que va a disparar, puede ser en numeros.
     effect = CONST_ME_MORTAREA --Efecto del daño, puede ser en numeros
    ---Configuracion

    end

    local function updateTargetList()
    for _,list in ipairs(getSpectators(getCreaturePosition(getNpcCid()), 7,6,false))do
     if (list ~= getNpcCid())then
     if getCreatureMaster(list) ~= list then
     if not isNpc(list) then
     if AttackPlayers and isPlayer(list) then
     target = list
     break
     elseif not AttackPlayers then
     if not isPlayer(list) then
     target = list
     break
     end
     end
     end
     end
     end
    end
    return target
    end

    function onCreatureDisappear(cid) npcHandler:onCreatureDisappear(cid) end
    function onCreatureSay(cid, type, msg) npcHandler:onCreatureSay(cid, type, msg) end
    function onThink()
    npcHandler:onThink()
    target = nil

    updateTargetList()
    if target ~= nil then
     local min, max = damageMin, damageMax
     local pos, tpos = getNpcPos(), getCreaturePosition(target)
     if os.time() > lastDamage then
     if((math.abs(tpos.x - pos.x) <= distanceToDamage) and (math.abs(tpos.y - pos.y)) <= distanceToDamage)then
     doCreatureSetNoMove(getNpcCid(), true)
     if(sendDistanceEffect)then
     doSendDistanceShoot(pos, tpos, distEffect)
     end
     if criticalDamagesEnabled then
     if(math.random(1,100) <= criticalHitChance)then
     doSendAnimatedText(getCreaturePosition(target), criticalText, criticalTextColor)
     doTargetCombatHealth(target, combat, -min*1, -max*1.3, effect)
     else
     doTargetCombatHealth(target, combat, -min, -max, effect)
     end
     else
     doTargetCombatHealth(target, combat, -min, -max, effect)
     end
     
     if sayAtTargetDeath and getCreatureHealth(target) < damageMin then
     doCreatureSay(getNpcCid(), leaveCombatTexts[math.random(1,#leaveCombatTexts)])
     doCreatureSetNoMove(getNpcCid(), false)
     end

     lastDamage = os.time()+attackInterval
     else
     selfFollow(target)
     end
     end
     else
     doCreatureSetNoMove(getNpcCid(), false)
     doTeleportThing(getNpcCid(), origenPos)
     target = 0
    end
    end

    npcHandler:addModule(FocusModule:new())

    Puedes modificar lo que quieras en configuracion.

    <npc name="Nombre" script="Nombre del script.lua" walkinterval="2000" speed="200" floorchange="0">
    Ahora para el npc, solo pon en script="" el archivo que creaste y listo!

    Cualquier error comentar para ir mejorando el script Very Happy

    3 participantes

    Simon Marin

    Simon Marin
    Miembro
    Miembro
    Muy buen aporte

    3 participantes

    Lukario

    Lukario
    Miembro
    Miembro
    no puedo configurar, le faltan cosas.

    3 participantes

    [Admin] God Maya

    [Admin] God Maya
    Administrador
    Administrador
    Lukario escribió:no puedo configurar, le faltan cosas.

    versiones tfs viejas

    Código:
    -------By Far Carder------
     -----------------start of config-----------------------------------------------------------------------What the formula looks like---------------
     local level = 10  ----- change this to make the npc hit more/less---------------------|damage_min = (level * 2 + maglevel * 3) * min_multiplier |
     local maglevel = 10  ----- change this to make the npc hit more/less -----------------|damage_max = (level * 2 + maglevel * 3) * max_multiplier |
     local min_multiplier = 2.1  ----- change this to make the npc hit more/less ----------|damage_formula = math.random(damage_min,damage_max)      |
     local max_multiplier = 4.2  ----- change this to make the npc hit more/less ---------------------------------------------------------------------
     local check_interval = 5  ----- change this to the time between checks for a creature (the less time the more it will probably lag :S) 
     local radiusx = 7  ----- change this to the amount of squares left/right the NPC checks (default 7 so he checks 7 squares left of him and 7 squares right (the hole screen) 
     local radiusy = 5  ----- change this to the amount of squares left/right the NPC checks (default 5 so he checks 5 squares up of him and 5 squares down (the hole screen) 
     local Attack_message = "An Invader, ATTACK!!!"  ----- change this to what the NPC says when he sees a monster(s) 
     local town_name = "Archgard"  ----- the name of the town the NPC says when you say "hi"
     local Attack_monsters = TRUE  ----- set to TRUE for the npc to attack monsters in his area or FALSE if he doesnt
     local Attack_swearers = TRUE  ----- set to TRUE for the npc to attack players that swear near him or FALSE if he doesnt
     local Attack_pkers = TRUE  ----- set to TRUE for the npc to attack players with white and red skulls or FALSE if he doesnt
     local health_left = 10  ----- set to the amount of health the npc will leave a player with if they swear at him (ie at 10 he will hit the player to 10 health left)
     local swear_message = "Take this!!!"  ----- change this to what you want the NPC to say when he attackes a swearer
     local swear_words = {"shit", "fuck", "dick", "cunt"}  ----- if "Attack_swearers" is set to TRUE then the NPC will attack anyone who says a word in here. Remember to put "" around each word and seperate each word with a comma (,)
     local hit_effect = CONST_ME_MORTAREA  ----- set this to the magic effect the creature will be hit with, see global.lua for more effects
     local shoot_effect = CONST_ANI_SUDDENDEATH  ----- set this to the magic effect that will be shot at the creature, see global.lua for more effects
     local damage_colour = TEXTCOLOR_RED  ----- set this to the colour of the text that shows the damage when the creature gets hit
     ------------------end of config------------------
     local check_clock = os.clock()  ----- leave this
     local focus = 0  ----- leave this 
     
     function msgcontains(txt, str) 
      return (string.find(txt, str) and not string.find(txt, '(%w+)' .. str) and not string.find(txt, str .. '(%w+)')) 
     end 
     
     function onCreatureSay(cid, type, msg) 
     msg = string.lower(msg)
     health = getCreatureHealth(cid) - health_left
        if ((string.find(msg, '(%a*)hi(%a*)'))) and getDistanceToCreature(cid) < 4 then 
            selfSay('Hello ' .. creatureGetName(cid) .. '! I am a defender of '..town_name..'.') 
            doNpcSetCreatureFocus(cid) 
            focus = 0
        end
     
        if msgcontains(msg, 'time') then
            selfSay('The time is ' .. getWorldTime() .. '.')
        end
     
        if messageIsInArray(swear_words, msg) then
            if Attack_swearers == TRUE then
                selfSay('' .. swear_message ..' ') 
                doCreatureAddHealth(cid,-health)
                doSendMagicEffect(getThingPos(cid),17) 
                doSendAnimatedText(getThingPos(cid),health,180)
                doNpcSetCreatureFocus(cid) 
                focus = 0 
            end
        end
     end 
     
     function getMonstersfromArea(pos, radiusx, radiusy, stack)
     local monsters = { } 
     local starting = {x = (pos.x - radiusx), y = (pos.y - radiusy), z = pos.z, stackpos = stack} 
     local ending = {x = (pos.x + radiusx), y = (pos.y + radiusy), z = pos.z, stackpos = stack} 
     local checking = {x = starting.x, y = starting.y, z = starting.z, stackpos = starting.stackpos} 
        repeat 
            creature = getThingfromPos(checking) 
                if creature.itemid > 0 then 
                    if isCreature(creature.uid) == TRUE then
                        if isPlayer(creature.uid) == FALSE then
                            if Attack_monsters == TRUE then                       
                                table.insert (monsters, creature.uid) 
                                check_clock = os.clock()                     
                            end
                        elseif isPlayer(creature.uid) == TRUE then 
                            if Attack_pkers == TRUE then
                                if getPlayerSkullType(creature.uid) > 0 then
                                    table.insert (monsters, creature.uid) 
                                    check_clock = os.clock()     
                                end
                            end
                        end 
                    end 
                end 
            if checking.x == pos.x-1 and checking.y == pos.y then 
                checking.x = checking.x+2 
            else 
                checking.x = checking.x+1 
            end 
            if checking.x > ending.x then 
                checking.x = starting.x 
                checking.y = checking.y+1 
            end 
        until checking.y > ending.y 
            return monsters 
     end 
     
     function onThink() 
     if (Attack_monsters == TRUE and Attack_pkers == TRUE) or (Attack_monsters == TRUE and Attack_pkers == FALSE) or (Attack_monsters == FALSE and Attack_pkers == TRUE) then
        if (os.clock() - check_clock) > check_interval then     
            monster_table = getMonstersfromArea(getCreaturePosition(getNpcCid(  )), radiusx, radiusy, 253) 
                if #monster_table >= 1 then
                    selfSay('' .. Attack_message ..' ') 
                        for i = 1, #monster_table do 
                            doNpcSetCreatureFocus(monster_table[i]) 
                            local damage_min = (level * 2 + maglevel * 3) * min_multiplier 
                            local damage_max = (level * 2 + maglevel * 3) * max_multiplier 
                            local damage_formula = math.random(damage_min,damage_max)
                            doSendDistanceShoot(getCreaturePosition(getNpcCid(  )), getThingPos(monster_table[i]), shoot_effect)
                            doSendMagicEffect(getThingPos(monster_table[i]),hit_effect) 
                            doSendAnimatedText(getThingPos(monster_table[i]),damage_formula,damage_colour) 
                            doCreatureAddHealth(monster_table[i],-damage_formula) 
                            check_clock = os.clock() 
                            focus = 0 
                        end 
                elseif table.getn(monster_table) < 1 then 
                    focus = 0 
                    check_clock = os.clock() 
                end   
        end
     end
        focus = 0
     end 
     

    Código:
    <?xml version="1.0"?>
     
     <npc name="Defender" script="defender.lua" access="5" lookdir="2" autowalk="25">
      <mana now="800" max="800"/>
      <health now="200" max="200"/>
      <look type="131" head="116" body="94" legs="78" feet="115" addons="3"/>
     </npc>

    versiones tfs en adelante de evolution

    Código:
    -------By Far Carder------
     -----------------start of config-----------------------------------------------------------------------What the formula looks like---------------
     local level = 10  ----- change this to make the npc hit more/less---------------------|damage_min = (level * 2 + maglevel * 3) * min_multiplier |
     local maglevel = 10  ----- change this to make the npc hit more/less -----------------|damage_max = (level * 2 + maglevel * 3) * max_multiplier |
     local min_multiplier = 2.1  ----- change this to make the npc hit more/less ----------|damage_formula = math.random(damage_min,damage_max)      |
     local max_multiplier = 4.2  ----- change this to make the npc hit more/less ---------------------------------------------------------------------
     local check_interval = 5  ----- change this to the time between checks for a creature (the less time the more it will probably lag :S)
     local radiusx = 7  ----- change this to the amount of squares left/right the NPC checks (default 7 so he checks 7 squares left of him and 7 squares right (the hole screen)
     local radiusy = 5  ----- change this to the amount of squares left/right the NPC checks (default 5 so he checks 5 squares up of him and 5 squares down (the hole screen)
     local Attack_message = "An Invader, ATTACK!!!"  ----- change this to what the NPC says when he sees a monster(s)
     local town_name = "Archgard"  ----- the name of the town the NPC says when you say "hi"
     local Attack_monsters = TRUE  ----- set to TRUE for the npc to attack monsters in his area or FALSE if he doesnt
     local Attack_swearers = TRUE  ----- set to TRUE for the npc to attack players that swear near him or FALSE if he doesnt
     local Attack_pkers = TRUE  ----- set to TRUE for the npc to attack players with white and red skulls or FALSE if he doesnt -- NOTE: Set this to FALSE if you are using TFS as there is no way to tell if a player is skulled on TFS, you will only get errors
     local health_left = 10  ----- set to the amount of health the npc will leave a player with if they swear at him (ie at 10 he will hit the player to 10 health left)
     local swear_message = "Take this!!!"  ----- change this to what you want the NPC to say when he attackes a swearer
     local swear_words = {"shit", "fuck", "dick", "cunt"}  ----- if "Attack_swearers" is set to TRUE then the NPC will attack anyone who says a word in here. Remember to put "" around each word and seperate each word with a comma (,)
     local hit_effect = CONST_ME_MORTAREA  ----- set this to the magic effect the creature will be hit with, see global.lua for more effects
     local damage_colour = TEXTCOLOR_RED  ----- set this to the colour of the text that shows the damage when the creature gets hit
     ------------------end of config------------------
     local check_clock = os.clock()  ----- leave this
     local focus = 0  ----- leave this
     function msgcontains(txt, str)
      return (string.find(txt, str) and not string.find(txt, '(%w+)' .. str) and not string.find(txt, str .. '(%w+)'))
     end
     
     function onCreatureSay(cid, type, msg)
     msg = string.lower(msg)
     health = getPlayerHealth(cid) - health_left
      if ((string.find(msg, '(%a*)hi(%a*)'))) and getDistanceToCreature(cid) < 4 then
      selfSay('Hello ' .. creatureGetName(cid) .. '! I am a defender of '..town_name..'.')
      doNpcSetCreatureFocus(cid)
      focus = 0
      end
      if msgcontains(msg, 'time') then
      selfSay('The time is ' .. getWorldTime() .. '.')
      end
      if messageIsInArray(swear_words, msg) then
      if Attack_swearers == TRUE then
        selfSay('' .. swear_message ..' ')
        doPlayerAddHealth(cid,-health)
        doSendMagicEffect(getThingPos(cid),17)
        doSendAnimatedText(getThingPos(cid),health,180)
        doNpcSetCreatureFocus(cid)
        focus = 0
      end
      end
     end 
     
     function getMonstersfromArea(pos, radiusx, radiusy, stack)
     local monsters = { }
     local starting = {x = (pos.x - radiusx), y = (pos.y - radiusy), z = pos.z, stackpos = stack}
     local ending = {x = (pos.x + radiusx), y = (pos.y + radiusy), z = pos.z, stackpos = stack}
     local checking = {x = starting.x, y = starting.y, z = starting.z, stackpos = starting.stackpos}
      repeat
          creature = getThingfromPos(checking)
          if creature.itemid > 0 then
        if isCreature(creature.uid) == TRUE then
          if isPlayer(creature.uid) == FALSE then
          if Attack_monsters == TRUE then
            table.insert (monsters, creature.uid)
            check_clock = os.clock()
          end
          elseif isPlayer(creature.uid) == TRUE then
          if Attack_pkers == TRUE then
            if getPlayerSkull(creature.uid) > 0 then
            table.insert (monsters, creature.uid)
            check_clock = os.clock()   
            end
          end
          end
        end
          end
          if checking.x == pos.x-1 and checking.y == pos.y then
            checking.x = checking.x+2
          else 
        checking.x = checking.x+1
          end
          if checking.x > ending.x then
        checking.x = starting.x
        checking.y = checking.y+1
          end
      until checking.y > ending.y
     return monsters
     end
     
     function onThink()
     if (Attack_monsters == TRUE and Attack_pkers == TRUE) or (Attack_monsters == TRUE and Attack_pkers == FALSE) or (Attack_monsters == FALSE and Attack_pkers == TRUE) then
      if (os.clock() - check_clock) > check_interval then   
      monster_table = getMonstersfromArea(getCreaturePosition(getNpcCid(  )), radiusx, radiusy, 253)
        if #monster_table >= 1 then
        selfSay('' .. Attack_message ..' ')
            for i = 1, #monster_table do
          doNpcSetCreatureFocus(monster_table[i])
          local damage_min = (level * 2 + maglevel * 3) * min_multiplier
          local damage_max = (level * 2 + maglevel * 3) * max_multiplier
          local damage_formula = math.random(damage_min,damage_max) 
          doSendMagicEffect(getThingPos(monster_table[i]),17)
          doCreatureAddHealth(monster_table[i],-damage_formula)  doSendMagicEffect(getThingPos(monster_table[i]),hit_effect)
          doSendAnimatedText(getThingPos(monster_table[i]),damage_formula,damage_colour) 
          check_clock = os.clock()
          focus = 0
            end
        elseif table.getn(monster_table) < 1 then
        focus = 0
        check_clock = os.clock()
        end 
      end
     end
     focus = 0
     end
     

    Código:
    <?xml version="1.0"?>
     
     <npc name="Defender" script="data/npc/scripts/defender.lua" access="5" lookdir="2" autowalk="25">
      <mana now="800" max="800"/>
      <health now="200" max="200"/>
      <look type="131" head="116" body="94" legs="78" feet="115" addons="3"/>
     </npc>


    agregar en tus lib/050-function.lua o global.lua

    Código:
    function messagecontains(txt, str)
        return (string.find(txt, str) and not string.find(txt, '(%w+)' .. str) and not string.find(txt, str .. '(%w+)'))
    end
     
    function messageIsInArray(array_name, message)
        value = false
        message = string.lower(message)
            for a = 1, table.getn(array_name) do
                if messagecontains(message, array_name[a]) then
                    value = true
                end
            end
        return value
    end


    posibles error que attacke a otros npc solo cambiar

    Código:
    if isCreature(creature.uid) == TRUE then
    if isPlayer(creature.uid) == FALSE then

    por esto

    Código:
    if isCreature(creature.uid) == TRUE then
    if creature.type == 2 then



    Npc que ataca monstruos y/o players 8.6 YNU5B25
    3 participantes
    http://www.tibiaface.com

    Contenido patrocinado


    3 participantes

    Ver el tema anterior Ver el tema siguiente Volver arriba  Mensaje (Página 1 de 1.)

    Permisos de este foro:
    No puedes responder a temas en este foro.

     

    BienvenidosTibiaFace es una comunidad de Open Tibia. Para participar debes estar registrado (click para Regístrate).