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 end
Crie um arquivo.xml em npcs e coloque isso dentro:
<?xml version="1.0" encoding="UTF-8"?> <npc name="Cleaner" script="default.lua" walkinterval="0" floorchange="0"> <health now="150" max="150"/> <look type="289" head="140" body="64" legs="121" feet="76" addons="3" corpse="2212"/> </npc>
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 end
Tag (talkactions):
<talkaction log="yes" words="/cleaner" access="5" script="cleaner.lua"/>
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 say
Vá no arquivo.xml do NPC que você criou e edite:
<npc name="Cleaner" (...)
<look type="289" head="140" body="64" legs="121" feet="76" addons="3" corpse="2212"/>
Usando:
/cleaner create -- Cria o Cleaner /cleaner remove -- Remove o cleaner
Créditos:
- LuckOake (Pelo sistema)