[Resolvido] [PEDIDO] NPC que vende itens em troca de x quantidades de storage

JS Lotus
em Resolvidos
  • 1
  • 2

JS Lotus

avatar
Campones
Campones

INFOS

Grupo: CamponesRegistrado: 21/09/18Posts: 21

 

Eae galera!

Hoje venho pedir mais uma ajuda de vocês.

 

OBS.: Na criação do tópico, não há a opção de várias tfs, portanto selecionei a mais próxima e deixei aqui a correta.

 

*TFS 0.3.6

 

Bolei um sistema aqui, que nele vou precisar de um NPC que vende itens em troca de uma quantidade específica (de acordo com o item a ser comprado) de uma storage fixa (ela será a moeda que o jogador utilizará para comprar os itens no NPC).

 

Já tentei várias vezes, mas infelizmente não consegui :C

 

OBS: apareceria uma janela/lista normal de trade com o NPC, aquelas que aparecem em NPCS comuns que vendem e compram itens.

 

Quem puder ajudar, agradeço!

GniusP

avatar
Artesão
Artesão

INFOS

Grupo: ArtesãoRegistrado: 20/04/18Posts: 116

Não entendi muito bem, você quer que o npc venda o item por storage?

 

JS Lotus

avatar
Campones
Campones

INFOS

Grupo: CamponesRegistrado: 21/09/18Posts: 21
17 horas atrás, GniusP disse:

Não entendi muito bem, você quer que o npc venda o item por storage?

 

Exatamente.

Ele será tipo um vendedor qualquer, porém no lugar de moedas, ele venderá os produtos dele porx quantidades de uma mesma storage, que no caso será a "moeda" de negociação.

Marshmello

Alone ~ [✖‿✖]
avatar
Conde
Conde

INFOS

Grupo: CondeRegistrado: 21/04/16Posts: 831Gênero: Masculino

@JS Lotus Esse npc ira vender 1 item só ou mais de 1

placa1.png.90a184502351cebe72cd7b69751e551d.png

Meu Facebook

INFOS:

Citar

CIDADE: Rio de janeiro

Idade: 22 anos
SOU: {"Scripter(lua)", "WebMaster", "ProgramadorC++"}
 

local config = {
	delrey = getPlayerCarValue(cid, DELREY),
	cigarro = getPlayerCancer(cid, DERBY),
	prostituta = getPlayerAIDS(cid, cracuda),
	tresOitao = getPlayerRevorvi(cid, 38)
}
if(delrey == "Ligado" and cigarro == "Aceso" and prostituta == "No Colo" and tresOitao == "Carregado") then
	doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "Começou o fim de semana. #PAS")
end

 

 

 

GniusP

avatar
Artesão
Artesão

INFOS

Grupo: ArtesãoRegistrado: 20/04/18Posts: 116

Se tiver algum erro me avisa, fiz aqui e não testei

 

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 item1 = 2160 -- id do item que o player vai receber
local cont1 = 1 -- quantidade de item que o player vai receber no item1
local item2 = 2145 -- id do item que o player vai receber
local cont2 = 1 -- quantidade de item que o player vai receber no item2
local storage = 24343 -- aqui é a storage que o player vai precisar pra trocar
 
function creatureSayCallback(cid, type, msg)
          if(not npcHandler:isFocused(cid)) then
                    return false
          end
          local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid

          if msgcontains(msg, 'dinheiro') then
                    if getPlayerStorageValue(cid, storage) > 0 then
                              doPlayerAddItem(cid,item1,cont1)
							  setPlayerStorageValue(cid, storage, 0)
                              selfSay('Você trocou sua storage por '.. getItemNameById(item1) ..' ', cid)
                    else
                              selfSay('Você precisa de storage para trocar', cid)
                    end

          elseif msgcontains(msg, 'dinheiroextra') then
                   if getPlayerStorageValue(cid, storage) > 0 then
                              doPlayerAddItem(cid,item1,cont2)
							  setPlayerStorageValue(cid, storage, 0)
                              selfSay('Você trocou sua storage por '.. getItemNameById(item2) ..' ', cid)
                    else
                              selfSay('Você precisa de storage para trocar', cid)
                    end
          end
          return TRUE
end
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())

 

JS Lotus

avatar
Campones
Campones

INFOS

Grupo: CamponesRegistrado: 21/09/18Posts: 21
7 minutos atrás, Marshmello disse:

