Cleaner NPC System

LuckOake
em Mods, funções e outros

LuckOake

avatar
Marquês
Marquês

INFOS

Grupo: MarquêsRegistrado: 23/07/12Posts: 1104Gênero: MasculinoChar 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
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)

drakylucas

Draky Scripter
avatar
Visconde
Visconde

INFOS

Grupo: ViscondeRegistrado: 12/09/10Posts: 416Char no Tibia: Draky Lucas

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)

LuckOake

avatar
Marquês
Marquês

INFOS

Grupo: MarquêsRegistrado: 23/07/12Posts: 1104Gênero: MasculinoChar no Tibia: Luck Oake

Rapaz, pior que nem sei, mas deve ser algo assim. No isWalkable tem um terceiro parâmetro que não sei o que faz, mas provável que seja isso ai.

 

~~ Edit ~~

 

Dei uma pesquisada e achei isso:

 

CONST_PROP_BLOCKSOLID = 0
CONST_PROP_HASHEIGHT = 1
CONST_PROP_BLOCKPROJECTILE = 2
CONST_PROP_BLOCKPATHFIND = 3
CONST_PROP_ISVERTICAL = 4
CONST_PROP_ISHORIZONTAL = 5
CONST_PROP_MOVABLE = 6
CONST_PROP_BLOCKINGANDNOTMOVABLE = 7
CONST_PROP_SUPPORTHANGABLE = 8

 

É, realmente, vou colocar o negócio pra evitar invadir houses.

 

~~ Edit 2 ~~

 

Fixed :)

Lordfireot

avatar
Conde
Conde

INFOS

Grupo: CondeRegistrado: 20/03/13Posts: 507Char no Tibia: Sherpy

Cara ele exclui todas as cosias que ele ve pela frente tipo

 

Bordas,Postes,e akeles negocio que coloca na ponta do muro ele exclui tanbem

 

eu joguei 1 iten no chao ele passo em cima nao nao deleto

Se tiver alguma duvida ou algo do tipo pode pergunta ae responderei.

 

ask.fm/paulim78

 

De Valor No Que Você Tem o Tempo Não Volta Atra

 

LuckOake

avatar
Marquês
Marquês

INFOS

Grupo: MarquêsRegistrado: 23/07/12Posts: 1104Gênero: MasculinoChar no Tibia: Luck Oake

Configura aqui:

 

CLEANER_IGNORE = {2148} -- Item ids ignored by the cleaner

 

São os ids que o Cleaner vai ignorar. Só ir adicionando assim {2148, 2160, 8139}, por exemplo.

Lordfireot

avatar
Conde
Conde

INFOS

Grupo: CondeRegistrado: 20/03/13Posts: 507Char no Tibia: Sherpy

Entoa eu tenho que coloca todos os tipos de de bordas e existe um monte dela :/

Se tiver alguma duvida ou algo do tipo pode pergunta ae responderei.

 

ask.fm/paulim78

 

De Valor No Que Você Tem o Tempo Não Volta Atra

 

Gears

avatar
Banidos
Banidos

INFOS

Grupo: BanidosRegistrado: 11/01/13Posts: 576Char no Tibia: Darashia del Shee

Como eu precisava disso, o.O, odiava quando eu tava fazendo algo e o pessoal vinha no meu skype dizer que o otserv estava muito sujo e não tinha nenhum gamemaster online, eu tinha que entrar e dar clean, agora com esse NPC, posso pedir para algum player do OT limpar para min, thanks a lot :)

Estagiário 24/01/2013

pedido para sair : 23/02/2013

Volta como estagiário: 11/04/2013

Pedido para sair: 10/05/2013