muito bom
- Fórum
- OTServ
- Tutoriais
- Tutoriais de Clients
- [OTClient] Sistema de Dialogo Otpokemon
[OTClient] Sistema de Dialogo Otpokemon
Por Gengo, 29 de ago. de 2020 em Tutoriais de Clients
Em 29/08/2020 em 15:44, Gengo disse:[OTClient] Sistema de Dialogo Otpokemon
Venho através desse tópico contribuir para a comunidade, um simples modulo de dialogo no estilo do Otpokemon,
não é um sistema de dialogo avançado é algo simples que deixa seu servidor intuitivo.
1) Faça o download do modulo no qual se encontra no final do tópico e abrindo a pasta do seu client, extraia e coloque o modulo na pasta modules.
2) O módulo utiliza uma função chamada switch que não é comum ter no otclient, porem podemos colocar sem muito esforço, na pasta do otclient abra o arquivo util.lua que se encontra em modules/corelib/ e no final do arquivo coloque o seguinte código:
function switch(indice) return function(codetable) local case = codetable[indice] or codetable.default if ( case ) then if ( type(case) == "function" ) then return case(indice) else error("action "..tostring(indice).." not a function") end end end end
Feito o passo 1 e 2, vamos para a parte do servidor.
1) Crie um arquivo na pasta data/lib/ podendo ter o nome de npcdialog_lib.lua e coloque o seguinte código:
local OpcodeDialog = 80 local Actions = { open = 1, closed = 2 } function doSendDialogNpc(cid, npc, msg, opc) if ( not opc ) then opc = '' end doSendPlayerExtendedOpcode(cid, OpcodeDialog, table.serialize({ action = Actions.open, data = { npcId = npc, message = msg, options = opc } })) end function doSendDialogNpcClose(cid) doSendPlayerExtendedOpcode(cid, OpcodeDialog, table.serialize({ action = Actions.closed })) end
2) O arquivo que acabamos de criar utiliza uma função chamada table.serialize que não é comum ter nos servidores, para que funcione sem erros vamos adicionar, abra o arquivo 012-table.lua que fica na pasta do seu servidor em data/lib/ ou você pode criar o arquivo e adicionar o seguinte código:
table.serialize = function(x, recur) local t = type(x) recur = recur or {} if t == nil then return "nil" elseif t == "string" then return string.format("%q", x) elseif t == "number" then return tostring(x) elseif t == "boolean" then return t and "true" or "false" elseif getmetatable(x) then error("Can not serialize a table that has a metatable associated with it.") elseif t == "table" then if(table.find(recur, x)) then error("Can not serialize recursive tables.") end table.insert(recur, x) local s = "{" for k, v in pairs(x) do s = s .. "[" .. table.serialize(k, recur) .. "]" s = s .. " = " .. table.serialize(v, recur) .. "," end s = s .. "}" return s else error("Can not serialize value of type '" .. t .. "'.") end end
Feito todo esse procedimento, estarei disponibilizando um npc para que vocês possam ter uma noção de como utilizar esse sistema de dialogo.
1) Crie um arquivo na pasta do servidor em data/npc/ chamado Gengo.xml e adicione o seguinte código:
<?xml version="1.0" encoding="UTF-8"?> <npc name="Gengo" script="gengo.lua"> <health now="150" max="150"/> <look type="1413" head="114" body="119" legs="114" feet="114" corpse="2212"/> </npc>
2) Crie um arquivo na pasta do servidor em data/npc/lib/ com o nome gengo.lua e adicione o seguinte código:
local keywordHandler = KeywordHandler:new() local npcHandler = NpcHandler:new(keywordHandler) NpcSystem.parseParameters(npcHandler) function onThink() npcHandler:onThink() end 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 greetCallback(cid) doSendDialogNpc(cid, getNpcId(), "Olá jovem, vejo que você conseguiu chegar até aqui!\nClique em Recompensa e fique feliz pela conquista!", "Fechar&Recompensa") return true end function creatureSayCallback(cid, type, msg) if not npcHandler:isFocused(cid) then return false end if msgcontains(msg:lower(), "recompensa") then local message = "" if getPlayerStorageValue(cid, 7000) == -1 then setPlayerStorageValue(cid, 7000, 1) doPlayerAddItem(cid, 2160, 1) message = "Você acaba de ganhar uns trocado por chegar até aqui.\nVolte sempre!" else message = "Você ja pegou sua recompensa, obrigado e volte sempre!" end doSendDialogNpc(cid, getNpcId(), message, "Fechar") elseif msgcontains(msg:lower(), "fechar") then doSendDialogNpcClose(cid) npcHandler:unGreet(cid) end return true end npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback) npcHandler:setCallback(CALLBACK_GREET, greetCallback) npcHandler:addModule(FocusModule:new())
O npc é algo simples, porem serve para que você possa ter uma noção de como utilizar as funções do npc.
Demostrativo dentro do game:
![]()
Arquivos para download e o scan:
meu servidor e pda e da esse erro quando digo hi
[01/09/2020 18:42:24] [Error - Npc interface]
[01/09/2020 18:42:24] data/npc/scripts/gengo.lua:onCreatureSay
[01/09/2020 18:42:24] Description:
[01/09/2020 18:42:24] data/lib/012-table.lua:16: attempt to call field 'find' (a nil value)
[01/09/2020 18:42:24] stack traceback:
[01/09/2020 18:42:24] data/lib/012-table.lua:16: in function 'serialize'
[01/09/2020 18:42:24] data/lib/npcdialog_lib.lua:11: in function 'doSendDialogNpc'
[01/09/2020 18:42:24] data/npc/scripts/gengo.lua:11: in function 'callback'
[01/09/2020 18:42:24] data/npc/lib/npcsystem/npchandler.lua:339: in function 'greet'
[01/09/2020 18:42:24] data/npc/lib/npcsystem/npchandler.lua:512: in function 'onGreet'
[01/09/2020 18:42:24] data/npc/lib/npcsystem/modules.lua:222: in function 'callback'
[01/09/2020 18:42:24] data/npc/lib/npcsystem/keywordhandler.lua:40: in function 'processMessage'
[01/09/2020 18:42:24] data/npc/lib/npcsystem/keywordhandler.lua:168: in function 'processNodeMessage'
[01/09/2020 18:42:24] data/npc/lib/npcsystem/keywordhandler.lua:122: in function 'processMessage'
[01/09/2020 18:42:24] data/npc/lib/npcsystem/npchandler.lua:388: in function 'onCreatureSay'
[01/09/2020 18:42:24] data/npc/scripts/gengo.lua:8: in function <data/npc/scripts/gengo.lua:8>
info
Grupo: Cavaleiro
Registrado: 10/03/13
Posts: 177
Reputação: +202
Gênero: Masculino
Char no Tibia: stor akia