@JS Lotus Esse npc ira vender 1 item só ou mais de 1

Opa, venderá mais de um item.

Acho que é complicado, mas se conseguir por trade window, caso não, ainda servirá

Marshmello

Alone ~ [✖‿✖]
avatar
Conde
Conde

INFOS

Grupo: CondeRegistrado: 21/04/16Posts: 831Gênero: Masculino
3 minutos atrás, JS Lotus disse:

Opa, venderá mais de um item.

Acho que é complicado, mas se conseguir por trade window, caso não, ainda servirá

por trade window não sera possivel , mais da pra fazer ele por lua

placa1.png.90a184502351cebe72cd7b69751e551d.png

Meu Facebook

INFOS:

Citar

CIDADE: Rio de janeiro

Idade: 22 anos
SOU: {"Scripter(lua)", "WebMaster", "ProgramadorC++"}
 

local config = {
	delrey = getPlayerCarValue(cid, DELREY),
	cigarro = getPlayerCancer(cid, DERBY),
	prostituta = getPlayerAIDS(cid, cracuda),
	tresOitao = getPlayerRevorvi(cid, 38)
}
if(delrey == "Ligado" and cigarro == "Aceso" and prostituta == "No Colo" and tresOitao == "Carregado") then
	doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "Começou o fim de semana. #PAS")
end

 

 

 

GniusP

avatar
Artesão
Artesão

INFOS

Grupo: ArtesãoRegistrado: 20/04/18Posts: 116

Não sei se vai funcionar, mas testar ai(Esse é o trade window)

Obs:Não esqueça de ler as linhas que estão em verde para alterar os IDS etc

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
local talkUser = NPCHANDLER_CONVbehavior == CONVERSATION_DEFAULT and 0 or cid
local shopWindow = {}
local t = {
 [13943] = {price = 0} -- não altere o price, altere so o ID do item no caso 13943
 }
 local storage = 544232 -- storage que o player precisa para trocar o item
local onBuy = function(cid, item, subType, amount, ignoreCap, inBackpacks)
if getPlayerStorageValue(cid, storage) > 0 then
selfSay("Voce nao tem a storage para trocar", cid)
else
doPlayerAddItem(cid,22222,1) -- id 22222 é o id que o player vai receber e 1 é a quantidade
setPlayerStorageValue(cid, storage, 0)
selfSay("Voce trocou sua storage por um item", cid)
  end
return true
end
if (msgcontains(msg, 'trade') or msgcontains(msg, 'TRADE'))then
for var, ret in pairs(t) do
table.insert(shopWindow, {id = var, subType = 0, buy = ret.price, sell = 0, name = getItemNameById(var)})
end
openShopWindow(cid, shopWindow, onBuy, onSell)
end
return true
end
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())

 

Marshmello

Alone ~ [✖‿✖]
avatar
Conde
Conde

INFOS

Grupo: CondeRegistrado: 21/04/16Posts: 831Gênero: Masculino

@JS Lotus

Script esta aqui

Spoiler

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

local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid
------------------- Configuração dos Itens -----------------------

local items = {1820, 1821, 2037, 2038, 2397, 2398, 2396, 2399, 2400, 11454} -- ID dos Itens
local nome = {'nome 1', 'nome Y', 'nome', 'nome', 'nome', 'nome', 'nome', 'nome', 'nome', 'nome'}  -- Nome dos Itens
local valor = {2145, 25} -- id da moeda, quantidade

------------------- MESSAGES INICIAIS ----------------------------------------
if msgcontains(msg, nome[1]) then
selfSay('Deseja comprar um {'..getItemNameById(items[1])..'} Por X Storage', cid)
talkState[talkUser] = 1

elseif msgcontains(msg, nome[2]) then
selfSay('Deseja comprar um {'..getItemNameById(items[2])..'} Por X Storage', cid)
talkState[talkUser] = 2

elseif msgcontains(msg, nome[3]) then
selfSay('Deseja comprar um {'..getItemNameById(items[3])..'} Por X Storage', cid)
talkState[talkUser] = 3

elseif msgcontains(msg, nome[4]) then
selfSay('Deseja comprar um {'..getItemNameById(items[4])..'} Por X Storage', cid)
talkState[talkUser] = 4

elseif msgcontains(msg, nome[5]) then
selfSay('Deseja comprar um {'..getItemNameById(items[5])..'} Por X Storage', cid)
talkState[talkUser] = 5

