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())