Ir para conteúdo

Featured Replies

Postado

Fale rapaziada. Preciso da ajuda para criar um npc em que ele só ira trocar uma quantidade x de item por uma moeda.

EXEMPLO:

'COIN=2151'

NPC: Ola 'JOGADOR', eu vendo a 'PICK' para minerar e também compro os 'ITENS' minerados.

PLAYER: PICK

NPC: A pick custa x COIN/// PLAYER: YES ////// NPC: Aqui esta sua pick.

PLAYER: ITENS ////// NPC: Eu compro 100 sapphires por 10 COIN, 100 Skull por 15 COIN, 100 Diamond por 20 COIN. ///// PLAYER: YES //////// NPC: Aqui esta suas COIN. 

 

O npc precisa das quantidade exatas para trocar pela a COIN, e ele troca todos os itens automático. O player não precisa ficar falando qual item ele quer troca. Se ele tiver 1000 Sapphires, 100 Skull, 10000 Diamond, ele ja vai somar e trocar tudo.

Senhoras e senhores, se alguma resposta lhe ajudou, marque-a como a melhor resposta e de ponto positivo, assim você incentiva quem lhe ajudou a continuar ajudando!!.

  • 3 weeks later...
Postado

Opa..

 

Xml do Npc:

<?xml version="1.0"?>
<npc name="Miner" script="data/npc/scripts/mining.lua" walkinterval="50000" floorchange="0">
<health now="1000" max="1000"/>
<look type="130" head="0" body="10" legs="10" feet="0" addons="0"/>
<parameters>
<parameter key="message_greet" value="Ola |PLAYERNAME|, eu vendo a {pick} para minerar e também compro os {itens} minerados"/>
</parameters>
</npc>

Script do Npc:

Spoiler

--------CONFIG---------#
local goldID = 2148 -- ID do gold 
local pickID = 2553 -- ID da pick
local pick_value = 10 -- Preço da pick

local itens = {
--[NOME DO ITEM] = QUANTIDADE--
["Skull"] = 100,
["Diamond"] = 100,
["Gold Nugget"] = 50,

}

local cost_Item = {
--[VALOR DO ITEM] = ID DO ITEM    
[1] = 2229, -- Skull
[2] = 2145, -- Diamond
[10] = 2157, -- Gold Nugget

}
-----------------------

local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local talkState = {}
local result = {}
local count = {}
local t = {}
local j = {}
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
msg,players = string.lower(msg), {getPlayerGUID(cid)}

if msgcontains(msg, 'pick') or msgcontains(msg, 'PICK') then
        npcHandler:say("A pick custa "..pick_value.." COIN, diga {yes} se quiser compra-la", cid)
        talkState[talkUser] = 1

   else if msgcontains(msg, 'yes') and talkState[talkUser] == 1 then
            if getPlayerMoney(cid) >= pick_value then
                    doPlayerAddItem(cid, pickID, 1)
                    doPlayerRemoveMoney(cid, pick_value)
                    npcHandler:say("Aqui esta sua pick.", cid)
                    talkState[talkUser] = 0
            else
                npcHandler:say("Voce nao possui dinheiro suficiente para comprar.", cid)
                talkState[talkUser] = 0
            end
   end
end

if msgcontains(msg, 'itens') or msgcontains(msg, 'ITENS') then
    
        for k,v in pairs(itens) do
            table.insert(result, v.." "..k.." por ")
            table.insert(count, v)
            
        end

        for k,v in pairs(cost_Item) do
            table.insert(t, k)
        end
        
        for i = 1, #result, 1 do
            x = result..""..t.." COINS "
            table.insert(j, x)
        end

            p = table.concat(j, ", ")        
            npcHandler:say("Eu compro "..p, cid)
            talkState[talkUser] = 2
            for i = 1, #j, 1 do
                table.remove(j, p)
                table.remove(result, p)
                table.remove(t, p)
            end    
        
else if msgcontains(msg, 'yes') and talkState[talkUser] == 2 then
        for _,v in pairs(itens) do
            for i,k in pairs(cost_Item) do
                if getPlayerItemCount(cid, k) == v then
                    doPlayerRemoveItem(cid, k, v)
                    doPlayerAddMoney(cid, i)
                    talkState[talkUser] = 3
                    break
                end
            end
        end
     if (talkState[talkUser] == 3) then
         npcHandler:say("Aqui esta suas COIN", cid)
         talkState[talkUser] = 0
         for i = 1, #j, 1 do
                table.remove(j, p)
                table.remove(result, p)
                table.remove(t, p)
        end
     else
         npcHandler:say("Voce nao possui os itens que eu preciso!", cid)
         talkState[talkUser] = 0
         for i = 1, #j, 1 do
                table.remove(j, p)
                table.remove(result, p)
                table.remove(t, p)
        end
     end
end
end
end

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


 

 

OBS: Para adicionar mais itens segue o exemplo. (Tem que estar na mesma ordem nas 2 tabelas!)

 

--------CONFIG---------#
local goldID = 2148 -- ID do gold 
local pickID = 2553 -- ID da pick
local pick_value = 10 -- Preço da pick

local itens = {
--[NOME DO ITEM] = QUANTIDADE--
["Skull"] = 100,
["Diamond"] = 100,
["Gold Nugget"] = 50,

["Worm"] = 30,

}

local cost_Item = {
--[VALOR DO ITEM] = ID DO ITEM    
[1] = 2229, -- Skull
[2] = 2145, -- Diamond
[10] = 2157, -- Gold Nugget

[3] = 2884, --Worm

}

 

Postado
  • Autor
Em 09/06/2019 em 00:01, Bolletox disse:

