Ir para conteúdo

Featured Replies

Postado

.Qual servidor ou website você utiliza como base? 

TFS 0.3.7 - 9.6

Qual o motivo deste tópico? 

Criar um NPC que reconheça e venda itens através do MOD Reputation.

Gostaria de um NPC que vendesse itens em troca dos pontos que ficam salvos na DATABASE referente ao Script MOD abaixo.

Exemplo: Eu tenho 50 pontos de REP,  e vou no NPC e compro uma Sword por 10 REP.

 

Agradeço desde já, e estarei no aguarde de qualquer ajuda.

Está surgindo algum erro? Se sim coloque-o aqui. 

Citar

 

 

Você tem o código disponível? Se tiver publique-o aqui: LINK do MOD:

 

 

 

 

Você tem alguma imagem que possa auxiliar no problema? Se sim, coloque-a aqui. 

 

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

Resolvido por Nego Tchuca

Ir para solução
  • Nego Tchuca mudou o título para Conexão de MOD Reputation com NPC
Postado

@Nego Tchuca Boa tarde, eu testei em um servidor 8.6 com tfs 0.4, acho que vai funcionar no seu.

 

1° Vá em data/lib e crie um arquivo chamado rep_seller_items.lua e adicione isto dentro: (as configurações estão comentadas nele)

-- Caso a coluna "REP" da tabela de players for diferente coloque o nome dela aqui
rep_coluna_database = "rep"

-- As falas do npc
rep_falas_npc = {
  conversa = {
    ['trocar'] = 'Veja nossa {lista de items} e confira quantos reps cada um vale.',
    ['lista_de_items'] = 'Agora, me diga o nome do item que voce quer trocar.',
  },
  sucesso = {
    ['item_comprado'] = 'Otimo, aqui esta o seu novo item.',
  },
  falha = {
    ['rep_points_insuficientes'] = 'Desculpe, mais voce nao possui rep points suficientes para trocar por este item.',
    ['item_nao_encontrado'] = 'Nao encontrei este item, por favor tente outro.'
  }
}

-- Items que o npc irá vender
rep_items = {
  { item_id = 2124, quantidade_rep_points = 5},
  { item_id = 2472, quantidade_rep_points = 30},
  { item_id = 2520, quantidade_rep_points = 10},
}

 

2° Vá na pasta dos npcs em data/npc e crie um arquivo chamado Rep.xml e adicione isto nele:

<npc name="Rep" script="data/npc/scripts/repseller.lua" floorchange="0" access="5">
<health now="150" max="150"/>
<look type="143" head="2" body="112" legs="78" feet="116" addons="2" corpse="2212"/>
 <parameters>
  <parameter key="message_greet" value="Ola! Voce posso {trocar} seus rep points por itens."/>
    </parameters></npc>

 

3° Agora crie um arquivo de script chamado repseller.lua na pasta data/npc/scripts e adicione isto nele:

dofile(getDataDir() .. "lib/rep_seller_items.lua")

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)
	local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid	
	if(not npcHandler:isFocused(cid)) then
			return false
		end

		if msgcontains(msg, 'trocar') then
			npcHandler:say(rep_falas_npc.conversa.trocar, cid)
      talkState[talkUser] = 1
    end

		if msgcontains(msg, 'lista de items') and talkState[talkUser] == 1 then
			mostrarListaItems(cid)
			npcHandler:say(rep_falas_npc.conversa.lista_de_items, cid)
			talkState[talkUser] = 2
		end

		if talkState[talkUser] == 2 then
			local item = buscarItemPeloNome(msg)
			if item == nil then
				return;
			end
			trocarRepPointsPeloItem(cid, item)
			talkState[talkUser] = 1
		end
return TRUE
end

