• 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 that attack creatures

Vikarious

New Member
Joined
Dec 16, 2008
Messages
93
Reaction score
2
Im deselvolving a project in wich an area is beginning to be explored so i putted some NPC's in the entrnces of the city like guards from the king, but i realize that if those npc's could attack when some monster come closer by luring or by inttentional spawn it could be a lot more funny...

Can someone help me?

I'm not programer I just had this idea but I don tknwo if it's possible.

I have a script where a npc attack skull player can it be changed to attack creatures?

local target = 0
local prevTarget = 0
local maxChaseDistance = 20
local origPos = 0
local lastAttack = 0
local followTimeout = 10

local function isSkulled(cid)
if(getPlayerSkullType(cid) >= 3 and isPlayerPzLocked(cid) == TRUE) 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
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("We do not tolerate people like you here!")
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, -500, -800, CONST_ME_EXPLOSIONAREA)
lastAttack = os.clock()
end
end

 
Back
Top