olha, nao cheguei a utilizar mas ja tem um problema nele..
nao tem nada verificando se é house.. se a house tiver aberta, o npc pode entrar e limpar todos os itens..
mas o sistema parece estar bem legal.. fica bom pra jogar nos depots das citys ^^
edit: talvez eu esteja errado.. o 7 equivale a house?
or hasProperty(tile.uid, 7)







info
Grupo: Marquês
Registrado: 22/07/12
Posts: 1.1k
Reputação: +400
Gênero: Masculino
Char no Tibia: Luck Oake
Olá galera. Tem um bom tempo que não dou sinal de vida aqui no xtibia no sentido de postar sistemas. Vou quebrar esse gelo, fiz um sisteminha aqui e trouxe pra vocês.
O que é: Um NPC que limpa o chão, se movendo sozinho. Possui sistema de ignore ids, pra evitar de limpar items valiosos como GPs (configurável).
Instalando:
Crie um arquivo em data/lib com o nome de cleaner_lib.lua e coloque isso dentro:
CLEANER_NAME = "Cleaner" -- Name of the NPC Cleaner CLEANER_INITIAL_POS = {x = 95, y = 117, z = 7} -- Initial position of the cleaner CLEANER_PZ = true -- Clean Non-Protection Zones (true/false) CLEANER_BACK = true -- The cleaner will back to initial pos if there's a player on the way? (true/false) CLEANER_EFFECT = 2 -- Effect on clean CLEANER_WALK_DELAY = 2 -- Walk delay of the cleaner (seconds) CLEANER_IGNORE = {2148} -- Item ids ignored by the cleaner CLEANER_PHRASES_CHANCE = 10 -- Percent of cleaner say something CLEANER_PHRASES = {"Hello!", "I'm cleaning!"} -- Phrases that the cleaner can say function isWalkable(pos, creature, proj, pz, house) -- by Nord if getTileThingByPos({x = pos.x, y = pos.y, z = pos.z, stackpos = 0}).itemid == 0 then return false end if getTopCreature(pos).uid > 0 and creature then return false end if getTilePzInfo(pos) and pz == false then return false end if getTileHouseInfo(pos) and house == false then return false end local n = not proj and 3 or 2 for i = 0, 255 do pos.stackpos = i local tile = getTileThingByPos(pos) if tile.itemid ~= 0 and not isCreature(tile.uid) then if hasProperty(tile.uid, n) or hasProperty(tile.uid, 7) then return false end end end return true end function findPath(cid) local dir = math.random(0, 3) if CLEANER_BACK and isCreature(getThingFromPos(getPosByDir(getCreaturePosition(cid), dir)).uid) then doTeleportThing(cid, CLEANER_INITIAL_POS) elseif not isWalkable(getPosByDir(getCreaturePosition(cid), dir), false, true, CLEANER_PZ, false) then return findPath(cid) end doMoveCreature(cid, dir) return true end function startCleaning(cid) if not isNpc(cid) then return true end findPath(cid) local removed = 0 for i = 1, 253 do local pos = getThingFromPos({x = getCreaturePosition(cid).x, y = getCreaturePosition(cid).y, z = getCreaturePosition(cid).z, stackpos = i}) if pos.uid > 0 and not isInArray(CLEANER_IGNORE, pos.itemid) and not isCreature(pos.uid) then removed = i doRemoveItem(pos.uid, 100) end end if removed > 0 then addEvent(doCreatureSay, 300, cid, "Cleaned!", TALKTYPE_MONSTER) addEvent(doSendMagicEffect, 300, getCreaturePosition(cid), CLEANER_EFFECT) else if math.random(1, 100) <= CLEANER_PHRASES_CHANCE then doCreatureSay(cid, CLEANER_PHRASES[math.random(1, #CLEANER_PHRASES)], TALKTYPE_MONSTER) end end return addEvent(startCleaning, CLEANER_WALK_DELAY*1000, cid) end function createCleaner() local npc = doCreateNpc(CLEANER_NAME, CLEANER_INITIAL_POS) startCleaning(npc) return true end function removeCleaner() if getCreatureByName(CLEANER_NAME) then return doRemoveCreature(getCreatureByName(CLEANER_NAME)) end return false endCrie um arquivo.xml em npcs e coloque isso dentro:
Crie um arquivo em talkactions/scripts com o nome de cleaner.lua e coloque isso dentro:
function onSay(cid, words, param) if param == "create" then createCleaner() elseif param == "remove" then if not removeCleaner() then doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "There aren't any cleaners.") else removeCleaner() doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Cleaner removed successfully.") end else doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "Incorrect params. You may only 'create' or 'remove' the cleaner.") end return true endTag (talkactions):
Configurando:
Vá no arquivo cleaner_lib.lua (data/lib) e edite isso:
CLEANER_NAME = "Cleaner" -- Name of the NPC Cleaner CLEANER_INITIAL_POS = {x = 95, y = 117, z = 7} -- Initial position of the cleaner CLEANER_PZ = true -- Clean Non-Protection Zones (true/false) CLEANER_BACK = true -- Will the cleaner teleport back to initial pos if there's a player on the way? (true/false) CLEANER_EFFECT = 2 -- Effect on clean CLEANER_WALK_DELAY = 2 -- Walk delay of the cleaner (seconds) CLEANER_IGNORE = {2148} -- Item ids ignored by the cleaner CLEANER_PHRASES_CHANCE = 10 -- Percent of chance to the cleaner say something CLEANER_PHRASES = {"Hello!", "I'm cleaning!"} -- Phrases that the cleaner can sayVá no arquivo.xml do NPC que você criou e edite:
Usando:
Créditos:
Editado Abril 24 por LuckOake