function trocarRepPointsPeloItem(cid, item)
	local playerRepPoints = buscarRepPoints(cid)
	if item.quantidade_rep_points > playerRepPoints then
		npcHandler:say(rep_falas_npc.falha.rep_points_insuficientes, cid)
		return;
	end
	local quantidadeRepPointsParaRemover = playerRepPoints - item.quantidade_rep_points
	if quantidadeRepPointsParaRemover < 0 then
		npcHandler:say(rep_falas_npc.falha.rep_points_insuficientes, cid)
		return;
	end
	if removerRepPoints(cid, quantidadeRepPointsParaRemover) then
		adicionarItemAoPlayer(cid, item)
		npcHandler:say(rep_falas_npc.sucesso.item_comprado, cid)
	end
end

function buscarRepPoints(cid)
	local sql = "SELECT `"..rep_coluna_database.."` FROM `players` WHERE id = " ..getPlayerGUID(cid)..";"
	local result = db.getResult(sql)
	if result:getID() <= -1 then
		return;
	end
	return result:getDataInt(rep_coluna_database)
end

function removerRepPoints(cid, quantidade)
	local sql = "UPDATE `players` SET `"..rep_coluna_database.."` = "..quantidade.." WHERE id = "..getPlayerGUID(cid)..";"
	local result = db.executeQuery(sql)
	if result == -1 then
		return false
	end
	return true
end

function mostrarListaItems(cid) 
	local message = ''
	for index = 1, #rep_items, 1 do
		local item = rep_items[index]
		local item_nome = getItemNameById(item.item_id)
		message = item_nome .. " - " .. item.quantidade_rep_points .. " REP Point(s)" .. "\n" .. message
	end
	doPlayerPopupFYI(cid, message)
end

function adicionarItemAoPlayer(cid, item)
	doPlayerAddItem(cid, item.item_id)
end

function buscarItemPeloNome(nome)
	for index = 1, #rep_items, 1 do
		local item = rep_items[index]
		local item_nome = getItemNameById(item.item_id)
		if (string.lower(nome) == string.lower(item_nome)) then
			return item
		end
	end
end

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

 

Espero ter ajudado

Postado
  • Autor
  • Solução
Em 21/08/2021 em 13:39, MatteusDeli disse:

@Nego Tchuca Boa tarde, eu testei em um servidor 8.6 com tfs 0.4, acho que vai funcionar no seu.

 

1° Vá em data/lib e crie um arquivo chamado rep_seller_items.lua e adicione isto dentro: (as configurações estão comentadas nele)


-- Caso a coluna "REP" da tabela de players for diferente coloque o nome dela aqui
rep_coluna_database = "rep"

-- As falas do npc
rep_falas_npc = {
  conversa = {
    ['trocar'] = 'Veja nossa {lista de items} e confira quantos reps cada um vale.',
    ['lista_de_items'] = 'Agora, me diga o nome do item que voce quer trocar.',
  },
  sucesso = {
    ['item_comprado'] = 'Otimo, aqui esta o seu novo item.',
  },
  falha = {
    ['rep_points_insuficientes'] = 'Desculpe, mais voce nao possui rep points suficientes para trocar por este item.',
    ['item_nao_encontrado'] = 'Nao encontrei este item, por favor tente outro.'
  }
}

-- Items que o npc irá vender
rep_items = {
  { item_id = 2124, quantidade_rep_points = 5},
  { item_id = 2472, quantidade_rep_points = 30},
  { item_id = 2520, quantidade_rep_points = 10},
}

 

2° Vá na pasta dos npcs em data/npc e crie um arquivo chamado Rep.xml e adicione isto nele:


<npc name="Rep" script="data/npc/scripts/repseller.lua" floorchange="0" access="5">
<health now="150" max="150"/>
<look type="143" head="2" body="112" legs="78" feet="116" addons="2" corpse="2212"/>
 <parameters>
  <parameter key="message_greet" value="Ola! Voce posso {trocar} seus rep points por itens."/>
    </parameters></npc>

 

3° Agora crie um arquivo de script chamado repseller.lua na pasta data/npc/scripts e adicione isto nele:


dofile(getDataDir() .. "lib/rep_seller_items.lua")

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)
	local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid	
	if(not npcHandler:isFocused(cid)) then
			return false
		end

		if msgcontains(msg, 'trocar') then
			npcHandler:say(rep_falas_npc.conversa.trocar, cid)
      talkState[talkUser] = 1
    end

		if msgcontains(msg, 'lista de items') and talkState[talkUser] == 1 then
			mostrarListaItems(cid)
			npcHandler:say(rep_falas_npc.conversa.lista_de_items, cid)
			talkState[talkUser] = 2
		end

		if talkState[talkUser] == 2 then
			local item = buscarItemPeloNome(msg)
			if item == nil then
				return;
			end
			trocarRepPointsPeloItem(cid, item)
			talkState[talkUser] = 1
		end
return TRUE
end

function trocarRepPointsPeloItem(cid, item)
	local playerRepPoints = buscarRepPoints(cid)
	if item.quantidade_rep_points > playerRepPoints then
		npcHandler:say(rep_falas_npc.falha.rep_points_insuficientes, cid)
		return;
	end
	local quantidadeRepPointsParaRemover = playerRepPoints - item.quantidade_rep_points
	if quantidadeRepPointsParaRemover < 0 then
		npcHandler:say(rep_falas_npc.falha.rep_points_insuficientes, cid)
		return;
	end
	if removerRepPoints(cid, quantidadeRepPointsParaRemover) then
		adicionarItemAoPlayer(cid, item)
		npcHandler:say(rep_falas_npc.sucesso.item_comprado, cid)
	end
end

function buscarRepPoints(cid)
	local sql = "SELECT `"..rep_coluna_database.."` FROM `players` WHERE id = " ..getPlayerGUID(cid)..";"
	local result = db.getResult(sql)
	if result:getID() <= -1 then
		return;
	end
	return result:getDataInt(rep_coluna_database)
end

function removerRepPoints(cid, quantidade)
	local sql = "UPDATE `players` SET `"..rep_coluna_database.."` = "..quantidade.." WHERE id = "..getPlayerGUID(cid)..";"
	local result = db.executeQuery(sql)
	if result == -1 then
		return false
	end
	return true
end

function mostrarListaItems(cid) 
	local message = ''
	for index = 1, #rep_items, 1 do
		local item = rep_items[index]
		local item_nome = getItemNameById(item.item_id)
		message = item_nome .. " - " .. item.quantidade_rep_points .. " REP Point(s)" .. "\n" .. message
	end
	doPlayerPopupFYI(cid, message)
end

function adicionarItemAoPlayer(cid, item)
	doPlayerAddItem(cid, item.item_id)
end

function buscarItemPeloNome(nome)
	for index = 1, #rep_items, 1 do
		local item = rep_items[index]
		local item_nome = getItemNameById(item.item_id)
		if (string.lower(nome) == string.lower(item_nome)) then
			return item
		end
	end
end

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

 

Espero ter ajudado

Muito Obrigado desde já, muita correria e só agora que vi a sua  mensagem.

Vou testar e já falo se deu certo.

Em 21/08/2021 em 13:39, MatteusDeli disse:

@Nego Tchuca Boa tarde, eu testei em um servidor 8.6 com tfs 0.4, acho que vai funcionar no seu.

 

1° Vá em data/lib e crie um arquivo chamado rep_seller_items.lua e adicione isto dentro: (as configurações estão comentadas nele)





-- Caso a coluna "REP" da tabela de players for diferente coloque o nome dela aqui
rep_coluna_database = "rep"

-- As falas do npc
rep_falas_npc = {
  conversa = {
    ['trocar'] = 'Veja nossa {lista de items} e confira quantos reps cada um vale.',
    ['lista_de_items'] = 'Agora, me diga o nome do item que voce quer trocar.',
  },
  sucesso = {
    ['item_comprado'] = 'Otimo, aqui esta o seu novo item.',
  },
  falha = {
    ['rep_points_insuficientes'] = 'Desculpe, mais voce nao possui rep points suficientes para trocar por este item.',
    ['item_nao_encontrado'] = 'Nao encontrei este item, por favor tente outro.'
  }
}

-- Items que o npc irá vender
rep_items = {
  { item_id = 2124, quantidade_rep_points = 5},
  { item_id = 2472, quantidade_rep_points = 30},
  { item_id = 2520, quantidade_rep_points = 10},
}

 

