• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!
  • 2026 staff recruitment is open! Check it out and consider applying!

[TFS 1.1] Bot NPC?

  • Thread starter Thread starter tejdi
  • Start date Start date
T

tejdi

Guest
Can someone create NPC that will exp in specific area?

Without hp losses but with menu where can i change his dmg or spells.

Script need also to remove loot from monsters killed by this Bot NPC.

It will be great and famous script imo :D
 
@Mokerhamer

Lane #61:
Code:
if isFightOn() and (Attack_monsters == TRUE and Attack_pkers == TRUE) or (Attack_monsters == TRUE and Attack_pkers == FALSE) or (Attack_monsters == FALSE and Attack_pkers == TRUE) then

lhbs2h.jpg
 
@Mokerhamer
Lane #45:
Code:
        if checking.x == pos.x-1 and checking.y == pos.y then

Lane #59:
Code:
    function onThink()

Lane #63
Code:
      monster_table = getMonstersfromAreaRedTurret(cid:getPosition(), radiusx, radiusy, 253)

ezsk32.jpg
 
@Mokerhamer

xk3d0y.jpg


redturret.lua [Better copy and paste in your notepadd to see more]:
Code:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)

local level = 21  ----- change this to make the npc hit more/less---------------------|damage_min = (level * 2 + maglevel * 3) * min_multiplier |
local maglevel = 4  ----- change this to make the npc hit more/less -----------------|damage_max = (level * 2 + maglevel * 3) * max_multiplier |
local min_multiplier = 1.0  ----- change this to make the npc hit more/less ----------|damage_formula = math.random(damage_min,damage_max)      |
local max_multiplier = 2.1  ----- change this to make the npc hit more/less ---------------------------------------------------------------------
local check_interval = 0  ----- change this to the time between checks for a creature (the less time the more it will probably lag :S)
local radiusx = 6  ----- 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 = 6  ----- 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_monsters = true  ----- set to TRUE for the npc to attack monsters in his area or FALSE if he doesnt
local Attack_swearers = false  ----- set to TRUE for the npc to attack players that swear near him or FALSE if he doesnt
local Attack_pkers = false  ----- set to TRUE for the npc to attack players with white and red skulls or FALSE if he doesnt
local health_left = 0  ----- 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 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 getMonstersfromAreaRedTurret(pos, radiusx, radiusy, stack)
local monsters = { Demon, Troll}
local starting = {x = 1122, y = 1029, z = 8, stackpos = 253}   --------Top left of killing area
local ending = {x = 1133, y = 1037, z = 8, stackpos = 253}     --------Bottom right of killing area
    repeat
        creature = getThingfromPos(pos)
            if creature.itemid > 0 then
                if isCreature(creature.uid) == TRUE then
                    if isPlayer(creature.uid) == FALSE then
                        if Attack_monsters == TRUE then
                        local monster = Creature(creature.uid)                     
                      if monster:getMaster() == nil then     ----Target all Monsters in speficik area EXECPT for summons.        
                            table.insert (monsters, creature.uid)
                            check_clock = os.clock()                       
                        end
                        end
                    elseif isPlayer(creature.uid) == TRUE then             ----Target all players in speficik area.

                                table.insert (monsters, creature.uid)
                                check_clock = os.clock()     
                    end
                end
            end
        if creature.x == pos.x-1 and creature.y == pos.y then
            creature.x = creature.x+2
        else 
            creature.x = creature.x+1
        end
        if creature.x > ending.x then
            creature.x = starting.x
            creature.y = creature.y+1
        end
    until creature.y > ending.y
        return monsters
end


    function onThink() 
local cid = Npc(getNpcCid(  ))
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 = getMonstersfromAreaRedTurret(cid:getPosition(), radiusx, radiusy, 253)
            if #monster_table >= 1 then
                    target = math.random(1,#monster_table)
                        doNpcSetCreatureFocus(monster_table[target])
                        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(cid:getPosition(), getThingPos(monster_table[target]), shoot_effect)
                        doSendMagicEffect(monster_table[target],hit_effect)
                        --doSendAnimatedText(monster_table[i],damage_formula,damage_colour)
                        doCreatureAddHealth(monster_table[target],-damage_formula)
                        check_clock = os.clock()
                        focus = 0
                    end
            elseif #monster_table < 1 then
                focus = 0
                check_clock = os.clock()         
    end
end
    focus = 0
end



npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
Code:
function getMonstersfromAreaRedTurret(pos, radiusx, radiusy, stack)
local monsters = { }          -----Keep it empty it's a storage!
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
                        local monster = Creature(creature.uid)                      
                      if monster:getMaster() == nil then     ----Target all Monsters in speficik area EXECPT for summons.         
                            table.insert (monsters, creature.uid)
                            check_clock = os.clock()                        
                        end
                        end
                    elseif isPlayer(creature.uid) == TRUE then             ----Target all players in speficik area.

                                table.insert (monsters, creature.uid)
                                check_clock = os.clock()      
                    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



@Mokerhamer

xk3d0y.jpg


redturret.lua [Better copy and paste in your notepadd to see more]:
Code:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)