45 minutos atrás, raulcdj disse:meu servidor e pda e da esse erro quando digo hi
[01/09/2020 18:42:24] [Error - Npc interface]
[01/09/2020 18:42:24] data/npc/scripts/gengo.lua:onCreatureSay
[01/09/2020 18:42:24] Description:
[01/09/2020 18:42:24] data/lib/012-table.lua:16: attempt to call field 'find' (a nil value)
[01/09/2020 18:42:24] stack traceback:
[01/09/2020 18:42:24] data/lib/012-table.lua:16: in function 'serialize'
[01/09/2020 18:42:24] data/lib/npcdialog_lib.lua:11: in function 'doSendDialogNpc'
[01/09/2020 18:42:24] data/npc/scripts/gengo.lua:11: in function 'callback'
[01/09/2020 18:42:24] data/npc/lib/npcsystem/npchandler.lua:339: in function 'greet'
[01/09/2020 18:42:24] data/npc/lib/npcsystem/npchandler.lua:512: in function 'onGreet'
[01/09/2020 18:42:24] data/npc/lib/npcsystem/modules.lua:222: in function 'callback'
[01/09/2020 18:42:24] data/npc/lib/npcsystem/keywordhandler.lua:40: in function 'processMessage'
[01/09/2020 18:42:24] data/npc/lib/npcsystem/keywordhandler.lua:168: in function 'processNodeMessage'
[01/09/2020 18:42:24] data/npc/lib/npcsystem/keywordhandler.lua:122: in function 'processMessage'
[01/09/2020 18:42:24] data/npc/lib/npcsystem/npchandler.lua:388: in function 'onCreatureSay'
[01/09/2020 18:42:24] data/npc/scripts/gengo.lua:8: in function <data/npc/scripts/gengo.lua:8>
Adicione o seguinte trecho na lib do seu servidor, pode ser no mesmo arquivo que você colocou o table.serialize
table.find = function (table, value) for i, v in pairs(table) do if(v == value) then return i end end return nil end
33 minutos atrás, Gengo disse:
table.serialize = function(x, recur)
local t = type(x)
recur = recur or {}
if t == nil then
return "nil"
elseif t == "string" then
return string.format("%q", x)
elseif t == "number" then
return tostring(x)
elseif t == "boolean" then
return t and "true" or "false"
elseif getmetatable(x) then
error("Can not serialize a table that has a metatable associated with it.")
elseif t == "table" then
if(table.find(recur, x)) then
error("Can not serialize recursive tables.")
end
table.insert(recur, x)
local s = "{"
for k, v in pairs(x) do
s = s .. "[" .. table.serialize(k, recur) .. "]"
s = s .. " = " .. table.serialize(v, recur) .. ","
end
s = s .. "}"
return s
else
error("Can not serialize value of type '" .. t .. "'.")
end
end
table.find = function (table, value)
for i, v in pairs(table) do
if(v == value) then
return i
end
end
return nil
end
Agora, raulcdj disse:table.serialize = function(x, recur)
local t = type(x)
recur = recur or {}if t == nil then
return "nil"
elseif t == "string" then
return string.format("%q", x)
elseif t == "number" then
return tostring(x)
elseif t == "boolean" then
return t and "true" or "false"
elseif getmetatable(x) then
error("Can not serialize a table that has a metatable associated with it.")
elseif t == "table" then
if(table.find(recur, x)) then
error("Can not serialize recursive tables.")
end
table.insert(recur, x)local s = "{"
for k, v in pairs(x) do
s = s .. "[" .. table.serialize(k, recur) .. "]"
s = s .. " = " .. table.serialize(v, recur) .. ","
end
s = s .. "}"
return s
else
error("Can not serialize value of type '" .. t .. "'.")
end
end
table.find = function (table, value)
for i, v in pairs(table) do
if(v == value) then
return i
end
end
return nil
end
nao tenho table.serialize tenho so o 012-table e o mesmo arquivo ou tenho que cria um table.serialize
55 minutos atrás, Gengo disse:
[01/09/2020 20:23:23] [Error - Npc interface]
[01/09/2020 20:23:23] data/npc/scripts/gengo.lua:onCreatureSay
[01/09/2020 20:23:23] Description:
[01/09/2020 20:23:23] data/lib/npcdialog_lib.lua:11: attempt to call global 'doSendPlayerExtendedOpcode' (a nil value)
[01/09/2020 20:23:23] stack traceback:
[01/09/2020 20:23:23] data/lib/npcdialog_lib.lua:11: in function 'doSendDialogNpc'
[01/09/2020 20:23:23] data/npc/scripts/gengo.lua:11: in function 'callback'
[01/09/2020 20:23:23] data/npc/lib/npcsystem/npchandler.lua:339: in function 'greet'
[01/09/2020 20:23:23] data/npc/lib/npcsystem/npchandler.lua:512: in function 'onGreet'
[01/09/2020 20:23:23] data/npc/lib/npcsystem/modules.lua:222: in function 'callback'
[01/09/2020 20:23:23] data/npc/lib/npcsystem/keywordhandler.lua:40: in function 'processMessage'
[01/09/2020 20:23:23] data/npc/lib/npcsystem/keywordhandler.lua:168: in function 'processNodeMessage'
[01/09/2020 20:23:23] data/npc/lib/npcsystem/keywordhandler.lua:122: in function 'processMessage'
[01/09/2020 20:23:23] data/npc/lib/npcsystem/npchandler.lua:388: in function 'onCreatureSay'
[01/09/2020 20:23:23] data/npc/scripts/gengo.lua:8: in function <data/npc/scripts/gengo.lua:8>
info
Grupo: Cavaleiro
Registrado: 10/03/13
Posts: 177
Reputação: +202
Gênero: Masculino
Char no Tibia: stor akia

