Ir para conteúdo
  • 0

[Resolvido] NPC Dialog


Marshmello

Pergunta

Salve Rapeize, esses dias tava mexendo no meu npc dialog e tava tentando por pra quando abrir aparecer a outfit que o NPC esta usando, porem deu failed.... alguem ae tem algum jeito pra me ajudar???

 

 

Script do Modulo

 

Spoiler

local npcDialogWindow = nil

 


function init()
  connect(g_game, { onGameEnd = onGameEnd })
  npcDialogWindow = g_ui.displayUI('npcDialog')
  npcDialogWindow:hide()
  ProtocolGame.registerExtendedOpcode(80, NpcDialog)  
end

function terminate()
  disconnect(g_game, { onGameEnd = onGameEnd })
  npcDialogWindow:destroy()
  ProtocolGame.unregisterExtendedOpcode(80)
end

function onGameEnd()
  if npcDialogWindow:isVisible() then
    npcDialogWindow:hide()
    end
end

function show()
  npcDialogWindow:show()
  npcDialogWindow:raise()
  addEvent(function() g_effects.fadeIn(npcDialogWindow, 250) end)
end

function hide()
  addEvent(function() g_effects.fadeOut(npcDialogWindow, 250) end)
  scheduleEvent(function() npcDialogWindow:hide() end, 250)
end

function TchauDialog()
 addEvent(function() g_effects.fadeOut(npcDialogWindow, 250) end)
  scheduleEvent(function() npcDialogWindow:hide() end, 250)
  scheduleEvent(g_game.talkChannel(11,0,"tchau"), 250)
  end
 
local function clickOptionButton(option)
  g_game.talkChannel(11,0,option)

end

function NpcDialog(protocol, opcode, buffer, creature)
  local param = buffer:split('@')

  show()

  local image = "/modules/game_npcdialog/npcs/"..param[1]..".png"
  npcDialogWindow:getChildById('imgPokemon'):setImageSource(image)
  npcDialogWindow:getChildById('labelNpcName'):setText(param[1])
  npcDialogWindow:getChildById('labelTalk'):setText(param[2])
  npcDialogWindow:getChildById('optionButtonOne'):setVisible(false)
  npcDialogWindow:getChildById('optionButtonTwo'):setVisible(false)
  npcDialogWindow:getChildById('optionButtonThree'):setVisible(false)

  if (param[3] ~= nil) then
    local options = param[3]:split('&')

    if (options[1]) then
      local image = "/modules/game_npcdialog/npcs/"..param[1]..".png"
      npcDialogWindow:getChildById('imgPokemon'):setImageSource(image)
      npcDialogWindow:getChildById('optionButtonOne'):setVisible(true)
      npcDialogWindow:getChildById('optionButtonOne'):setText(options[1])
      npcDialogWindow:getChildById('optionButtonOne').onClick = function() clickOptionButton(options[1]) end
    end

    if (options[2]) then
      local image = "/modules/game_npcdialog/npcs/"..param[1]..".png"
      npcDialogWindow:getChildById('imgPokemon'):setImageSource(image)
      npcDialogWindow:getChildById('optionButtonTwo'):setVisible(true)
      npcDialogWindow:getChildById('optionButtonTwo'):setText(options[2])
      npcDialogWindow:getChildById('optionButtonTwo').onClick = function() clickOptionButton(options[2])  end
    end

    if (options[3]) then
      local image = "/modules/game_npcdialog/npcs/"..param[1]..".png"
      npcDialogWindow:getChildById('imgPokemon'):setImageSource(image)
      npcDialogWindow:getChildById('optionButtonThree'):setVisible(true)
      npcDialogWindow:getChildById('optionButtonThree'):setText(options[3])
      npcDialogWindow:getChildById('optionButtonThree').onClick = function() clickOptionButton(options[3]) end
    end
  end
end

 

 

Link para o comentário
Compartilhar em outros sites