elseif msgcontains(msg, nome[6]) then
selfSay('Deseja comprar um {'..getItemNameById(items[6])..'} Por X Storage', cid)
talkState[talkUser] = 6

elseif msgcontains(msg, nome[7]) then
selfSay('Deseja comprar um {'..getItemNameById(items[7])..'} Por X Storage', cid)
talkState[talkUser] = 7

elseif msgcontains(msg, nome[8]) then
selfSay('Deseja comprar um {'..getItemNameById(items[8])..'} Por X Storage', cid)
talkState[talkUser] = 8

elseif msgcontains(msg, nome[9]) then
selfSay('Deseja comprar um {'..getItemNameById(items[9])..'} Por X Storage', cid)
talkState[talkUser] = 9

elseif msgcontains(msg, nome[10]) then
selfSay('Deseja comprar um {'..getItemNameById(items[10])..'} Por X Storage', cid)
talkState[talkUser] = 10

elseif (msgcontains(msg, 'trade') or msgcontains(msg, 'hi')) then
selfSay(' Digite qual item deseja adquirir.', cid)
selfSay('Atualmente temos {'..getItemNameById(items[1])..'}, {'..getItemNameById(items[2])..'}, {'..getItemNameById(items[3])..'}, {'..getItemNameById(items[4])..'}, {'..getItemNameById(items[5])..'}, {'..getItemNameById(items[6])..'}, {'..getItemNameById(items[7])..'}, {'..getItemNameById(items[8])..'}, {'..getItemNameById(items[9])..'} e {'..getItemNameById(items[10])..'}.', cid)
talkState[talkUser] = 0

---------------------- NEGOCIAÇÃO -------------------------------

elseif talkState[talkUser] == 1 then
if (msgcontains(msg, 'sim') or msgcontains(msg, 'yes')) then
    if getPlayerStorageValue(cid, 5984548) >= 10 then
        setPlayerStorageValue(cid, 5984548, 0)
        doPlayerAddItem(cid, items[1], 1)
        selfSay('Parabens, voce acaba de adquirir um '..getItemNameById(items[1])..'.', cid)
    else
        selfSay('Voce nao tem Storage o suficiente.', cid)
    talkState[talkUser] = 0
    end
end

elseif talkState[talkUser] == 2 then
if (msgcontains(msg, 'sim') or msgcontains(msg, 'yes')) then
        if getPlayerStorageValue(cid, 5984548) >= 10 then
        setPlayerStorageValue(cid, 5984548, 0)
        doPlayerAddItem(cid, items[2], 1)
        selfSay('Parabens, voce acaba de adquirir um '..getItemNameById(items[2])..'.', cid)
    else
        selfSay('Voce nao tem Storage o suficiente.', cid)
    talkState[talkUser] = 0
    end
end

elseif talkState[talkUser] == 3 then
if (msgcontains(msg, 'sim') or msgcontains(msg, 'yes')) then
        if getPlayerStorageValue(cid, 5984548) >= 10 then
        setPlayerStorageValue(cid, 5984548, 0)
        doPlayerAddItem(cid, items[3], 1)
        selfSay('Parabens, voce acaba de adquirir um '..getItemNameById(items[3])..'.', cid)
    else
        selfSay('Voce nao tem Storage o suficiente.', cid)
    talkState[talkUser] = 0
    end
end

elseif talkState[talkUser] == 4 then
if (msgcontains(msg, 'sim') or msgcontains(msg, 'yes')) then
    if getPlayerStorageValue(cid, 5984548) >= 10 then
        setPlayerStorageValue(cid, 5984548, 0)
        doPlayerAddItem(cid, items[4], 1)
        selfSay('Parabens, voce acaba de adquirir um '..getItemNameById(items[4])..'.', cid)
    else
        selfSay('Voce nao tem Storage o suficiente.', cid)
    talkState[talkUser] = 0
    end
end

elseif talkState[talkUser] == 5 then
if (msgcontains(msg, 'sim') or msgcontains(msg, 'yes')) then
if getPlayerStorageValue(cid, 5984548) >= 10 then
        setPlayerStorageValue(cid, 5984548, 0)
        doPlayerAddItem(cid, items[5], 1)
        selfSay('Parabens, voce acaba de adquirir um '..getItemNameById(items[5])..'.', cid)
    else
        selfSay('Voce nao tem Storage o suficiente.', cid)
    talkState[talkUser] = 0
    end
