Ir para conteúdo

[Pedido] NPC que transfira pontos físicos no jogo em pontos no site

Featured Replies

Postado

Por isso que odeio npcs da versão 0.4

local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)

local talkState = {}
 
local k = {
	item = 9970
} 
 
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 function getCount(s)
	local b, e = s:find('%d+')
	return b and e and math.min(4294967295, tonumber(s:sub(b, e))) or -1
end

function creatureSayCallback(cid, type, msg)
	local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid
	if not npcHandler:isFocused(cid) then
		return false
	elseif msgcontains(msg, 'transfer') then
		npcHandler:say('Please tell me the amount that you want change.', cid)
		talkState[talkUser] = 1
		if talkState[talkUser] == 1 then
			if getCount(msg) == -1 then
				npcHandler:say('Please tell me the amount that you want change.', cid)
				talkState[talkUser] = nil
			else
				count[cid] = getCount(msg)
				npcHandler:say('Do you want change ' .. count[cid] .. ' '.. getItemNameById(k.item) ..' for ' .. count[cid] .. ' premium points in the website?', cid)
				talkState[talkUser] = 2
			end
		end
	elseif talkState[talkUser] == 2 and msgcontains(msg, 'yes') then
		if doPlayerRemoveItem(cid, k.item, count[cid]) then
			local p = "UPDATE `accounts` SET `premium_points` = `premium_points` + ".. count[cid] .." where id="..getPlayerAccountId(cid)
			db.executeQuery(p)
			npcHandler:say('Very well. You have transfered ' .. count[cid] .. ' '.. getItemNameById(k.item) ..' for ' .. count[cid] .. '.', cid)
			talkState[talkUser] = nil
		else
			npcHandler:say('You do not have the items.', cid)
			talkState[talkUser] = nil
		end
	elseif talkState[talkUser] == 2 and msgcontains(msg, 'no') then
		npcHandler:say('Ok then.', cid)
		talkState[talkUser] = nil
	end
	return true
end
 
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())

 

discord.pngDiscord: vankk #7765

Precisando de ajuda? Entre em contato comigo via Discord.

 

Muitos vêm seus muitos dias de glória, mas poucos vêm seus muitos dias de luta.

  • Respostas 22
  • Visualizações 804
  • Created
  • Última resposta

Top Posters In This Topic

Most Popular Posts

  • tenta assim   local keywordHandler = KeywordHandler:new() local npcHandler = NpcHandler:new(keywordHandler) NpcSystem.parseParameters(npcHandler) local talkState = {} function onCreature

  • count[cid] = getCount(msg) /\   to indo pra aula agr, depois eu ajudo.. mas acho q o problema é essa parte aqui e outra: TFS 0.4 é db.query em vez de db.executeQuery  

  • Depois da uma ajudada nesse tópico ai, pq 0.4 fede

Postado

Não foi seu, foi meu mesmo, eu esqueço sempre de configurar o talkState mesmo. Testa e veja o que da.

discord.pngDiscord: vankk #7765

Precisando de ajuda? Entre em contato comigo via Discord.

 

Muitos vêm seus muitos dias de glória, mas poucos vêm seus muitos dias de luta.

Postado
  • Autor

@vankk

Agora quando eu falo hi > transfer acontece o seguinte:

19:29 Transferir Pontos: Please tell me the amount that you want change.
19:29 Transferir Pontos: Please tell me the amount that you want change.
19:29 GM Vy'n [661]: 100

 

Ele manda a mensagem duas vezes ai eu mando a quantidade ele não fala mais nada, e não da nenhum erro na distro.

Editado por One Punch Man (veja o histórico de edições)

x1fCxnI.png

Postado
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)

local talkState = {}
 
local k = {
	item = 9970
} 
 
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 function getCount(s)
	local b, e = s:find('%d+')
	return b and e and math.min(4294967295, tonumber(s:sub(b, e))) or -1
end

function creatureSayCallback(cid, type, msg)
	local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid
	if not npcHandler:isFocused(cid) then
		return false
	elseif msgcontains(msg, 'transfer') then
		npcHandler:say('Please tell me the amount that you want change.', cid)
		talkState[talkUser] = 1
		if talkState[talkUser] == 1 then
			if getCount(msg) == -1 then
				count[cid] = getCount(msg)
				npcHandler:say('Do you want change ' .. count[cid] .. ' '.. getItemNameById(k.item) ..' for ' .. count[cid] .. ' premium points in the website?', cid)
				talkState[talkUser] = 2
			end
		end
	elseif talkState[talkUser] == 2 and msgcontains(msg, 'yes') then
		if doPlayerRemoveItem(cid, k.item, count[cid]) then
			local p = "UPDATE `accounts` SET `premium_points` = `premium_points` + ".. count[cid] .." where id="..getPlayerAccountId(cid)
			db.executeQuery(p)
			npcHandler:say('Very well. You have transfered ' .. count[cid] .. ' '.. getItemNameById(k.item) ..' for ' .. count[cid] .. '.', cid)
			talkState[talkUser] = nil
		else
			npcHandler:say('You do not have the items.', cid)
			talkState[talkUser] = nil
		end
	elseif talkState[talkUser] == 2 and msgcontains(msg, 'no') then
		npcHandler:say('Ok then.', cid)
		talkState[talkUser] = nil
	end
	return true
end
 
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())

 

discord.pngDiscord: vankk #7765

Precisando de ajuda? Entre em contato comigo via Discord.

 

Muitos vêm seus muitos dias de glória, mas poucos vêm seus muitos dias de luta.

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