• 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!

NPC Guard that kills nearby monsters & attacks PKS

Synergy

New Member
Joined
Nov 24, 2011
Messages
334
Reaction score
0
NPC Guard that kills nearby monsters & attacks PKS

Hello, I'm looking for a fully working guard that kills monsters and attack PK's


Im using 9.60 tfs

- - - Updated - - -

bump
 
\data\npc\scripts:
PHP:
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

\data\npc:
PHP:
<?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>
 
\data\npc\scripts:
PHP:
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

\data\npc:
PHP:
<?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>

Knekam, but this NPC attack players?
 
Yep sorry, he just copied a old guard script here from otland, that one sucks and won't work out good, it doesnt even kill the monsters :]

bump.. I still need a working one please anyone
 
[6:47:21.319] [Error - NpcScript Interface]
[6:47:21.319] data/npc/scripts/Guard.lua:eek:nCreatureSay
[6:47:21.319] Description:
[6:47:21.319] data/npc/scripts/Guard.lua:40: attempt to call global 'messageIsInArray' (a nil value)
[6:47:21.319] stack traceback:
[6:47:21.319] data/npc/scripts/Guard.lua:40: in function <data/npc/scripts/Guard.lua:27>
 
Hey, thanks for posting that script knekarn,
So I'm using it with 1.1 tfs,
its just what I was looking for,

so as for the script, i disabled the lines about doSendAnimatedText by adding -- at the beggining of the line,
because it was sending an error, likely i dont have that in compat, or global.
but i didnt really need that, so yeah
I also disabled all about the attack to those who swear, messageIsinArray was also sending an error whenever i talked to the npc,
also I disabled (or deleted) the function onCreatureSay, ('fixed' the error Szpaku17 posted about, no idea how to actually fix that)
cause my xml with the npc libs handles the talk. Also cause with it I couldnt talk to the npc.

and then as for the attacking npcs, I changed this (for Karain)
after this line
if isCreature(creature.uid) == TRUE then
there is this one
if isPlayer(creature.uid) == FALSE then
i changed it to
if isMonster(creature.uid) == TRUE then

that fixed it, after editing that the npc wont attack other npcs.
basically, it was attacking every Creature, in other words every PK Player and every not Player (monsters, npcs)
so with that change, now it attacks pk players and monsters.

also, all of that is fine, as I wanted the other part, attack pk players and monsters.
I'm currently trying to add somethig so that it will delete the corpses of monsters or perhaps force quickly the corpse decay to bones.
(because i dont want players to exploit guards to kill monsters and grab the loot)
not there yet tho.
 
Hey, thanks for posting that script knekarn,
So I'm using it with 1.1 tfs,
its just what I was looking for,

so as for the script, i disabled the lines about doSendAnimatedText by adding -- at the beggining of the line,
because it was sending an error, likely i dont have that in compat, or global.
but i didnt really need that, so yeah
I also disabled all about the attack to those who swear, messageIsinArray was also sending an error whenever i talked to the npc,
also I disabled (or deleted) the function onCreatureSay, ('fixed' the error Szpaku17 posted about, no idea how to actually fix that)
cause my xml with the npc libs handles the talk. Also cause with it I couldnt talk to the npc.

and then as for the attacking npcs, I changed this (for Karain)
after this line
if isCreature(creature.uid) == TRUE then
there is this one
if isPlayer(creature.uid) == FALSE then
i changed it to
if isMonster(creature.uid) == TRUE then

that fixed it, after editing that the npc wont attack other npcs.
basically, it was attacking every Creature, in other words every PK Player and every not Player (monsters, npcs)
so with that change, now it attacks pk players and monsters.

also, all of that is fine, as I wanted the other part, attack pk players and monsters.
I'm currently trying to add somethig so that it will delete the corpses of monsters or perhaps force quickly the corpse decay to bones.
(because i dont want players to exploit guards to kill monsters and grab the loot)
not there yet tho.

Would be great if you'd share it once you complete it, well done! :)

Kind Regards,
Eldin.
 
Hey, thanks for posting that script knekarn,
So I'm using it with 1.1 tfs,
its just what I was looking for,

so as for the script, i disabled the lines about doSendAnimatedText by adding -- at the beggining of the line,
because it was sending an error, likely i dont have that in compat, or global.
but i didnt really need that, so yeah
I also disabled all about the attack to those who swear, messageIsinArray was also sending an error whenever i talked to the npc,
also I disabled (or deleted) the function onCreatureSay, ('fixed' the error Szpaku17 posted about, no idea how to actually fix that)
cause my xml with the npc libs handles the talk. Also cause with it I couldnt talk to the npc.