end

elseif talkState[talkUser] == 6 then
if (msgcontains(msg, 'sim') or msgcontains(msg, 'yes')) then
if getPlayerStorageValue(cid, 5984548) >= 10 then
        setPlayerStorageValue(cid, 5984548, 0)
        doPlayerAddItem(cid, items[6], 1)
        selfSay('Parabens, voce acaba de adquirir um '..getItemNameById(items[6])..'.', cid)
    else
        selfSay('Voce nao tem Storage o suficiente.', cid)
    talkState[talkUser] = 0
    end
end

elseif talkState[talkUser] == 7 then
if (msgcontains(msg, 'sim') or msgcontains(msg, 'yes')) then
if getPlayerStorageValue(cid, 5984548) >= 10 then
        setPlayerStorageValue(cid, 5984548, 0)
        doPlayerAddItem(cid, items[7], 1)
        selfSay('Parabens, voce acaba de adquirir um '..getItemNameById(items[7])..'.', cid)
    else
        selfSay('Voce nao tem Storage o suficiente.', cid)
    talkState[talkUser] = 0
    end
end

elseif talkState[talkUser] == 8 then
if (msgcontains(msg, 'sim') or msgcontains(msg, 'yes')) then
if getPlayerStorageValue(cid, 5984548) >= 10 then
        setPlayerStorageValue(cid, 5984548, 0)
        doPlayerAddItem(cid, items[8], 1)
        selfSay('Parabens, voce acaba de adquirir um '..getItemNameById(items[8])..'.', cid)
    else
        selfSay('Voce nao tem Storage o suficiente.', cid)
    talkState[talkUser] = 0
    end
end

elseif talkState[talkUser] == 9 then
if (msgcontains(msg, 'sim') or msgcontains(msg, 'yes')) then
    if getPlayerItemCount(cid, valor[1]) >= valor[2] then
        doPlayerRemoveItem(cid, valor[1], valor[2])
        doPlayerAddItem(cid, items[9], 1)
        selfSay('Parabens, voce acaba de adquirir um '..getItemNameById(items[9])..'.', cid)
    else
        selfSay('Voce nao tem Storage o suficiente.', cid)
    talkState[talkUser] = 0
    end
end

elseif talkState[talkUser] == 10 then
if (msgcontains(msg, 'sim') or msgcontains(msg, 'yes')) then
if getPlayerStorageValue(cid, 5984548) >= 10 then
        setPlayerStorageValue(cid, 5984548, 0)
        doPlayerAddItem(cid, items[10], 1)
        selfSay('Parabens, voce acaba de adquirir um '..getItemNameById(items[10])..'.', cid)
    else
        selfSay('Voce nao tem Storage o suficiente.', cid)
    talkState[talkUser] = 0
    end
end

end
return true
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())

 

placa1.png.90a184502351cebe72cd7b69751e551d.png

Meu Facebook

INFOS:

Citar

CIDADE: Rio de janeiro

Idade: 22 anos
SOU: {"Scripter(lua)", "WebMaster", "ProgramadorC++"}
 

local config = {
	delrey = getPlayerCarValue(cid, DELREY),
	cigarro = getPlayerCancer(cid, DERBY),
	prostituta = getPlayerAIDS(cid, cracuda),
	tresOitao = getPlayerRevorvi(cid, 38)
}
if(delrey == "Ligado" and cigarro == "Aceso" and prostituta == "No Colo" and tresOitao == "Carregado") then
	doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "Começou o fim de semana. #PAS")
end

 

 

 

GniusP

avatar
Artesão
Artesão

INFOS

Grupo: ArtesãoRegistrado: 20/04/18Posts: 116

Aqui esta o XML do npc caso esteja com problemas

<?xml version="1.0"?>
<npc name="NOMEDONPC" script="NOMEDONPC.lua" walkinterval="0" floorchange="0">
<health now="100" max="100"/>
<look type="2201" head="87" body="0" legs="87" feet="0" addons="3"/>
<parameters>
<parameter key="message_greet" value="Ola |PLAYERNAME|. fale {trade} para comprar items com storage!"/>
</parameters>
</npc>

 

JS Lotus

avatar
Campones
Campones

INFOS