Opa..

 

Xml do Npc:


<?xml version="1.0"?>
<npc name="Miner" script="data/npc/scripts/mining.lua" walkinterval="50000" floorchange="0">
<health now="1000" max="1000"/>
<look type="130" head="0" body="10" legs="10" feet="0" addons="0"/>
<parameters>
<parameter key="message_greet" value="Ola |PLAYERNAME|, eu vendo a {pick} para minerar e também compro os {itens} minerados"/>
</parameters>
</npc>

Script do Npc:

  Ocultar conteúdo

--------CONFIG---------#
local goldID = 2148 -- ID do gold 
local pickID = 2553 -- ID da pick
local pick_value = 10 -- Preço da pick

local itens = {
--[NOME DO ITEM] = QUANTIDADE--
["Skull"] = 100,
["Diamond"] = 100,
["Gold Nugget"] = 50,

}

local cost_Item = {
--[VALOR DO ITEM] = ID DO ITEM    
[1] = 2229, -- Skull
[2] = 2145, -- Diamond
[10] = 2157, -- Gold Nugget

}
----------------------- 

local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local talkState = {}
local result = {}
local count = {}
local t = {}
local j = {}
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
msg,players = string.lower(msg), {getPlayerGUID(cid)}

if msgcontains(msg, 'pick') or msgcontains(msg, 'PICK') then
        npcHandler:say("A pick custa "..pick_value.." COIN, diga {yes} se quiser compra-la", cid)
        talkState[talkUser] = 1

   else if msgcontains(msg, 'yes') and talkState[talkUser] == 1 then
            if getPlayerMoney(cid) >= pick_value then
                    doPlayerAddItem(cid, pickID, 1)
                    doPlayerRemoveMoney(cid, pick_value)
                    npcHandler:say("Aqui esta sua pick.", cid)
                    talkState[talkUser] = 0
            else
                npcHandler:say("Voce nao possui dinheiro suficiente para comprar.", cid)
                talkState[talkUser] = 0
            end
   end
end

if msgcontains(msg, 'itens') or msgcontains(msg, 'ITENS') then
    
        for k,v in pairs(itens) do
            table.insert(result, v.." "..k.." por ")
            table.insert(count, v)
            
        end

        for k,v in pairs(cost_Item) do
            table.insert(t, k)
        end
        
        for i = 1, #result, 1 do
            x = result..""..t.." COINS "
            table.insert(j, x)
        end

            p = table.concat(j, ", ")        
            npcHandler:say("Eu compro "..p, cid)
            talkState[talkUser] = 2
            for i = 1, #j, 1 do
                table.remove(j, p)
                table.remove(result, p)
                table.remove(t, p)
            end    
        
else if msgcontains(msg, 'yes') and talkState[talkUser] == 2 then
        for _,v in pairs(itens) do
            for i,k in pairs(cost_Item) do
                if getPlayerItemCount(cid, k) == v then
                    doPlayerRemoveItem(cid, k, v)
                    doPlayerAddMoney(cid, i)
                    talkState[talkUser] = 3
                    break
                end
            end
        end
     if (talkState[talkUser] == 3) then
         npcHandler:say("Aqui esta suas COIN", cid)
         talkState[talkUser] = 0
         for i = 1, #j, 1 do
                table.remove(j, p)
                table.remove(result, p)
                table.remove(t, p)
        end
     else
         npcHandler:say("Voce nao possui os itens que eu preciso!", cid)
         talkState[talkUser] = 0
         for i = 1, #j, 1 do
                table.remove(j, p)
                table.remove(result, p)
                table.remove(t, p)
        end
     end
end
end
end

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


 

 

OBS: Para adicionar mais itens segue o exemplo. (Tem que estar na mesma ordem nas 2 tabelas!)

 

--------CONFIG---------#
local goldID = 2148 -- ID do gold 
local pickID = 2553 -- ID da pick
local pick_value = 10 -- Preço da pick

local itens = {
--[NOME DO ITEM] = QUANTIDADE--
["Skull"] = 100,
["Diamond"] = 100,
["Gold Nugget"] = 50,

["Worm"] = 30,

}

local cost_Item = {
--[VALOR DO ITEM] = ID DO ITEM    
[1] = 2229, -- Skull
[2] = 2145, -- Diamond
[10] = 2157, -- Gold Nugget

[3] = 2884, --Worm

}

 

 

Valeu por ajudar.

 

Esta dando esse erro.

 

 


[Error - NpcScript Interface]
data/npc/scripts/mining.lua:onCreatureSay
Description:
data/npc/scripts/mining.lua:63: attempt to concatenate upvalue 't' (a table value)
stack traceback:
        data/npc/scripts/mining.lua:63: in function 'callback'
        data/npc/lib/npcsystem/npchandler.lua:423: in function 'onCreatureSay'
        data/npc/scripts/mining.lua:28: in function <data/npc/scripts/mining.lua:28>

 

 

 

## EDIT ####

Consegui arrumar o erro do t, agora aparece um erro do remove

image.thumb.png.8d1e121fba526f2defef7dfd80464ac5.png

Editado por tetheuscunha (veja o histórico de edições)

Senhoras e senhores, se alguma resposta lhe ajudou, marque-a como a melhor resposta e de ponto positivo, assim você incentiva quem lhe ajudou a continuar ajudando!!.

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.

Visitante
Responder

Quem Está Navegando 0

  • Nenhum usuário registrado visualizando esta página.

Conteúdo Similar

Estatísticas dos Fóruns

  • Tópicos 96.9k
  • Posts 519.6k

Informação Importante

Confirmação de Termo