Postado Março 17, 2015 10 anos Este é um post popular. ANTES DE TUDO: Você deve instalar a função getCreaturePathTo no seu servidor, disponibilizada pelo elwyn. ------------------------------------------------------------------------------------------------------------------------------------------- Oi, o código consiste num NPC que, a troco de dinheiro (configurável), caminha até determinado lugar (escolhido pelo jogador durante o diálogo). Tais lugares, assim como a mensagem que os representa, são configuráveis. Ao chegar no destino, o NPC fica parado durante alguns segundos. Depois, ele volta andando até sua posição de origem. Fiz alguns testes e não encontrei bug algum. Caso você ache, reporte aqui no tópico (ou resolva você mesmo). E se algum jogador/monstro/summon ficar no caminho do NPC, ele passará "por cima" da criatura. Well, em data/npc, crie um arquivo com extensão .XML, nomeie-o Pather, e coloque o seguinte conteúdo: <?xml version="1.0" encoding="UTF-8"?> <npc name="Jonathan" script="path.lua" walkinterval="350000" floorchange="0" speed="0"> <health now="150" max="150"/> <look type="134" head="39" body="113" legs="38" feet="0" addons="3" corpse="2212"/> <parameters> <parameter key="message_greet" value="Hello, wanna see the path of some place?"/> </parameters> </npc> Depois, em data/npc/scripts, crie um arquivo com extensão .lua, nomeie-o path, e coloque o seguinte conteúdo: local keywordHandler = KeywordHandler:new() local npcHandler = NpcHandler:new(keywordHandler) NpcSystem.parseParameters(npcHandler) local talkState = {} function onCreatureAppear(cid) npcHandler:onCreatureAppear(cid) end function onCreatureDisappear(cid) npcHandler:onCreatureDisappear(cid) end function onCreatureSay(cid, type, msg) npcHandler:onCreatureSay(cid, type, msg) end function onThink() npcHandler:onThink() end local place = nil function creatureSayCallback(cid, type, msg) if not npcHandler:isFocused(cid) then return false end local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid local config = { price = 1000, --Preço. backTime = 5, --Tempo para voltar, em segundos. places = { --["message"] = {to_position}, ["rat"] = {x = 1058, y = 912, z = 7}, ["troll"] = {x = 1059, y = 915, z = 7}, ["goblin"] = {x = 1060, y = 915, z = 7}, }, } local isWalking = getPlayerStorageValue(getNpcCid(), 8013) > -1 and true or false if not isWalking then if talkState[talkUser] == 1 then if config.places[msg:lower()] then selfSay("It will cost you "..config.price.." dollars. Are you sure?", cid) talkState[talkUser] = 2 place = msg:lower() return true else selfSay("I can't go to this place.", cid) return true end elseif msgcontains(msg:lower(), "yes") and talkState[talkUser] == 2 then if doPlayerRemoveMoney(cid, config.price) then selfSay("OK, let's go!", cid) local path = getCreaturePathTo(getNpcCid(), config.places[place], 50) setPlayerStorageValue(getNpcCid(), 8013, 1) local npc = getNpcCid() local npcPos = getNpcPos() for i = 1, #path do addEvent(function() doMoveCreature(npc, path[i]) if i == #path then doCreatureSay(npc, "And here we are!", TALKTYPE_SAY) addEvent(function() doCreatureSay(npc, "Well, I'm going back.", TALKTYPE_SAY) path = getCreaturePathTo(npc, npcPos, 50) for j = 1, #path do addEvent(function() doMoveCreature(npc, path[j]) if j == #path then setPlayerStorageValue(npc, 8013, -1) end end, j * 900) end end, config.backTime * 1000) end end, i * 900) end else selfSay("You do not have enough money.", cid) talkState[talkUser] = 0 return true end elseif msgcontains(msg:lower(), "no") and talkState[talkUser] == 2 then selfSay("Ok, then...", cid) talkState[talkUser] = 0 return true elseif msgcontains(msg:lower(), "yes") then local str = "" local z = {} for _, b in pairs(config.places) do table.insert(z, _) end for d = 1, #z do if str == "" then str = z[d] else str = str..(d == #z and " and " or ", ")..z[d] end end selfSay("I can show you the path for the following places: {"..str.."}. Which path do you wanna see?", cid) talkState[talkUser] = 1 return true elseif msgcontains(msg:lower(), "no") then selfSay("Ok, bye.") talkState[talkUser] = 0 return true end end return true end npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback) npcHandler:addModule(FocusModule:new()) No momento estou de saída, logo não posso gravar um vídeo, tirar alguma screenshot ou fazer um gif. Caso esteja curioso, instale o código e teste-o. Até breve. Editado Março 17, 2015 10 anos por zipter98 (veja o histórico de edições)
Postado Março 17, 2015 10 anos Muito bom! Seu tutorial foi aprovado, você recebeu um ponto de reputação e o tópico será movido para a área correta. Esperamos mais conteúdos como este.
Postado Março 18, 2015 10 anos muito bom haha, vc podia colocar que se o caminho não for andável (isWalkable) ele retraçava a rota pra desviar dos players edit: podia fazer um npc q vc paga pra ele e ele vai até um lugar X e pisa num tile que abre a porta de alguma quest.. dai vc teria que sacar esse sistema e ou pedir pra um amigo pisar lá enquanto vc faz a quest ou pagar o npc pra pisar.. seria mt foda.
Postado Março 18, 2015 10 anos Caso eu esteja no andar 7, e o meu destino acabe no andar 8. O que acontece?
Participe da conversa
Você pode postar agora e se cadastrar mais tarde. Se você tem uma conta, faça o login para postar com sua conta.