Grupo: CamponesRegistrado: 21/09/18Posts: 21
Em 18/10/2018 em 21:51, GniusP disse:

Não sei se vai funcionar, mas testar ai(Esse é o trade window)

Obs:Não esqueça de ler as linhas que estão em verde para alterar os IDS etc

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
local talkUser = NPCHANDLER_CONVbehavior == CONVERSATION_DEFAULT and 0 or cid
local shopWindow = {}
local t = {
 [13943] = {price = 0} -- não altere o price, altere so o ID do item no caso 13943
 }
 local storage = 544232 -- storage que o player precisa para trocar o item
local onBuy = function(cid, item, subType, amount, ignoreCap, inBackpacks)
if getPlayerStorageValue(cid, storage) > 0 then
selfSay("Voce nao tem a storage para trocar", cid)
else
doPlayerAddItem(cid,22222,1) -- id 22222 é o id que o player vai receber e 1 é a quantidade
setPlayerStorageValue(cid, storage, 0)
selfSay("Voce trocou sua storage por um item", cid)
  end
return true
end
if (msgcontains(msg, 'trade') or msgcontains(msg, 'TRADE'))then
for var, ret in pairs(t) do
table.insert(shopWindow, {id = var, subType = 0, buy = ret.price, sell = 0, name = getItemNameById(var)})
end
openShopWindow(cid, shopWindow, onBuy, onSell)
end
return true
end
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())

 

 

Não funcionou :C Aparece a janela, porém sem os itens, configurei o id do item, e não foi, não dá erro.

GniusP

avatar
Artesão
Artesão

INFOS

Grupo: ArtesãoRegistrado: 20/04/18Posts: 116
17 minutos atrás, JS Lotus disse:

 

Não funcionou :C Aparece a janela, porém sem os itens, configurei o id do item, e não foi, não dá erro.

Da algum erro?

JS Lotus

avatar
Campones
Campones

INFOS

Grupo: CamponesRegistrado: 21/09/18Posts: 21
1 minuto atrás, GniusP disse:

Da algum erro?

Não =/

GniusP

avatar
Artesão
Artesão

INFOS

Grupo: ArtesãoRegistrado: 20/04/18Posts: 116
11 minutos atrás, JS Lotus disse:

Não =/

 

Vê se funciona(altera as ids)

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
local talkUser = NPCHANDLER_CONVbehavior == CONVERSATION_DEFAULT and 0 or cid
local shopWindow = {}
local t = {
 [13943] = {price = 1} -- não altere o price, altere so o ID do item no caso 13943
 }
 local storage = 544232 -- storage que o player precisa para trocar o item
local onBuy = function(cid, item, subType, amount, ignoreCap, inBackpacks)
if getPlayerStorageValue(cid, storage) > 0 then
selfSay("Voce nao tem a storage para trocar", cid)
else
doPlayerAddItem(cid,22222,1) -- id 22222 é o id que o player vai receber e 1 é a quantidade
setPlayerStorageValue(cid, storage, 0)
selfSay("Voce trocou sua storage por um item", cid)
  end
return true
end
if (msgcontains(msg, 'trade') or msgcontains(msg, 'TRADE'))then
for var, ret in pairs(t) do
table.insert(shopWindow, {id = var, subType = 0, buy = ret.price, sell = 0, name = getItemNameById(var)})
end
openShopWindow(cid, shopWindow, onBuy, onSell)
end
return true
end
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())

 

JS Lotus

avatar
Campones
Campones

INFOS

Grupo: CamponesRegistrado: 21/09/18Posts: 21
Em 18/10/2018 em 21:54, Marshmello disse:

@JS Lotus

Script esta aqui

  Mostrar conteúdo oculto

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

local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid
------------------- Configuração dos Itens -----------------------

local items = {1820, 1821, 2037, 2038, 2397, 2398, 2396, 2399, 2400, 11454} -- ID dos Itens
local nome = {'nome 1', 'nome Y', 'nome', 'nome', 'nome', 'nome', 'nome', 'nome', 'nome', 'nome'}  -- Nome dos Itens
local valor = {2145, 25} -- id da moeda, quantidade

------------------- MESSAGES INICIAIS ----------------------------------------
if msgcontains(msg, nome[1]) then
selfSay('Deseja comprar um {'..getItemNameById(items[1])..'} Por X Storage', cid)
talkState[talkUser] = 1

