ImaG
Active Member
Hi, I pasted the script and now I can't log into my server. I edit pos players and delete npc lua/xml and nothing, what could have happened?
it doesn't crash the server, it closes the entire game client and doesn't log me in
LUA:
dofile('data/npc/lib/npcsystem/npcsystem.lua')
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local guard = defender:new()
guard:setHitInterval(getNpcParameter("HitInterval"))
guard:setShootEffect(getNpcParameter("ShootEffect"))
guard:setHitEffect(getNpcParameter("HitEffect"))
guard:setTypeDmg(getNpcParameter("TypeDmg"))
guard:setDamage(getNpcParameter("minDamage"), getNpcParameter("maxDamage"))
guard:setSayText(getNpcParameter("sayText"))
guard:setHeal(getNpcParameter("minHeal"), getNpcParameter("maxHeal"))
guard:setHitSkulledPlayer(getNpcParameter("hitSkulledPlayer"))
guard:setMultiAttack(getNpcParameter("multiAttack"))
guard:setDmgRadius(getNpcParameter("dmgRadiusX"), getNpcParameter("dmgRadiusY"))
guard:setHealRadius(getNpcParameter("healRadiusX"), getNpcParameter("healRadiusY"))
-- Ścieżka patrolowa
local path = {
{x = 762, y = 1306, z = 7},
{x = 763, y = 1306, z = 7},
-- ... (reszta punktów ścieżki jak wcześniej)
{x = 763, y = 1306, z = 7}
}
local currentPathIndex = 1
local walkInterval = 2500
local isMoving = false
local chasingTarget = false
local isPaused = false
function hasSkull(cid)
if not isPlayer(cid) then return false end
local skull = getPlayerSkullType(cid)
return skull and skull >= 1 and skull <= 5
end
function findTarget(npcId)
local npcPos = getThingPos(npcId)
local spectators = getSpectators(npcPos, 5, 5, false)
if spectators then
for _, pid in ipairs(spectators) do
if isPlayer(pid) and hasSkull(pid) then
return pid
end
end
end
return nil
end
function getDirectionTo(fromPos, toPos)
local dx = toPos.x - fromPos.x
local dy = toPos.y - fromPos.y
if math.abs(dx) > math.abs(dy) then
return dx > 0 and EAST or WEST
else
return dy > 0 and SOUTH or NORTH
end
end
function isWalkable(pos)
local tileInfo = getTileInfo(pos)
if tileInfo.protection or tileInfo.blocking or tileInfo.itemid == 0 then
return false
end
local creature = getTopCreature(pos)
return creature.type == 0 -- 0 = brak gracza/potwora
end
function isNextPathAvailable(npcId, nextPos)
local npcPos = getThingPos(npcId)
return npcPos.x == nextPos.x and npcPos.y == nextPos.y
end
function pauseMovement(npcId)
isPaused = true
addEvent(function()
isPaused = false
moveAlongPath(npcId)
end, 2000)
end
function moveAlongPath(npcId)
if not isCreature(npcId) or chasingTarget then return end
if isPaused then return end
if currentPathIndex > #path then
currentPathIndex = 1
end
local nextPos = path[currentPathIndex]
local npcPos = getThingPos(npcId)
if isNextPathAvailable(npcId, nextPos) then
currentPathIndex = currentPathIndex + 1
else
local direction = getDirectionTo(npcPos, nextPos)
local testPos = {x = npcPos.x, y = npcPos.y, z = npcPos.z}
if direction == NORTH then testPos.y = testPos.y - 1
elseif direction == SOUTH then testPos.y = testPos.y + 1
elseif direction == EAST then testPos.x = testPos.x + 1
elseif direction == WEST then testPos.x = testPos.x - 1 end
if isWalkable(testPos) then
doMoveCreature(npcId, direction)
pauseMovement(npcId)
end
end
addEvent(moveAlongPath, walkInterval, npcId)
end
function moveToTarget(npcId, targetId)
if not isCreature(npcId) or not isCreature(targetId) then return false end
local npcPos = getThingPos(npcId)
local targetPos = getThingPos(targetId)
local direction = getDirectionTo(npcPos, targetPos)
local nextPos = {x = npcPos.x, y = npcPos.y, z = npcPos.z}
if direction == NORTH then nextPos.y = nextPos.y - 1
elseif direction == SOUTH then nextPos.y = nextPos.y + 1
elseif direction == EAST then nextPos.x = nextPos.x + 1
elseif direction == WEST then nextPos.x = nextPos.x - 1 end
if isWalkable(nextPos) then
doMoveCreature(npcId, direction)
return true
end
return false
end
function moveGuard(npcId)
if isMoving then return end
isMoving = true
if not isCreature(npcId) then
isMoving = false
return
end
local target = findTarget(npcId)
if target then
chasingTarget = true
moveToTarget(npcId, target)
else
chasingTarget = false
moveAlongPath(npcId)
end
addEvent(function()
isMoving = false
moveGuard(npcId)
end, walkInterval)
end
function onThink()
local npc = getNpcCid()
if not isCreature(npc) then return end
guard:onThink(npc)
npcHandler:onThink()
moveGuard(npc)
end
function onCreatureSay(cid, type, msg)
npcHandler:onCreatureSay(cid, type, msg)
end
npcHandler:addModule(FocusModule:new())
Post automatically merged:
it doesn't crash the server, it closes the entire game client and doesn't log me in