and then as for the attacking npcs, I changed this (for Karain)
after this line
if isCreature(creature.uid) == TRUE then
there is this one
if isPlayer(creature.uid) == FALSE then
i changed it to
if isMonster(creature.uid) == TRUE then

that fixed it, after editing that the npc wont attack other npcs.
basically, it was attacking every Creature, in other words every PK Player and every not Player (monsters, npcs)
so with that change, now it attacks pk players and monsters.

also, all of that is fine, as I wanted the other part, attack pk players and monsters.
I'm currently trying to add somethig so that it will delete the corpses of monsters or perhaps force quickly the corpse decay to bones.
(because i dont want players to exploit guards to kill monsters and grab the loot)
not there yet tho.
https://otland.net/threads/advance-guard-attacking-pks-and-monsters-with-options-tfs-1-x.239349/
 
Hey,
thanks Eldin, here is what i have for now,
i havent been able to do what i wanted, (remove the corpse of monsters to avoid exploit, or decay the corpse to bones)
but found a temporal workaround.
so i made a mage guard: just like a guard, though this one makes you disappear.
litteraly, hahah
so it kinda works, and plus when it makes a player disappear, it makes you logout, then when you login again, you have 1 hp. but you appear where you were, so i added no logout zone on my map around the mage guard ( in my coliseum)
that makes it that when it makes a pk player disappear, it forces logout, and when you log back in, because of the no logout zone, the player appears back in his temple, with 1 hp. also added so it will spawn the item ashes on the creature position. only the mage guard does this btw.
its not perfect, but it'll do for now.
note btw, i didnt change much of the original script, for both the guard and mage guard, i added a couple of lines so it will say the creature name with each attack, and changed the effects and added a second effect after it hit.

here it is
Mage Guard.lua
Code:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)

function onCreatureAppear(cid)            npcHandler:onCreatureAppear(cid)            end
function onCreatureDisappear(cid)        npcHandler:onCreatureDisappear(cid)            end
function onCreatureSay(cid, type, msg)        npcHandler:onCreatureSay(cid, type, msg)        end


local level = 50  ----- change this to make the npc hit more/less---------------------|damage_min = (level * 2 + maglevel * 3) * min_multiplier |
local maglevel = 100  ----- change this to make the npc hit more/less -----------------|damage_max = (level * 2 + maglevel * 3) * max_multiplier |
local min_multiplier = 200  ----- change this to make the npc hit more/less ----------|damage_formula = math.random(damage_min,damage_max)      |
local max_multiplier = 500  ----- 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 = 4  ----- 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 = 4  ----- 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 = "Disappear!"  ----- change this to what the NPC says when he sees a monster(s)
local town_name = "The Coliseum"  ----- 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_pkers = TRUE  ----- set to TRUE for the npc to attack players with white and red skulls or FALSE if he doesnt
local hit_effect = CONST_ME_BIGCLOUDS ----- set this to the magic effect the creature will be hit with, see global.lua for more effects
local power_effect = CONST_ME_FIREAREA
local shoot_effect = CONST_ANI_FIRE  ----- set this to the magic effect that will be shot at the creature, see global.lua for more effects
------------------end of config------------------
local check_clock = os.clock()  ----- leave this
local focus = 0  ----- leave this

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 isMonster(creature.uid) == TRUE 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)
                
                
                        local monsterpos = {x =getThingPos(monster_table[i]).x, y = getThingPos(monster_table[i]).y, z = getThingPos(monster_table[i]).z, stackpos = getThingPos(monster_table[i]).stackpos}
                        --Attack by saying creature name.
                        local monstername = getCreatureName(monster_table[i])
                        selfSay('' .. monstername ..'! ' .. Attack_message ..' ')
                
                        doSendDistanceShoot(getCreaturePosition(getNpcCid(  )), getThingPos(monster_table[i]), shoot_effect)
                        doSendMagicEffect(getThingPos(monster_table[i]),hit_effect)
                        doCreatureAddHealth(monster_table[i],-damage_formula)
                        doSendMagicEffect(getThingPos(monster_table[i]),power_effect)
                
                        -- makes creature disappear
                        doRemoveCreature(monster_table[i])
                        doCreateItem(7349, 1, monsterpos)  --ashes = 7349
    
                        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

local focusModule = FocusModule:new()
focusModule:addGreetMessage({'hi', 'hello', 'ashari'})
focusModule:addFarewellMessage({'bye', 'farewell', 'asgha thrazi'})
npcHandler:addModule(focusModule)