Em 01/09/2020 em 20:03, raulcdj disse:table.serialize = function(x, recur)
local t = type(x)
recur = recur or {}if t == nil then
return "nil"
elseif t == "string" then
return string.format("%q", x)
elseif t == "number" then
return tostring(x)
elseif t == "boolean" then
return t and "true" or "false"
elseif getmetatable(x) then
error("Can not serialize a table that has a metatable associated with it.")
elseif t == "table" then
if(table.find(recur, x)) then
error("Can not serialize recursive tables.")
end
table.insert(recur, x)local s = "{"
for k, v in pairs(x) do
s = s .. "[" .. table.serialize(k, recur) .. "]"
s = s .. " = " .. table.serialize(v, recur) .. ","
end
s = s .. "}"
return s
else
error("Can not serialize value of type '" .. t .. "'.")
end
end
table.find = function (table, value)
for i, v in pairs(table) do
if(v == value) then
return i
end
end
return nil
endnao tenho table.serialize tenho so o 012-table e o mesmo arquivo ou tenho que cria um table.serialize
[01/09/2020 20:23:23] [Error - Npc interface]
[01/09/2020 20:23:23] data/npc/scripts/gengo.lua:onCreatureSay
[01/09/2020 20:23:23] Description:
[01/09/2020 20:23:23] data/lib/npcdialog_lib.lua:11: attempt to call global 'doSendPlayerExtendedOpcode' (a nil value)
[01/09/2020 20:23:23] stack traceback:
[01/09/2020 20:23:23] data/lib/npcdialog_lib.lua:11: in function 'doSendDialogNpc'
[01/09/2020 20:23:23] data/npc/scripts/gengo.lua:11: in function 'callback'
[01/09/2020 20:23:23] data/npc/lib/npcsystem/npchandler.lua:339: in function 'greet'
[01/09/2020 20:23:23] data/npc/lib/npcsystem/npchandler.lua:512: in function 'onGreet'
[01/09/2020 20:23:23] data/npc/lib/npcsystem/modules.lua:222: in function 'callback'
[01/09/2020 20:23:23] data/npc/lib/npcsystem/keywordhandler.lua:40: in function 'processMessage'
[01/09/2020 20:23:23] data/npc/lib/npcsystem/keywordhandler.lua:168: in function 'processNodeMessage'
[01/09/2020 20:23:23] data/npc/lib/npcsystem/keywordhandler.lua:122: in function 'processMessage'
[01/09/2020 20:23:23] data/npc/lib/npcsystem/npchandler.lua:388: in function 'onCreatureSay'
[01/09/2020 20:23:23] data/npc/scripts/gengo.lua:8: in function <data/npc/scripts/gengo.lua:8>
Certo, você nao tem, então siga o tutorial e adicione, e reveja com cuidado, verifique no seu servidor você não tem a função doSendPlayerExtendedOpcode, recomendo instalar, esse topico não ensino instalar opcodes.




info
Grupo: Campones
Registrado: 27/08/18
Posts: 90
Reputação: +51
Gênero: Masculino
Manda pm para mim que eu vou ajudar você.