9 respostass a esta questão

Posts Recomendados

  • 0

Fala @MarshmelloBlz!

Para que seja enviado a outfit do npc, mude sua função sendDialogNpc para essa:

Spoiler

function sendDialogNpc(cid, npc, message, options)
	if not(options) then
		options = ''
	end
	local structOtcOutfit = "{"..
		"  type = "..getCreatureOutfit(npc).lookType..
		", feet = "..getCreatureOutfit(npc).lookFeet..
		", addons = "..getCreatureOutfit(npc).lookAddons..
		", legs = "..getCreatureOutfit(npc).lookLegs..
		", auxType = "..getCreatureOutfit(npc).lookTypeEx..
		", head = "..getCreatureOutfit(npc).lookHead..
		", body = "..getCreatureOutfit(npc).lookBody..
	"}"
		 
	doSendPlayerExtendedOpcode(cid, 80, getCreatureName(npc)..'@'..structOtcOutfit..'@'..message..'@'..options) 
end

 

 

E na parte do module em npcdialog.lua mude sua função NpcDialog para esta:

Spoiler

function NpcDialog(protocol, opcode, buffer, creature)
  local param = buffer:split('@')

  show()

  local image = "/modules/game_npcdialog/npcs/"..param[1]..".png"
  npcDialogWindow:getChildById('imgPokemon'):setImageSource(image)
  npcDialogWindow:getChildById('labelNpcName'):setText(param[1])
  npcDialogWindow:getChildById('outfit'):setOutfit(loadstring('return '..param[2])()) -- >> Parte acrescentada <<
  npcDialogWindow:getChildById('labelTalk'):setText(param[3])
  npcDialogWindow:getChildById('optionButtonOne'):setVisible(false)
  npcDialogWindow:getChildById('optionButtonTwo'):setVisible(false)
  npcDialogWindow:getChildById('optionButtonThree'):setVisible(false)

  if (param[4] ~= nil) then
    local options = param[4]:split('&')

    if (options[1]) then
      local image = "/modules/game_npcdialog/npcs/"..param[1]..".png"
      npcDialogWindow:getChildById('imgPokemon'):setImageSource(image)
      npcDialogWindow:getChildById('optionButtonOne'):setVisible(true)
      npcDialogWindow:getChildById('optionButtonOne'):setText(options[1])
      npcDialogWindow:getChildById('optionButtonOne').onClick = function() clickOptionButton(options[1]) end
    end

    if (options[2]) then
      local image = "/modules/game_npcdialog/npcs/"..param[1]..".png"
      npcDialogWindow:getChildById('imgPokemon'):setImageSource(image)
      npcDialogWindow:getChildById('optionButtonTwo'):setVisible(true)
      npcDialogWindow:getChildById('optionButtonTwo'):setText(options[2])
      npcDialogWindow:getChildById('optionButtonTwo').onClick = function() clickOptionButton(options[2])  end
    end

    if (options[3]) then
      local image = "/modules/game_npcdialog/npcs/"..param[1]..".png"
      npcDialogWindow:getChildById('imgPokemon'):setImageSource(image)
      npcDialogWindow:getChildById('optionButtonThree'):setVisible(true)
      npcDialogWindow:getChildById('optionButtonThree'):setText(options[3])
      npcDialogWindow:getChildById('optionButtonThree').onClick = function() clickOptionButton(options[3]) end
    end
  end
end

 

Bom, acho que da para entender muito bem.

Link para o comentário
Compartilhar em outros sites

  • 0
local npcDialogWindow = nil

function init()
  connect(g_game, { onGameEnd = onGameEnd })
  npcDialogWindow = g_ui.displayUI('npcDialog')
  npcDialogWindow:hide()
  ProtocolGame.registerExtendedOpcode(80, NpcDialog)  
end

function terminate()
  disconnect(g_game, { onGameEnd = onGameEnd })
  npcDialogWindow:destroy()
  ProtocolGame.unregisterExtendedOpcode(80)