mage guard.xml
Code:
<?xml version="1.0" encoding="UTF-8"?>
<npc name="Mage Guard" script="Mage Guard.lua" walkinterval="0" floorchange="0">
    <health now="100" max="100" />
    <look type="130" head="0" body="0" legs="113" feet="114" addons="3"/>
<parameters>
        <parameter key="module_keywords" value="1"/>
        <parameter key="keywords" value="name;job;help;"/>
        <parameter key="keyword_reply1" value="My name does not matter."/>
        <parameter key="keyword_reply2" value="I am a Mage Guard, I protect this coliseum from foes, by desintegrating them into ashes."/>
        <parameter key="keyword_reply3" value="I can help you by defeating any PKs or Monsters that may try to harm you."/>
        <parameter key="message_farewell" value="Goodbye."/>
        <parameter key="message_walkaway" value="..."/>
        <parameter key="message_greet" value="Welcome |PLAYERNAME| to The Coliseum."/>
</parameters>
</npc>
note: for those who might use these xml, you can easily change, and add, to what the npc says.
normal guard and the rest of the post on next post. (limit reached)
 
Last edited:
second part.

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

function onCreatureAppear(cid)            npcHandler:onCreatureAppear(cid)            end
function onCreatureDisappear(cid)        npcHandler:onCreatureDisappear(cid)            end
function onCreatureSay(cid, type, msg)        npcHandler:onCreatureSay(cid, type, msg)        end


local level = 50  ----- 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 = 10  ----- change this to make the npc hit more/less ----------|damage_formula = math.random(damage_min,damage_max)      |
local max_multiplier = 15  ----- 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 = 3  ----- 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 = 3  ----- 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 = "Take this!"  ----- change this to what the NPC says when he sees a monster(s)
local town_name = "The Coliseum"  ----- 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_pkers = TRUE  ----- set to TRUE for the npc to attack players with white and red skulls or FALSE if he doesnt
local hit_effect = CONST_ME_DRAWBLOOD ----- set this to the magic effect the creature will be hit with, see global.lua for more effects
local power_effect = CONST_ME_HITAREA -- edit this for more or less powerful effect, less CONST_ME_HITAREA, more CONST_ME_GROUNDSHAKER
local shoot_effect = CONST_ANI_WHIRLWINDSWORD  ----- set this to the magic effect that will be shot at the creature, see global.lua for more effects
------------------end of config------------------
local check_clock = os.clock()  ----- leave this
local focus = 0  ----- leave this 

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 isMonster(creature.uid) == TRUE 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)
                        --Attack by saying creature name.
                        local monstername = getCreatureName(monster_table[i])
                        selfSay('' .. monstername ..'! ' .. Attack_message ..' ')
                    
                        doSendDistanceShoot(getCreaturePosition(getNpcCid(  )), getThingPos(monster_table[i]), shoot_effect)
                        doSendMagicEffect(getThingPos(monster_table[i]),hit_effect) 
                        doCreatureAddHealth(monster_table[i],-damage_formula)
                        doSendMagicEffect(getThingPos(monster_table[i]),power_effect)
                        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

local focusModule = FocusModule:new()
focusModule:addGreetMessage({'hi', 'hello', 'ashari'})
focusModule:addFarewellMessage({'bye', 'farewell', 'asgha thrazi'})
npcHandler:addModule(focusModule)


guard.xml
Code:
<?xml version="1.0" encoding="UTF-8"?>
<npc name="Guard" script="Guard.lua" walkinterval="0" floorchange="0">
    <health now="100" max="100" />
    <look type="131" head="57" body="57" legs="57" feet="57" addons="1"/>
    <parameters>
        <parameter key="module_keywords" value="1" />
        <parameter key="keywords" value="name;job;help;" />
        <parameter key="keyword_reply1" value="My name does not matter." />
        <parameter key="keyword_reply2" value="I am a Guard, I protect this coliseum from foes." />
        <parameter key="keyword_reply3" value="I help by defeating monsters and pks." />
        <parameter key="message_farewell" value="Goodbye."/>
        <parameter key="message_walkaway" value="..." />
        <parameter key="message_greet" value="Welcome |PLAYERNAME| to The Coliseum." />
</parameters>
</npc>


also, Printer, great script,
I havent used it yet, but will check it out to see how it works.
As far as I can see of it, it looks very well written and advanced.

so thats its,
again thanks to knekarn, who posted the original script which is what i used as a base. I just tweaked it a little.

also, if anyone has an idea on how i could improve any of it, its always welcome.

i will edit this if i make any progress or improve it further.
 
Last edited:
Back
Top