elseif msgcontains(msg, nome[2]) then
selfSay('Deseja comprar um {'..getItemNameById(items[2])..'} Por X Storage', cid)
talkState[talkUser] = 2

elseif msgcontains(msg, nome[3]) then
selfSay('Deseja comprar um {'..getItemNameById(items[3])..'} Por X Storage', cid)
talkState[talkUser] = 3

elseif msgcontains(msg, nome[4]) then
selfSay('Deseja comprar um {'..getItemNameById(items[4])..'} Por X Storage', cid)
talkState[talkUser] = 4

elseif msgcontains(msg, nome[5]) then
selfSay('Deseja comprar um {'..getItemNameById(items[5])..'} Por X Storage', cid)
talkState[talkUser] = 5

elseif msgcontains(msg, nome[6]) then
selfSay('Deseja comprar um {'..getItemNameById(items[6])..'} Por X Storage', cid)
talkState[talkUser] = 6

elseif msgcontains(msg, nome[7]) then
selfSay('Deseja comprar um {'..getItemNameById(items[7])..'} Por X Storage', cid)
talkState[talkUser] = 7

elseif msgcontains(msg, nome[8]) then
selfSay('Deseja comprar um {'..getItemNameById(items[8])..'} Por X Storage', cid)
talkState[talkUser] = 8

elseif msgcontains(msg, nome[9]) then
selfSay('Deseja comprar um {'..getItemNameById(items[9])..'} Por X Storage', cid)
talkState[talkUser] = 9

elseif msgcontains(msg, nome[10]) then
selfSay('Deseja comprar um {'..getItemNameById(items[10])..'} Por X Storage', cid)
talkState[talkUser] = 10

elseif (msgcontains(msg, 'trade') or msgcontains(msg, 'hi')) then
selfSay(' Digite qual item deseja adquirir.', cid)
selfSay('Atualmente temos {'..getItemNameById(items[1])..'}, {'..getItemNameById(items[2])..'}, {'..getItemNameById(items[3])..'}, {'..getItemNameById(items[4])..'}, {'..getItemNameById(items[5])..'}, {'..getItemNameById(items[6])..'}, {'..getItemNameById(items[7])..'}, {'..getItemNameById(items[8])..'}, {'..getItemNameById(items[9])..'} e {'..getItemNameById(items[10])..'}.', cid)
talkState[talkUser] = 0

---------------------- NEGOCIAÇÃO -------------------------------

elseif talkState[talkUser] == 1 then
if (msgcontains(msg, 'sim') or msgcontains(msg, 'yes')) then
    if getPlayerStorageValue(cid, 5984548) >= 10 then
        setPlayerStorageValue(cid, 5984548, 0)
        doPlayerAddItem(cid, items[1], 1)
        selfSay('Parabens, voce acaba de adquirir um '..getItemNameById(items[1])..'.', cid)
    else
        selfSay('Voce nao tem Storage o suficiente.', cid)
    talkState[talkUser] = 0
    end
end

elseif talkState[talkUser] == 2 then
if (msgcontains(msg, 'sim') or msgcontains(msg, 'yes')) then
        if getPlayerStorageValue(cid, 5984548) >= 10 then
        setPlayerStorageValue(cid, 5984548, 0)
        doPlayerAddItem(cid, items[2], 1)
        selfSay('Parabens, voce acaba de adquirir um '..getItemNameById(items[2])..'.', cid)
    else
        selfSay('Voce nao tem Storage o suficiente.', cid)
    talkState[talkUser] = 0
    end
end

elseif talkState[talkUser] == 3 then
if (msgcontains(msg, 'sim') or msgcontains(msg, 'yes')) then
        if getPlayerStorageValue(cid, 5984548) >= 10 then
        setPlayerStorageValue(cid, 5984548, 0)
        doPlayerAddItem(cid, items[3], 1)
        selfSay('Parabens, voce acaba de adquirir um '..getItemNameById(items[3])..'.', cid)
    else
        selfSay('Voce nao tem Storage o suficiente.', cid)
    talkState[talkUser] = 0
    end
end

elseif talkState[talkUser] == 4 then
if (msgcontains(msg, 'sim') or msgcontains(msg, 'yes')) then
    if getPlayerStorageValue(cid, 5984548) >= 10 then
        setPlayerStorageValue(cid, 5984548, 0)
        doPlayerAddItem(cid, items[4], 1)
        selfSay('Parabens, voce acaba de adquirir um '..getItemNameById(items[4])..'.', cid)
    else
        selfSay('Voce nao tem Storage o suficiente.', cid)
    talkState[talkUser] = 0
    end