local level = 21  ----- change this to make the npc hit more/less---------------------|damage_min = (level * 2 + maglevel * 3) * min_multiplier |
local maglevel = 4  ----- change this to make the npc hit more/less -----------------|damage_max = (level * 2 + maglevel * 3) * max_multiplier |
local min_multiplier = 1.0  ----- change this to make the npc hit more/less ----------|damage_formula = math.random(damage_min,damage_max)      |
local max_multiplier = 2.1  ----- change this to make the npc hit more/less ---------------------------------------------------------------------
local check_interval = 0  ----- change this to the time between checks for a creature (the less time the more it will probably lag :S)
local radiusx = 6  ----- 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 = 6  ----- 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_monsters = true  ----- set to TRUE for the npc to attack monsters in his area or FALSE if he doesnt
local Attack_swearers = false  ----- set to TRUE for the npc to attack players that swear near him or FALSE if he doesnt
local Attack_pkers = false  ----- set to TRUE for the npc to attack players with white and red skulls or FALSE if he doesnt
local health_left = 0  ----- 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 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 getMonstersfromAreaRedTurret(pos, radiusx, radiusy, stack)
local monsters = { Demon, Troll}
local starting = {x = 1122, y = 1029, z = 8, stackpos = 253}   --------Top left of killing area
local ending = {x = 1133, y = 1037, z = 8, stackpos = 253}     --------Bottom right of killing area
    repeat
        creature = getThingfromPos(pos)
            if creature.itemid > 0 then
                if isCreature(creature.uid) == TRUE then
                    if isPlayer(creature.uid) == FALSE then
                        if Attack_monsters == TRUE then
                        local monster = Creature(creature.uid)                  
                      if monster:getMaster() == nil then     ----Target all Monsters in speficik area EXECPT for summons.     
                            table.insert (monsters, creature.uid)
                            check_clock = os.clock()                    
                        end
                        end
                    elseif isPlayer(creature.uid) == TRUE then             ----Target all players in speficik area.

                                table.insert (monsters, creature.uid)
                                check_clock = os.clock()  
                    end
                end
            end
        if creature.x == pos.x-1 and creature.y == pos.y then
            creature.x = creature.x+2
        else
            creature.x = creature.x+1
        end
        if creature.x > ending.x then
            creature.x = starting.x
            creature.y = creature.y+1
        end
    until creature.y > ending.y
        return monsters
end


    function onThink()
local cid = Npc(getNpcCid(  ))
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 = getMonstersfromAreaRedTurret(cid:getPosition(), radiusx, radiusy, 253)
            if #monster_table >= 1 then
                    target = math.random(1,#monster_table)
                        doNpcSetCreatureFocus(monster_table[target])
                        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(cid:getPosition(), getThingPos(monster_table[target]), shoot_effect)
                        doSendMagicEffect(monster_table[target],hit_effect)
                        --doSendAnimatedText(monster_table[i],damage_formula,damage_colour)
                        doCreatureAddHealth(monster_table[target],-damage_formula)
                        check_clock = os.clock()
                        focus = 0
                    end
            elseif #monster_table < 1 then
                focus = 0
                check_clock = os.clock()      
    end
end
    focus = 0
end



npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
@Mokerhamer

No errors right now, but no reaction also. What should i add in troll.xml? He doesn't attack tower and tower doesn't attack troll.

raorxq.jpg



Code:
function getMonstersfromAreaRedTurret(pos, radiusx, radiusy, stack)
local monsters = { }          -----Keep it empty it's a storage!
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
                        local monster = Creature(creature.uid)                     
                      if monster:getMaster() == nil then     ----Target all Monsters in speficik area EXECPT for summons.        
                            table.insert (monsters, creature.uid)
                            check_clock = os.clock()                       
                        end
                        end
                    elseif isPlayer(creature.uid) == TRUE then             ----Target all players in speficik area.

                                table.insert (monsters, creature.uid)
                                check_clock = os.clock()     
                    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
 
change
if monster:getMaster() == nil then
to
if monster:isMonster() then

I've changed. Still any errors in console and any reaction from troll/turret.
Script now is looking like this:

Code:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)