end

function onGameEnd()
  if npcDialogWindow:isVisible() then
    npcDialogWindow:hide()
    end
end

function show()
  npcDialogWindow:show()
  npcDialogWindow:raise()
  addEvent(function() g_effects.fadeIn(npcDialogWindow, 250) end)
end

function hide()
  addEvent(function() g_effects.fadeOut(npcDialogWindow, 250) end)
  scheduleEvent(function() npcDialogWindow:hide() end, 250)
end

function TchauDialog()
 addEvent(function() g_effects.fadeOut(npcDialogWindow, 250) end)
  scheduleEvent(function() npcDialogWindow:hide() end, 250)
  scheduleEvent(g_game.talkChannel(11,0,"tchau"), 250)
  end
 
local function clickOptionButton(option)
  g_game.talkChannel(11,0,option)
end

function NpcDialog(protocol, opcode, buffer, creature)
  local param = buffer:split('@')
  local image = "/modules/game_npcdialog/npcs/"..param[1]..".png"
  npcDialogWindow:getChildById('imgPokemon'):setImageSource(image)
  npcDialogWindow:getChildById('labelNpcName'):setText(param[1])
  npcDialogWindow:getChildById('outfitBox'):setOutfit(loadstring('return '..param[2])())
  npcDialogWindow:getChildById('labelTalk'):setText(param[3])
  npcDialogWindow:getChildById('optionButtonOne'):setVisible(false)
  npcDialogWindow:getChildById('optionButtonTwo'):setVisible(false)
  npcDialogWindow:getChildById('optionButtonThree'):setVisible(false)

  if (param[4] ~= nil) then
    local options = param[4]:split('&')

    if (options[1]) then
      local image = "/modules/game_npcdialog/npcs/"..param[1]..".png"
      npcDialogWindow:getChildById('imgPokemon'):setImageSource(image)
      npcDialogWindow:getChildById('optionButtonOne'):setVisible(true)
      npcDialogWindow:getChildById('optionButtonOne'):setText(options[1])
      npcDialogWindow:getChildById('optionButtonOne').onClick = function() clickOptionButton(options[1]) end
    end

    if (options[2]) then
      local image = "/modules/game_npcdialog/npcs/"..param[1]..".png"
      npcDialogWindow:getChildById('imgPokemon'):setImageSource(image)
      npcDialogWindow:getChildById('optionButtonTwo'):setVisible(true)
      npcDialogWindow:getChildById('optionButtonTwo'):setText(options[2])
      npcDialogWindow:getChildById('optionButtonTwo').onClick = function() clickOptionButton(options[2])  end
    end

    if (options[3]) then
      local image = "/modules/game_npcdialog/npcs/"..param[1]..".png"
      npcDialogWindow:getChildById('imgPokemon'):setImageSource(image)
      npcDialogWindow:getChildById('optionButtonThree'):setVisible(true)
      npcDialogWindow:getChildById('optionButtonThree'):setText(options[3])
      npcDialogWindow:getChildById('optionButtonThree').onClick = function() clickOptionButton(options[3]) end
    end
  end
  
  show()
end

 

Link para o comentário
Compartilhar em outros sites

  • 0
2 horas atrás, Crypter disse:

local npcDialogWindow = nil

function init()
  connect(g_game, { onGameEnd = onGameEnd })
  npcDialogWindow = g_ui.displayUI('npcDialog')
  npcDialogWindow:hide()
  ProtocolGame.registerExtendedOpcode(80, NpcDialog)  
end

function terminate()
  disconnect(g_game, { onGameEnd = onGameEnd })
  npcDialogWindow:destroy()
  ProtocolGame.unregisterExtendedOpcode(80)
end

function onGameEnd()
  if npcDialogWindow:isVisible() then
    npcDialogWindow:hide()
    end
end

