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

npc attacks x voc

Amiroslo

Excellent OT User
Joined
Jul 28, 2009
Messages
6,812
Solutions
6
Reaction score
822
Hello,
I want a npc that attacks voc 1 and 2 if in range. hits like a monster, doesnt kill immeadtly. unkillable.

rep++
 
bro you can just copy the police man and instead of isInArray(getCreatureSkulls)---->isInArray(getPlayerVocation(cid)

- - - Updated - - -

here you are
LUA:
<?xml version="1.0" encoding="UTF-8"?>
<npc name="Vocation Attacker" script="data/npc/scripts/Policeman.lua" walkinterval="2000" floorchange="0" speed="1500">
<health now="100" max="100"/>
<look type="151" head="62" body="62" legs="62" feet="114" addons="0"/>
</npc>
LUA:
 local target = 0
local prevTarget = 0
local maxChaseDistance = 40
local origPos = 0
local lastAttack = 0
local followTimeout = 10
local function isSkulled(cid)
local vocations = {1, 2}
if isInArray(vocations, getPlayerVocation(cid)) then
return true
end
return false
end
local function goToOrigPos()
target = 0
lastAttack = 0
selfFollow(0)
doTeleportThing(getNpcCid(), origPos)
end
local function updateTarget()
if(isPlayer(target) == FALSE) then
goToOrigPos()
elseif(not isSkulled(target)) then
selfSay("Now, behave in the future.")
goToOrigPos()
end
if(target == 0) then
local list = getSpectators(getNpcPos(), 9, 9, false)
for i = 1, table.getn(list) do
local _target = list[i]
if(_target ~= 0) then
if(isPlayer(_target) == TRUE and isSkulled(_target)) then
if(getTilePzInfo(getCreaturePosition(_target)) == FALSE) then
if(selfFollow(_target)) then
target = _target
if(target ~= prevTarget) then
selfSay("You Have No Respect For Me And Going Pk In Front Of My Sight!")
end
prevTarget = target
break
end
end
end
end
end
end
end
function onCreatureAppear(cid)
if(cid == getNpcCid()) then
origPos = getNpcPos()
end
end
function onCreatureDisappear(cid)
if(cid == target) then
goToOrigPos()
end
end
function onCreatureMove(creature, oldPos, newPos)
-- 
end
function onThink()
updateTarget()
if(target == 0) then
return
end
local playerPos = getCreaturePosition(target)
local myPos = getNpcPos()
if(myPos.z ~= playerPos.z) then
goToOrigPos()
return
end
if(math.abs(myPos.x - origPos.x) > maxChaseDistance or math.abs(myPos.y - origPos.y) > maxChaseDistance) then
selfSay("I'll catch you next time.")
goToOrigPos()
return
end
if(lastAttack == 0) then
lastAttack = os.clock()
end
if(os.clock() - lastAttack > followTimeout) then
selfSay("You got me this time, but just wait.")
goToOrigPos()
return
end
if((math.abs(playerPos.x - myPos.x) <= 1) and (math.abs(playerPos.y - myPos.y) <= 1)) then
doTargetCombatHealth(getNpcCid(), target, COMBAT_LIFEDRAIN, -8000, -20000, CONST_ME_EXPLOSIONAREA)
lastAttack = os.clock()
end
end
 
Last edited:
it follows him if skulled only right? i want to follow @ anytime as soon he sees a player with the voc 1 or 2

- - - Updated - - -

also
doTargetCombatHealth(getNpcCid(), target, COMBAT_LIFEDRAIN, -8000, -20000, CONST_ME_EXPLOSIONAREA)

i want it to hit randomly from 1-20
 
try
LUA:
local target = 0
local prevTarget = 0
local maxChaseDistance = 40
local origPos = 0
local lastAttack = 0
local followTimeout = 10
local vocations = {1, 2}
if isInArray(vocations, getPlayerVocation(cid)) then
return true
end
return false
end
local function goToOrigPos()
target = 0
lastAttack = 0
selfFollow(0)
doTeleportThing(getNpcCid(), origPos)
end
local function updateTarget()
if(isPlayer(target) == FALSE) then
goToOrigPos()
elseif not isInArray(vocations, getPlayerVocation(cid)) then
selfSay("I hate mages.")
goToOrigPos()
end
if(target == 0) then
local list = getSpectators(getNpcPos(), 9, 9, false)
for i = 1, table.getn(list) do
local _target = list[i]
if(_target ~= 0) then
if(isPlayer(_target) == TRUE ) then
if(getTilePzInfo(getCreaturePosition(_target)) == FALSE) then
if(selfFollow(_target)) then
target = _target
if(target ~= prevTarget) then
selfSay("Die mage!")
end
prevTarget = target
break
end
end
end
end
end
end
end
function onCreatureAppear(cid)
if(cid == getNpcCid()) then
origPos = getNpcPos()
end
end
function onCreatureDisappear(cid)
if(cid == target) then
goToOrigPos()
end
end
function onCreatureMove(creature, oldPos, newPos)
-- 
end
function onThink()
updateTarget()
if(target == 0) then
return
end
local playerPos = getCreaturePosition(target)
local myPos = getNpcPos()
if(myPos.z ~= playerPos.z) then
goToOrigPos()
return
end
if(math.abs(myPos.x - origPos.x) > maxChaseDistance or math.abs(myPos.y - origPos.y) > maxChaseDistance) then
selfSay("I'll catch you next time.")
goToOrigPos()
return
end
if(lastAttack == 0) then
lastAttack = os.clock()
end
if(os.clock() - lastAttack > followTimeout) then
selfSay("You got me this time, but just wait.")
goToOrigPos()
return
end
if((math.abs(playerPos.x - myPos.x) <= 1) and (math.abs(playerPos.y - myPos.y) <= 1)) then
doTargetCombatHealth(getNpcCid(), target, COMBAT_LIFEDRAIN, -1, -20, CONST_ME_EXPLOSIONAREA)
lastAttack = os.clock()
end
end
 
try
LUA:
local target = 0
local prevTarget = 0
local maxChaseDistance = 40
local origPos = 0
local lastAttack = 0
local followTimeout = 10
local vocations = {1, 2}
if isInArray(vocations, getPlayerVocation(cid)) then
return true
end
return false
end
local function goToOrigPos()
target = 0
lastAttack = 0
selfFollow(0)
doTeleportThing(getNpcCid(), origPos)
end
local function updateTarget()
if(isPlayer(target) == FALSE) then
goToOrigPos()
elseif not isInArray(vocations, getPlayerVocation(cid)) then
selfSay("I hate mages.")
goToOrigPos()
end
if(target == 0) then
local list = getSpectators(getNpcPos(), 9, 9, false)
for i = 1, table.getn(list) do
local _target = list[i]
if(_target ~= 0) then
if(isPlayer(_target) == TRUE ) then
if(getTilePzInfo(getCreaturePosition(_target)) == FALSE) then
if(selfFollow(_target)) then
target = _target
if(target ~= prevTarget) then
selfSay("Die mage!")
end
prevTarget = target
break
end
end
end
end
end
end
end
function onCreatureAppear(cid)
if(cid == getNpcCid()) then
origPos = getNpcPos()
end
end
function onCreatureDisappear(cid)
if(cid == target) then
goToOrigPos()
end
end
function onCreatureMove(creature, oldPos, newPos)
-- 
end
function onThink()
updateTarget()
if(target == 0) then
return
end
local playerPos = getCreaturePosition(target)
local myPos = getNpcPos()
if(myPos.z ~= playerPos.z) then
goToOrigPos()
return
end
if(math.abs(myPos.x - origPos.x) > maxChaseDistance or math.abs(myPos.y - origPos.y) > maxChaseDistance) then
selfSay("I'll catch you next time.")
goToOrigPos()
return
end
if(lastAttack == 0) then
lastAttack = os.clock()
end
if(os.clock() - lastAttack > followTimeout) then
selfSay("You got me this time, but just wait.")
goToOrigPos()
return
end
if((math.abs(playerPos.x - myPos.x) <= 1) and (math.abs(playerPos.y - myPos.y) <= 1)) then
doTargetCombatHealth(getNpcCid(), target, COMBAT_LIFEDRAIN, -1, -20, CONST_ME_EXPLOSIONAREA)
lastAttack = os.clock()
end
end



[27/6/2013 10:25:21] [Warning - NpcEvents::NpcEvents] Cannot load script: data/npc/scripts/Amy Azzkaban RPG NPC/Anti-Mage.lua
[27/6/2013 10:25:21] data/npc/scripts/Amy Azzkaban RPG NPC/Anti-Mage.lua:17: '<eof>' expected near 'end'
 
LUA:
 local target = 0
local prevTarget = 0
local maxChaseDistance = 40
local origPos = 0
local lastAttack = 0
local followTimeout = 10
local function isSkulled(cid)
local vocations = {1, 2}
if isInArray(vocations, getPlayerVocation(cid)) then
return true
end
return false
end
local function goToOrigPos()
target = 0
lastAttack = 0
selfFollow(0)
doTeleportThing(getNpcCid(), origPos)
end
local function updateTarget()
if(isPlayer(target) == FALSE) then
goToOrigPos()
elseif(not isSkulled(target)) then
selfSay("Now, behave in the future.")
goToOrigPos()
end
if(target == 0) then
local list = getSpectators(getNpcPos(), 9, 9, false)
for i = 1, table.getn(list) do
local _target = list[i]
if(_target ~= 0) then
if(isPlayer(_target) == TRUE and isSkulled(_target)) then
if(getTilePzInfo(getCreaturePosition(_target)) == FALSE) then
if(selfFollow(_target)) then
target = _target
if(target ~= prevTarget) then
selfSay("You Have No Respect For Me And Going Pk In Front Of My Sight!")
end
prevTarget = target
break
end
end
end
end
end
end
end
function onCreatureAppear(cid)
if(cid == getNpcCid()) then
origPos = getNpcPos()
end
end
function onCreatureDisappear(cid)
if(cid == target) then
goToOrigPos()
end
end
function onCreatureMove(creature, oldPos, newPos)
-- 
end
function onThink()
updateTarget()
if(target == 0) then
return
end
local playerPos = getCreaturePosition(target)
local myPos = getNpcPos()
if(myPos.z ~= playerPos.z) then
goToOrigPos()
return
end
if(math.abs(myPos.x - origPos.x) > maxChaseDistance or math.abs(myPos.y - origPos.y) > maxChaseDistance) then
selfSay("I'll catch you next time.")
goToOrigPos()
return
end
if(lastAttack == 0) then
lastAttack = os.clock()
end
if(os.clock() - lastAttack > followTimeout) then
selfSay("You got me this time, but just wait.")
goToOrigPos()
return
end
if((math.abs(playerPos.x - myPos.x) <= 1) and (math.abs(playerPos.y - myPos.y) <= 1)) then
doTargetCombatHealth(getNpcCid(), target, COMBAT_LIFEDRAIN, -1, -20, CONST_ME_EXPLOSIONAREA)
lastAttack = os.clock()
end
end
 
LUA:
 local target = 0
local prevTarget = 0
local maxChaseDistance = 40
local origPos = 0
local lastAttack = 0
local followTimeout = 10
local function isSkulled(cid)
local vocations = {1, 2}
if isInArray(vocations, getPlayerVocation(cid)) then
return true
end
return false
end
local function goToOrigPos()
target = 0
lastAttack = 0
selfFollow(0)
doTeleportThing(getNpcCid(), origPos)
end
local function updateTarget()
if(isPlayer(target) == FALSE) then
goToOrigPos()
elseif(not isSkulled(target)) then
selfSay("Now, behave in the future.")
goToOrigPos()
end
if(target == 0) then
local list = getSpectators(getNpcPos(), 9, 9, false)
for i = 1, table.getn(list) do
local _target = list[i]
if(_target ~= 0) then
if(isPlayer(_target) == TRUE and isSkulled(_target)) then
if(getTilePzInfo(getCreaturePosition(_target)) == FALSE) then
if(selfFollow(_target)) then
target = _target
if(target ~= prevTarget) then
selfSay("You Have No Respect For Me And Going Pk In Front Of My Sight!")
end
prevTarget = target
break
end
end
end
end
end
end
end
function onCreatureAppear(cid)
if(cid == getNpcCid()) then
origPos = getNpcPos()
end
end
function onCreatureDisappear(cid)
if(cid == target) then
goToOrigPos()
end
end
function onCreatureMove(creature, oldPos, newPos)
-- 
end
function onThink()
updateTarget()
if(target == 0) then
return
end
local playerPos = getCreaturePosition(target)
local myPos = getNpcPos()
if(myPos.z ~= playerPos.z) then
goToOrigPos()
return
end
if(math.abs(myPos.x - origPos.x) > maxChaseDistance or math.abs(myPos.y - origPos.y) > maxChaseDistance) then
selfSay("I'll catch you next time.")
goToOrigPos()
return
end
if(lastAttack == 0) then
lastAttack = os.clock()
end
if(os.clock() - lastAttack > followTimeout) then
selfSay("You got me this time, but just wait.")
goToOrigPos()
return
end
if((math.abs(playerPos.x - myPos.x) <= 1) and (math.abs(playerPos.y - myPos.y) <= 1)) then
doTargetCombatHealth(getNpcCid(), target, COMBAT_LIFEDRAIN, -1, -20, CONST_ME_EXPLOSIONAREA)
lastAttack = os.clock()
end
end

Work perfect! But attack in PZ!
 
LUA:
 local target = 0
local prevTarget = 0
local maxChaseDistance = 40
local origPos = 0
local lastAttack = 0
local followTimeout = 10
local function isSkulled(cid)
local vocations = {1, 2}
if isInArray(vocations, getPlayerVocation(cid)) then
return true
end
return false
end
local function goToOrigPos()
target = 0
lastAttack = 0
selfFollow(0)
doTeleportThing(getNpcCid(), origPos)
end
local function updateTarget()
if(isPlayer(target) == FALSE) then
goToOrigPos()
elseif(not isSkulled(target)) then
selfSay("Now, behave in the future.")
goToOrigPos()
end
if(target == 0) then
local list = getSpectators(getNpcPos(), 9, 9, false)
for i = 1, table.getn(list) do
local _target = list[i]
if(_target ~= 0) then
if(isPlayer(_target) == TRUE and isSkulled(_target)) then
if(getTileInfo(getCreaturePosition(_target).protection) == true) then
return false
end
if(selfFollow(_target)) then
target = _target
if(target ~= prevTarget) then
selfSay("You Have No Respect For Me And Going Pk In Front Of My Sight!")
end
prevTarget = target
break
end
end
end
end
end
end
function onCreatureAppear(cid)
if(cid == getNpcCid()) then
origPos = getNpcPos()
end
end
function onCreatureDisappear(cid)
if(cid == target) then
goToOrigPos()
end
end
function onCreatureMove(creature, oldPos, newPos)
-- 
end
function onThink()
updateTarget()
if(target == 0) then
return
end
local playerPos = getCreaturePosition(target)
local myPos = getNpcPos()
if(myPos.z ~= playerPos.z) then
goToOrigPos()
return
end
if(math.abs(myPos.x - origPos.x) > maxChaseDistance or math.abs(myPos.y - origPos.y) > maxChaseDistance) then
selfSay("I'll catch you next time.")
goToOrigPos()
return
end
if(lastAttack == 0) then
lastAttack = os.clock()
end
if(os.clock() - lastAttack > followTimeout) then
selfSay("You got me this time, but just wait.")
goToOrigPos()
return
end
if((math.abs(playerPos.x - myPos.x) <= 1) and (math.abs(playerPos.y - myPos.y) <= 1)) then
doTargetCombatHealth(getNpcCid(), target, COMBAT_LIFEDRAIN, -1, -20, CONST_ME_EXPLOSIONAREA)
lastAttack = os.clock()
end
end

it had the function but it was lil missed (getTilePzInfo) should be --->getTileInfo.protection

try it

- - - Updated - - -

Amy is working on a Rpg :)
 