2° Vá na pasta dos npcs em data/npc e crie um arquivo chamado Rep.xml e adicione isto nele:





<npc name="Rep" script="data/npc/scripts/repseller.lua" floorchange="0" access="5">
<health now="150" max="150"/>
<look type="143" head="2" body="112" legs="78" feet="116" addons="2" corpse="2212"/>
 <parameters>
  <parameter key="message_greet" value="Ola! Voce posso {trocar} seus rep points por itens."/>
    </parameters></npc>

 

3° Agora crie um arquivo de script chamado repseller.lua na pasta data/npc/scripts e adicione isto nele:





dofile(getDataDir() .. "lib/rep_seller_items.lua")

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)
	local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid	
	if(not npcHandler:isFocused(cid)) then
			return false
		end

		if msgcontains(msg, 'trocar') then
			npcHandler:say(rep_falas_npc.conversa.trocar, cid)
      talkState[talkUser] = 1
    end

		if msgcontains(msg, 'lista de items') and talkState[talkUser] == 1 then
			mostrarListaItems(cid)
			npcHandler:say(rep_falas_npc.conversa.lista_de_items, cid)
			talkState[talkUser] = 2
		end

		if talkState[talkUser] == 2 then
			local item = buscarItemPeloNome(msg)
			if item == nil then
				return;
			end
			trocarRepPointsPeloItem(cid, item)
			talkState[talkUser] = 1
		end
return TRUE
end

function trocarRepPointsPeloItem(cid, item)
	local playerRepPoints = buscarRepPoints(cid)
	if item.quantidade_rep_points > playerRepPoints then
		npcHandler:say(rep_falas_npc.falha.rep_points_insuficientes, cid)
		return;
	end
	local quantidadeRepPointsParaRemover = playerRepPoints - item.quantidade_rep_points
	if quantidadeRepPointsParaRemover < 0 then
		npcHandler:say(rep_falas_npc.falha.rep_points_insuficientes, cid)
		return;
	end
	if removerRepPoints(cid, quantidadeRepPointsParaRemover) then
		adicionarItemAoPlayer(cid, item)
		npcHandler:say(rep_falas_npc.sucesso.item_comprado, cid)
	end
end

function buscarRepPoints(cid)
	local sql = "SELECT `"..rep_coluna_database.."` FROM `players` WHERE id = " ..getPlayerGUID(cid)..";"
	local result = db.getResult(sql)
	if result:getID() <= -1 then
		return;
	end
	return result:getDataInt(rep_coluna_database)
end

function removerRepPoints(cid, quantidade)
	local sql = "UPDATE `players` SET `"..rep_coluna_database.."` = "..quantidade.." WHERE id = "..getPlayerGUID(cid)..";"
	local result = db.executeQuery(sql)
	if result == -1 then
		return false
	end
	return true
end

function mostrarListaItems(cid) 
	local message = ''
	for index = 1, #rep_items, 1 do
		local item = rep_items[index]
		local item_nome = getItemNameById(item.item_id)
		message = item_nome .. " - " .. item.quantidade_rep_points .. " REP Point(s)" .. "\n" .. message
	end
	doPlayerPopupFYI(cid, message)
end

function adicionarItemAoPlayer(cid, item)
	doPlayerAddItem(cid, item.item_id)
end

function buscarItemPeloNome(nome)
	for index = 1, #rep_items, 1 do
		local item = rep_items[index]
		local item_nome = getItemNameById(item.item_id)
		if (string.lower(nome) == string.lower(item_nome)) then
			return item
		end
	end
end

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

 

Espero ter ajudado

@MatteusDeli muito obrigado, está funcionando 100%  e sem nenhum erro.

Muito Obrigado mesmo.

 

Seria possível o NPC primeiramente perguntar se o player quer comprar o item antes de retirar os pontos de REP?

 

De qualquer forma, muito obrigado, me ajudou muito.

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.

Estatísticas dos Fóruns

  • Tópicos 96.9k
  • Posts 519.7k

Informação Importante

Confirmação de Termo