What's new

NPC Guard Skrypt

Status
Not open for further replies.

vegetroex

Active User
Joined
Dec 14, 2012
Messages
78
Reaction score
2
N[LUA]local target = 0
local prevTarget = 0
local maxChaseDistance = 20
local origPos = 0
local lastAttack = 0
local followTimeout = 10

local function isSkulled(cid)
if(getCreatureSkullType(cid) >= SKULL_WHITE and isPlayerPzLocked(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(not isPlayer(target)) 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) and isSkulled(_target)) then
if(not getTilePzInfo(getCreaturePosition(_target))) 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, -10000, -20000, CONST_ME_BLOCKHIT)
lastAttack = os.clock()
end
end[/LUA]

Oto moj drugi skrypt.Co myslicie
ten skrypt to jest prostu cityguard skrypt
 

kuba1418

Banned
Joined
Apr 12, 2008
Messages
178
Reaction score
17
Odp: Guard Skrypt

A oto cityguard.lua w tfs co myslicie ?
[LUA]local target = 0
local prevTarget = 0
local maxChaseDistance = 20
local origPos = 0
local lastAttack = 0
local followTimeout = 10

local function isSkulled(cid)
if(getCreatureSkullType(cid) >= SKULL_WHITE and isPlayerPzLocked(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(not isPlayer(target)) 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) and isSkulled(_target)) then
if(not getTilePzInfo(getCreaturePosition(_target))) 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, -200, -300, CONST_ME_BLOCKHIT)
lastAttack = os.clock()
end
end
[/LUA]
 

Zbizu

Luakami
Joined
Mar 13, 2010
Messages
719
Reaction score
104
Age
28
Odp: Guard Skrypt

A oto cityguard.lua w tfs co myslicie ?
Skraca?bym.
Code:
function onCreatureAppear(cid) return true end
function onCreatureDisappear(cid) return true end
function onCreatureMove(creature, oldPos, newPos) return true end
function onThink() return true end
bo nie potrzeba ?eby robi? co? wi?cej ni? sta? jak ko?ek
 
Status
Not open for further replies.
Top