Demonguard.xml
Demonguard.lua
XML:
<?xml version="1.0" encoding="UTF-8"?>
<npc name="Demonguard" script="Demonguard.lua" walkinterval="0" floorchange="0">
<health now="100" max="100" />
<look type="131" head="97" body="94" legs="94" feet="94" addons="3" />
</npc>
LUA:
-- Author: Rodrigo (Nottinghster) - (OTLand, OTFans, XTibia, OTServBR)
-- Country: Brazil
-- From: Tibia World RPG OldSchool
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
local attackedPlayers = {}
local attackInterval = 1000
local lastAttackTime = 0
local fireCondition = Condition(CONDITION_FIRE)
fireCondition:setParameter(CONDITION_PARAM_DELAYED, true)
fireCondition:addDamage(10, 1000, -10)
function onThink()
npcHandler:onThink()
local now = os.time() * 1000
if now - lastAttackTime < attackInterval then
return
end
lastAttackTime = now
local npc = Npc()
local npcPos = npc:getPosition()
local spectators = Game.getSpectators(npcPos, false, true, 5, 5, 5, 5)
local currentPlayerGuids = {}
for i = 1, #spectators do
local player = spectators[i]
if player:isPlayer() then
local guid = player:getGuid()
currentPlayerGuids[guid] = true
if not attackedPlayers[guid] then
player:addCondition(fireCondition)
npcPos:sendMagicEffect(CONST_ME_MAGIC_RED)
player:getPosition():sendMagicEffect(CONST_ME_HITBYFIRE)
npc:say("Die, intruder!", TALKTYPE_SAY)
attackedPlayers[guid] = true
end
end
end
for guid in pairs(attackedPlayers) do
if not currentPlayerGuids[guid] then
attackedPlayers[guid] = nil
end
end
end
npcHandler:addModule(FocusModule:new())