function show()
  npcDialogWindow:show()
  npcDialogWindow:raise()
  addEvent(function() g_effects.fadeIn(npcDialogWindow, 250) end)
end

function hide()
  addEvent(function() g_effects.fadeOut(npcDialogWindow, 250) end)
  scheduleEvent(function() npcDialogWindow:hide() end, 250)
end

function TchauDialog()
 addEvent(function() g_effects.fadeOut(npcDialogWindow, 250) end)
  scheduleEvent(function() npcDialogWindow:hide() end, 250)
  scheduleEvent(g_game.talkChannel(11,0,"tchau"), 250)
  end
 
local function clickOptionButton(option)
  g_game.talkChannel(11,0,option)
end

function NpcDialog(protocol, opcode, buffer, creature)
  local param = buffer:split('@')
  local image = "/modules/game_npcdialog/npcs/"..param[1]..".png"
  npcDialogWindow:getChildById('imgPokemon'):setImageSource(image)
  npcDialogWindow:getChildById('labelNpcName'):setText(param[1])
  npcDialogWindow:getChildById('outfitBox'):setOutfit(loadstring('return '..param[2])())
  npcDialogWindow:getChildById('labelTalk'):setText(param[3])
  npcDialogWindow:getChildById('optionButtonOne'):setVisible(false)
  npcDialogWindow:getChildById('optionButtonTwo'):setVisible(false)
  npcDialogWindow:getChildById('optionButtonThree'):setVisible(false)

  if (param[4] ~= nil) then
    local options = param[4]:split('&')

    if (options[1]) then
      local image = "/modules/game_npcdialog/npcs/"..param[1]..".png"
      npcDialogWindow:getChildById('imgPokemon'):setImageSource(image)
      npcDialogWindow:getChildById('optionButtonOne'):setVisible(true)
      npcDialogWindow:getChildById('optionButtonOne'):setText(options[1])
      npcDialogWindow:getChildById('optionButtonOne').onClick = function() clickOptionButton(options[1]) end
    end

    if (options[2]) then
      local image = "/modules/game_npcdialog/npcs/"..param[1]..".png"
      npcDialogWindow:getChildById('imgPokemon'):setImageSource(image)
      npcDialogWindow:getChildById('optionButtonTwo'):setVisible(true)
      npcDialogWindow:getChildById('optionButtonTwo'):setText(options[2])
      npcDialogWindow:getChildById('optionButtonTwo').onClick = function() clickOptionButton(options[2])  end
    end

    if (options[3]) then
      local image = "/modules/game_npcdialog/npcs/"..param[1]..".png"
      npcDialogWindow:getChildById('imgPokemon'):setImageSource(image)
      npcDialogWindow:getChildById('optionButtonThree'):setVisible(true)
      npcDialogWindow:getChildById('optionButtonThree'):setText(options[3])
      npcDialogWindow:getChildById('optionButtonThree').onClick = function() clickOptionButton(options[3]) end
    end
  end
  
  show()
end

 

Mesma coisa

Link para o comentário
Compartilhar em outros sites

  • 0

Printa no console o param e veja qual indice retorna a outift, possivelmente deve ser isso o param[2] não deve retornar o esperado, testei o aqui no meu e não dá erro nenhum.

Obs: estou usando o UICreature

Editado por Gengo
Link para o comentário
Compartilhar em outros sites

  • 0
32 minutos atrás, Gengo disse:

Printa no console o param e veja qual indice retorna a outift, possivelmente deve ser isso o param[2] não deve retornar o esperado, testei o aqui no meu e não dá erro nenhum.

Obs: estou usando o UICreature

Eu coseguir arrumar amigo, sua função me deu MT adianto obrigado

Link para o comentário
Compartilhar em outros sites

Visitante
Este tópico está impedido de receber novos posts.
  • Quem Está Navegando   0 membros estão online

    • Nenhum usuário registrado visualizando esta página.
×
×
  • Criar Novo...