end

elseif talkState[talkUser] == 5 then
if (msgcontains(msg, 'sim') or msgcontains(msg, 'yes')) then
if getPlayerStorageValue(cid, 5984548) >= 10 then
        setPlayerStorageValue(cid, 5984548, 0)
        doPlayerAddItem(cid, items[5], 1)
        selfSay('Parabens, voce acaba de adquirir um '..getItemNameById(items[5])..'.', cid)
    else
        selfSay('Voce nao tem Storage o suficiente.', cid)
    talkState[talkUser] = 0
    end
end

elseif talkState[talkUser] == 6 then
if (msgcontains(msg, 'sim') or msgcontains(msg, 'yes')) then
if getPlayerStorageValue(cid, 5984548) >= 10 then
        setPlayerStorageValue(cid, 5984548, 0)
        doPlayerAddItem(cid, items[6], 1)
        selfSay('Parabens, voce acaba de adquirir um '..getItemNameById(items[6])..'.', cid)
    else
        selfSay('Voce nao tem Storage o suficiente.', cid)
    talkState[talkUser] = 0
    end
end

elseif talkState[talkUser] == 7 then
if (msgcontains(msg, 'sim') or msgcontains(msg, 'yes')) then
if getPlayerStorageValue(cid, 5984548) >= 10 then
        setPlayerStorageValue(cid, 5984548, 0)
        doPlayerAddItem(cid, items[7], 1)
        selfSay('Parabens, voce acaba de adquirir um '..getItemNameById(items[7])..'.', cid)
    else
        selfSay('Voce nao tem Storage o suficiente.', cid)
    talkState[talkUser] = 0
    end
end

elseif talkState[talkUser] == 8 then
if (msgcontains(msg, 'sim') or msgcontains(msg, 'yes')) then
if getPlayerStorageValue(cid, 5984548) >= 10 then
        setPlayerStorageValue(cid, 5984548, 0)
        doPlayerAddItem(cid, items[8], 1)
        selfSay('Parabens, voce acaba de adquirir um '..getItemNameById(items[8])..'.', cid)
    else
        selfSay('Voce nao tem Storage o suficiente.', cid)
    talkState[talkUser] = 0
    end
end

elseif talkState[talkUser] == 9 then
if (msgcontains(msg, 'sim') or msgcontains(msg, 'yes')) then
    if getPlayerItemCount(cid, valor[1]) >= valor[2] then
        doPlayerRemoveItem(cid, valor[1], valor[2])
        doPlayerAddItem(cid, items[9], 1)
        selfSay('Parabens, voce acaba de adquirir um '..getItemNameById(items[9])..'.', cid)
    else
        selfSay('Voce nao tem Storage o suficiente.', cid)
    talkState[talkUser] = 0
    end
end

elseif talkState[talkUser] == 10 then
if (msgcontains(msg, 'sim') or msgcontains(msg, 'yes')) then
if getPlayerStorageValue(cid, 5984548) >= 10 then
        setPlayerStorageValue(cid, 5984548, 0)
        doPlayerAddItem(cid, items[10], 1)
        selfSay('Parabens, voce acaba de adquirir um '..getItemNameById(items[10])..'.', cid)
    else
        selfSay('Voce nao tem Storage o suficiente.', cid)
    talkState[talkUser] = 0
    end
end

end
return true
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())

 

Funcionou quase perfeitamente, o NPC está checando a quantidade, entregando o item normalmente, mas pelo que vi, quando você compra algum item a quantidade de storage e é sentada para 0, então se o player quiser comprar mais de um item e tiver por exemplo 30 quantidades, após comprar um ele some, tem como consertar isso? Ajudaria bastante

10 minutos atrás, GniusP disse:

Me manda a script ja com os ids editado por favor

No momento to no celular, pior que acabei excluindo o arquivo, a NET do PC tá bugada, então eu copio o script e passo pro px através de um cabo USB.

As vezes buga e eu tenho que consertar vários símbolos no notepad que fica bugado quando colo, se conseguir consertar pode passar em .lua? Se não for incômodo

 

Pode pôr cerca de 8  itens, os IDS são: 15060 até 15067

  • 1
  • 2