[15:37:04.742] [Error - NpcScript Interface]
[15:37:04.744] data/npc/scripts/oguard.lua:onThink
[15:37:04.745] Description:
[15:37:04.746] attempt to index a nil value
[15:37:04.747] stack traceback:
[15:37:04.748] [C]: in function 'getTileInfo'
[15:37:04.749] data/npc/scripts/oguard.lua:33: in function 'updateTarget'
[15:37:04.750] data/npc/scripts/oguard.lua:63: in function <data/npc/scripts/og
uard.lua:62>
 
LUA:
 local target = 0
local prevTarget = 0
local maxChaseDistance = 40
local origPos = 0
local lastAttack = 0
local followTimeout = 10
local function isSkulled(cid)
local vocations = {1, 2}
if isInArray(vocations, getPlayerVocation(cid)) then
return true
end
return false
end
local function goToOrigPos()
target = 0
lastAttack = 0
selfFollow(0)
doTeleportThing(getNpcCid(), origPos)
end
local function updateTarget()
if(isPlayer(target) == FALSE) then
goToOrigPos()
elseif(not isSkulled(target)) then
selfSay("Now, behave in the future.")
goToOrigPos()
end
if(target == 0) then
local list = getSpectators(getNpcPos(), 9, 9, false)
for i = 1, table.getn(list) do
local _target = list[i]
if(_target ~= 0) then
if(isPlayer(_target) == TRUE and isSkulled(_target)) then
if(getTilePzInfo(getCreaturePosition(_target)) == FALSE) then
if(selfFollow(_target)) then
target = _target
if(target ~= prevTarget) then
selfSay("You Have No Respect For Me And Going Pk In Front Of My Sight!")
end
prevTarget = target
break
end
end
end
end
end
end
end
function onCreatureAppear(cid)
if(cid == getNpcCid()) then
origPos = getNpcPos()
end
end
function onCreatureDisappear(cid)
if(cid == target) then
goToOrigPos()
end
end
function onCreatureMove(creature, oldPos, newPos)
-- 
end
function onThink()
updateTarget()
if(target == 0) then
return
end
local playerPos = getCreaturePosition(target)
local myPos = getNpcPos()
if(myPos.z ~= playerPos.z) then
goToOrigPos()
return
end
if(math.abs(myPos.x - origPos.x) > maxChaseDistance or math.abs(myPos.y - origPos.y) > maxChaseDistance) then
selfSay("I'll catch you next time.")
goToOrigPos()
return
end
if(lastAttack == 0) then
lastAttack = os.clock()
end
if(os.clock() - lastAttack > followTimeout) then
selfSay("You got me this time, but just wait.")
goToOrigPos()
return
end
if((math.abs(playerPos.x - myPos.x) <= 1) and (math.abs(playerPos.y - myPos.y) <= 1)) then
doTargetCombatHealth(getNpcCid(), target, COMBAT_LIFEDRAIN, -1, -20, CONST_ME_EXPLOSIONAREA)
lastAttack = os.clock()
end
if getTileInfo(getCreaturePosition(_target).protection) == true then
return false
end
end
 
his movements is kinda wrong. I want him to move normaly. he moves and gets back to same spot. bugged movement. also he hits to fast. I need it a bit slower :P
and he talks in yellow. is it possible to make him so he talks orange?

- - - Updated - - -

also i can walk on the npc. can u make it so i can go through him?

- - - Updated - - -

also he doesnt follow the creature. the creature needs to be beside him. can u make it so he follows him. but not all the way?
 
well what about his movement. when he is alone. he moves wrong. not normal idk why
he moves forward then back to his spot as the same time he moved forward. kinda bugged
 
Back
Top