@Strikerzerh Boa noite
XML do Npc
<?xml version="1.0" encoding="UTF-8"?>
<npc name="Traveller" script="data/npc/scripts/traveler.lua" walkinterval="1000" floorchange="0">
<health now="100" max="100"/>
<look type="128" head="96" body="99" legs="76" feet="115" addons="1"/>
</npc>
Na pasta data/npc/scripts crie um arquivo chamado traveler.lua e adicione isso dentro:
local TELEPORT_EFFECT = 10
local config = {
['Demonland'] = {
position = { x=160, y=54, z=7 },
items = {
[2160] = { count = 1 },
[2124] = { count = 1 }
}
},
['Orc Hall'] = {
position = { x=160, y=54, z=7 },
items = {
[8299] = { count = 1 },
}
},
-- [DESTINO] = {
-- position = { x=160, y=54, z=7 },
-- items = {
-- [ITEM_ID] = { count = QUANTIDADE_DO_ITEM },
-- }
-- },
}
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
function creatureSayCallback(cid, type, msg)
if(not npcHandler:isFocused(cid)) then
return false
end
if (not checkDestinyExists(msg)) then
selfSay('Este lugar nao existe. Por favor diga outro.', cid)
return false
end
local destinyData = getDestinyData(msg)
if msgcontains(string.lower(msg), string.lower(destinyData.destiny)) then
local items = {}
for item, data in pairs(destinyData.data.items) do
if (getPlayerItemCount(cid, item) < data.count) then
table.insert(items, { item = item })
end
end
if (#items <= 0) then
removePlayerItems(cid, destinyData.data.items)
doTeleportThing(cid, destinyData.data.position)
doSendMagicEffect(getThingPos(cid), TELEPORT_EFFECT)
selfSay('Ate mais.', cid)
return true
end
selfSay('Voce nao possui todos os itens necessarios para viajar.', cid)
end
return TRUE
end
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
function checkDestinyExists(destiny)
for dest, _ in pairs(config) do
if (string.lower(dest) == string.lower(destiny)) then
return true
end
end
return false
end
function getDestinyData(destiny)
for dest, data in pairs(config) do
if (string.lower(dest) == string.lower(destiny)) then
return { destiny = dest, data = data }
end
end
end
function removePlayerItems(cid, items)
for item, data in pairs(items) do
doPlayerRemoveItem(cid, item, data.count)
end
end