PL

Npc Trade

Por ploshvisk, 07 de fev. de 2012 em Archived

4
617
ploshviskP
07 de fevereiro de 2012 às 22:33

Queria um NPC, que ser ao inves do trade seria pela fala, só que ia vender items normalmente, só que pela fala. Versão 8.54. Obrigado.

leandroskt8L
07 de fevereiro de 2012 às 22:37

lol tipo assim oi itens por favor ? que for assim eu faço.

ploshviskP
08 de fevereiro de 2012 às 18:35

Por exemplo

 

Player : Hi

NPC : Hi, I buy and sell Items

player : coconut

NPC: Do you want sell 10 coconuts for 10 dollars? (Dollar é moeda do meu server)

player: Yes.

NPC: Here.

 

Esse npc também vendera items. Entendeu?

bepokemonB
08 de fevereiro de 2012 às 20:57

Eu fiz sem testar, mas acho que deve funcionar:

 

local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local talkState, shopState = {}, {}
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

local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid
local m, stat = string.lower(msg), {}
local tables = {
sellAble = {['coconut'] = 10},
buyAble = {['coconut'] = 5}
}

function doPlayerAddHundreds(cid, itemid, count) -- By Byerne XTibia
       if count <= 100 then
               return doPlayerAddItem(cid, itemid, count)
       end
       local count_now = count
       while count_now > 100 do
               doPlayerAddItem(cid, itemid, 100)
               count_now = count_now - 100
       end
       return doPlayerAddItem(cid, itemid, count_now)
end

if talkState[talkUser] == 0 then
for table,list in ipairs(tables) do
if list[m] then
table.insert(stat[m], table)
end
end

if #stat[m] == 2 then
selfSay('Do you want to buy or sell '..m..'?', cid)
shopState[talkUser] = {getItemIdByName(m)}
talkState[talkUser] = 2
else
talkState[talkUser] = 1
if stat[m][1] == 1 then
selfSay('How many '..m..' do you want to sell?', cid)
shopState[talkUser] = {getItemIdByName(m), 'sell', sellAble[m]}
elseif stat[m][1] == 2 then
selfSay('How many '..m..' do you want to buy?', cid)
shopState[talkUser] = {getItemIdByName(m), 'buy', buyAble[m]}
end
end

elseif talkState[talkUser] == 1 then
if tonumber(msg) then
shopState[talkUser][4] = tonumber(msg)
talkState[talkUser] = 3
end
elseif talkState[talkUser] == 2 then
if msgcontains(msg, 'buy') then
shopState[talkUser][2] = 'buy'
shopState[talkUser][3] = buyAble[getItemNameById(shopState[talkUser][1])]
talkState[talkUser] = 1
elseif msgcontains(msg, 'sell') then
shopState[talkUser][2] = 'sell'
shopState[talkUser][3] = sellAble[getItemNameById(shopState[talkUser][1])]
talkState[talkUser] = 1
end
elseif(talkState[talkUser] == 3 and msgcontains(msg, 'yes')) then
local s = shopState[talkUser]
if s[2] == 'sell' then
if doPlayerRemoveItem(cid, s[1], s[4]) then
doPlayerAddMoney(cid, s[3]*100)
selfSay('Thank you very much.',cid)
end
else
if doPlayerRemoveMoney(cid, s[3]*100) then
doPlayerAddHundreds(cid, s[1], s[4])
selfSay('Here you are.', cid)
end
end
end

return true
end
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())