local level = 21  ----- change this to make the npc hit more/less---------------------|damage_min = (level * 2 + maglevel * 3) * min_multiplier |
local maglevel = 4  ----- change this to make the npc hit more/less -----------------|damage_max = (level * 2 + maglevel * 3) * max_multiplier |
local min_multiplier = 1.0  ----- change this to make the npc hit more/less ----------|damage_formula = math.random(damage_min,damage_max)      |
local max_multiplier = 2.1  ----- change this to make the npc hit more/less ---------------------------------------------------------------------
local check_interval = 0  ----- change this to the time between checks for a creature (the less time the more it will probably lag :S)
local radiusx = 6  ----- 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 = 6  ----- 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_monsters = true  ----- set to TRUE for the npc to attack monsters in his area or FALSE if he doesnt
local Attack_swearers = false  ----- set to TRUE for the npc to attack players that swear near him or FALSE if he doesnt
local Attack_pkers = false  ----- set to TRUE for the npc to attack players with white and red skulls or FALSE if he doesnt
local health_left = 0  ----- 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 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 getMonstersfromAreaRedTurret(pos, radiusx, radiusy, stack)
local monsters = { }          -----Keep it empty it's a storage!
local starting = {x = (pos.x - radiusx), y = (pos.y - radiusy), z = pos.z, stackpos = stack}   --------Top left of killing area
local ending = {x = (pos.x + radiusx), y = (pos.y + radiusy), z = pos.z, stackpos = stack}     --------Bottom right of killing area
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
                        local monster = Creature(creature.uid)                      
                      if monster:isMonster() then     ----Target all Monsters in speficik area EXECPT for summons.         
                            table.insert (monsters, creature.uid)
                            check_clock = os.clock()                        
                        end
                        end
                    elseif isPlayer(creature.uid) == TRUE then             ----Target all players in speficik area.

                                table.insert (monsters, creature.uid)
                                check_clock = os.clock()      
                    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()  
local cid = Npc(getNpcCid(  ))
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 = getMonstersfromAreaRedTurret(cid:getPosition(), radiusx, radiusy, 253)
            if #monster_table >= 1 then
                    target = math.random(1,#monster_table)
                        doNpcSetCreatureFocus(monster_table[target])
                        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(cid:getPosition(), getThingPos(monster_table[target]), shoot_effect)
                        doSendMagicEffect(monster_table[target],hit_effect)
                        --doSendAnimatedText(monster_table[i],damage_formula,damage_colour)
                        doCreatureAddHealth(monster_table[target],-damage_formula)
                        check_clock = os.clock()
                        focus = 0
                    end
            elseif #monster_table < 1 then
                focus = 0
                check_clock = os.clock()          
    end
end
    focus = 0
end



npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
true and TRUE are not the same thing, maybe that is why it isn't working?
Code:
local t = true
print(t == TRUE)
-- prints false

Try this I just removed the TRUE & FALSE and made the adjustments.
Code:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)

local level = 21  ----- change this to make the npc hit more/less---------------------|damage_min = (level * 2 + maglevel * 3) * min_multiplier |
local maglevel = 4  ----- change this to make the npc hit more/less -----------------|damage_max = (level * 2 + maglevel * 3) * max_multiplier |
local min_multiplier = 1.0  ----- change this to make the npc hit more/less ----------|damage_formula = math.random(damage_min,damage_max)      |
local max_multiplier = 2.1  ----- change this to make the npc hit more/less ---------------------------------------------------------------------
local check_interval = 0  ----- change this to the time between checks for a creature (the less time the more it will probably lag :S)
local radiusx = 6  ----- 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 = 6  ----- 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_monsters = true  ----- set to TRUE for the npc to attack monsters in his area or FALSE if he doesnt
local Attack_swearers = false  ----- set to TRUE for the npc to attack players that swear near him or FALSE if he doesnt
local Attack_pkers = false  ----- set to TRUE for the npc to attack players with white and red skulls or FALSE if he doesnt
local health_left = 0  ----- 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 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 getMonstersfromAreaRedTurret(pos, radiusx, radiusy, stack)
    local monsters = { }          -----Keep it empty it's a storage!
    local starting = {x = (pos.x - radiusx), y = (pos.y - radiusy), z = pos.z, stackpos = stack}   --------Top left of killing area
    local ending = {x = (pos.x + radiusx), y = (pos.y + radiusy), z = pos.z, stackpos = stack}     --------Bottom right of killing area
    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) then
                if not isPlayer(creature.uid) then
                    if Attack_monsters then
                        local monster = Creature(creature.uid)                     
                        if monster:isMonster() then     ----Target all Monsters in speficik area EXECPT for summons.        
                            table.insert (monsters, creature.uid)
                            check_clock = os.clock()                       
                        end
                    end
                elseif isPlayer(creature.uid) then             ----Target all players in speficik area.
                    table.insert (monsters, creature.uid)
                    check_clock = os.clock()     
                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() 
    local cid = Npc(getNpcCid(  ))
    if (Attack_monsters and Attack_pkers) or (Attack_monsters and not Attack_pkers ) or (not Attack_monsters and Attack_pkers) then
        if (os.clock() - check_clock) > check_interval then   
            monster_table = getMonstersfromAreaRedTurret(cid:getPosition(), radiusx, radiusy, 253)
            if #monster_table >= 1 then
                target = math.random(1,#monster_table)
                doNpcSetCreatureFocus(monster_table[target])
                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(cid:getPosition(), getThingPos(monster_table[target]), shoot_effect)
                doSendMagicEffect(monster_table[target],hit_effect)
                --doSendAnimatedText(monster_table[i],damage_formula,damage_colour)
                doCreatureAddHealth(monster_table[target],-damage_formula)
                check_clock = os.clock()
                focus = 0
            end
        elseif #monster_table < 1 then
            focus = 0
            check_clock = os.clock()         
        end
    end
    focus = 0
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
Last edited:
ok, so we will run a test, see if any of this prints to the console
Code:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)

local level = 21  ----- change this to make the npc hit more/less---------------------|damage_min = (level * 2 + maglevel * 3) * min_multiplier |
local maglevel = 4  ----- change this to make the npc hit more/less -----------------|damage_max = (level * 2 + maglevel * 3) * max_multiplier |
local min_multiplier = 1.0  ----- change this to make the npc hit more/less ----------|damage_formula = math.random(damage_min,damage_max)      |
local max_multiplier = 2.1  ----- change this to make the npc hit more/less ---------------------------------------------------------------------
local check_interval = 0  ----- change this to the time between checks for a creature (the less time the more it will probably lag :S)
local radiusx = 6  ----- 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 = 6  ----- 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_monsters = true  ----- set to TRUE for the npc to attack monsters in his area or FALSE if he doesnt
local Attack_swearers = false  ----- set to TRUE for the npc to attack players that swear near him or FALSE if he doesnt
local Attack_pkers = false  ----- set to TRUE for the npc to attack players with white and red skulls or FALSE if he doesnt
local health_left = 0  ----- 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 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 getMonstersfromAreaRedTurret(pos, radiusx, radiusy, stack)
    local monsters = { }          -----Keep it empty it's a storage!
    local starting = {x = (pos.x - radiusx), y = (pos.y - radiusy), z = pos.z, stackpos = stack}   --------Top left of killing area
    local ending = {x = (pos.x + radiusx), y = (pos.y + radiusy), z = pos.z, stackpos = stack}     --------Bottom right of killing area
    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) then
                if not isPlayer(creature.uid) then
                    if Attack_monsters then
                        local monster = Creature(creature.uid)                     
                        if monster:isMonster() then     ----Target all Monsters in speficik area EXECPT for summons.        
                            table.insert (monsters, creature.uid)
                            check_clock = os.clock()                       
                        end
                    end
                elseif isPlayer(creature.uid) then             ----Target all players in speficik area.
                    table.insert (monsters, creature.uid)
                    check_clock = os.clock()     
                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() 
    local cid = Npc(getNpcCid(  ))
    print(cid, unpack(cid:getPosition()), (os.clock() - check_clock), os.clock(), check_clock)
    if (Attack_monsters and Attack_pkers) or (Attack_monsters and not Attack_pkers ) or (not Attack_monsters and Attack_pkers) then
        if (os.clock() - check_clock) > check_interval then   
            monster_table = getMonstersfromAreaRedTurret(cid:getPosition(), radiusx, radiusy, 253)
            print("this is the size of the monster table ", #monster_table)
            if #monster_table >= 1 then
                target = math.random(1,#monster_table)
                print("this is target number "...target)
                doNpcSetCreatureFocus(monster_table[target])
                print("this is the target to target ", monster_table[target])
                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)
                print('damage formula ', damage_formula)
                doSendDistanceShoot(cid:getPosition(), getThingPos(monster_table[target]), shoot_effect)
                doSendMagicEffect(monster_table[target],hit_effect)
                --doSendAnimatedText(monster_table[i],damage_formula,damage_colour)
                doCreatureAddHealth(monster_table[target], -damage_formula)
                check_clock = os.clock()
                focus = 0
            end
        elseif #monster_table < 1 then
            focus = 0
            check_clock = os.clock()         
        end
    end
    focus = 0
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
I think the error is coming from Npc(getNpcCid( )), since cid:getPosiiton() returns nil
This would also explain why the monster table has 0 indexes.
 
I think there needs to be 2 functions created outside of onthink, a getspectators and a callback, the getspectators could be passed to the callback which would make this script work, but I have to leave for work soon so i can't write it for you :(
 
I think there needs to be 2 functions created outside of onthink, a getspectators and a callback, the getspectators could be passed to the callback which would make this script work, but I have to leave for work soon so i can't write it for you :(
Thanks for advice then! It's not my lvl of LUA, so i will wait for someone with time. Thanks and have a nice day!
 
Back
Top