Ir para conteúdo

Featured Replies

Postado

Script 

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 playerHaveItems(cid, itemid)
local items = type(itemid) == "table" and itemid or {itemid}
for i = 1, #items do
if getPlayerItemCount(cid, items) <= 0 then
return false
end
end
return true
end

function doPlayerRemoveItems(cid, itemid, count)
local items = type(itemid) == "table" and itemid or {itemid}
for i = 1, #items do
doPlayerRemoveItem(cid, items, count ~= nil and count or 1)
end
return nil
end

function creatureSayCallback(cid, type, msg)

if(not npcHandler:isFocused(cid)) then
return false
end

if msgcontains(msg, "trocar") then
if playerHaveItems(cid, {2134, 2174, 2159}) then
doPlayerRemoveItems(cid, {2134, 2174, 2159}, 300)
doPlayerAddItem(cid, 2090, 1)
else
selfSay("Você Não tem os itens necessarios.")
end
end
return true

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

 

 

Agora vá em Data/Npc/Nomedonpc.xml

 

<?xml version="1.0" encoding="UTF-8"?>
<npc name="Fernando" script="trocaitems.lua" walkinterval="2000" floorchange="0">
<health now="100" max="100"/>
<look type="169" head="114" body="86" legs="114" feet="0" addons="2"/>
<parameters>
<parameter key="message_greet" value="Ola, diga {trocar} para trocar 3 items por 1."/>
</parameters>
</npc>

Ta Dando esse erro

[10/02/2016 12:58:23] [Error - LuaScriptInterface::loadFile] data/npc/scripts/trocaitems.lua:45: 'end' expected (to close 'function' at line 29) near 'endnpcHandler'
[10/02/2016 12:58:23] [Warning - NpcScript::NpcScript] Cannot load script: data/npc/scripts/trocaitems.lua
[10/02/2016 12:58:23] data/npc/scripts/trocaitems.lua:45: 'end' expected (to close 'function' at line 29) near 'endnpcHandler'

  • Respostas 19
  • Visualizações 784
  • Created
  • Última resposta

Top Posters In This Topic

Most Popular Posts

  • Troca isso: endnpcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)   Por isso: end npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)

  • Encontrei o erro na variável da função doplayerremoveitems () playerHaveItems(cid, iremos)   Troca "iremos" por "items"  

Postado
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 playerHaveItems(cid, itemid)
local items = type(itemid) == "table" and itemid or {itemid}
for i = 1, #items do
if getPlayerItemCount(cid, items) <= 0 then
return false
end
end
return true
end
function doPlayerRemoveItems(cid, itemid, count)
local items = type(itemid) == "table" and itemid or {itemid}
for i = 1, #items do
doPlayerRemoveItem(cid, items, count ~= nil and count or 1)
end
return nil
end
function creatureSayCallback(cid, type, msg)
if(not npcHandler:isFocused(cid)) then
return false
end
if msgcontains(msg, "trocar") then
if playerHaveItems(cid, {2134, 2174, 2159}) then
doPlayerRemoveItems(cid, {2134, 2174, 2159}, 300)
doPlayerAddItem(cid, 2090, 1)
else
selfSay("Você Não tem os itens necessarios.")
end
end
end
return true

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

testa ai n é certeza 

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

Postado
  • Autor

[10/02/2016 13:23:47] [Error - LuaScriptInterface::loadFile] data/npc/scripts/trocaitems.lua:40: '<eof>' expected near 'endnpcHandler'
[10/02/2016 13:23:47] [Warning - NpcScript::NpcScript] Cannot load script: data/npc/scripts/trocaitems.lua
[10/02/2016 13:23:47] data/npc/scripts/trocaitems.lua:40: '<eof>' expected near 'endnpcHandler'

Postado
14 minutos atrás, Daniel augusto silva disse:

[10/02/2016 13:23:47] [Error - LuaScriptInterface::loadFile] data/npc/scripts/trocaitems.lua:40: '<eof>' expected near 'endnpcHandler'
[10/02/2016 13:23:47] [Warning - NpcScript::NpcScript] Cannot load script: data/npc/scripts/trocaitems.lua
[10/02/2016 13:23:47] data/npc/scripts/trocaitems.lua:40: '<eof>' expected near 'endnpcHandler'

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 playerHaveItems(cid, itemid)
local items = type(itemid) == "table" and itemid or {itemid}
for i = 1, #items do
if getPlayerItemCount(cid, items) <= 0 then
return false
end
end
return true
end
function doPlayerRemoveItems(cid, itemid, count)
local items = type(itemid) == "table" and itemid or {itemid}
for i = 1, #items do
doPlayerRemoveItem(cid, items, count ~= nil and count or 1)
end
return nil
end
function creatureSayCallback(cid, type, msg)
if(not npcHandler:isFocused(cid)) then
return false
end
if msgcontains(msg, "trocar") then
if playerHaveItems(cid, {2134, 2174, 2159}) then
doPlayerRemoveItems(cid, {2134, 2174, 2159}, 300)
doPlayerAddItem(cid, 2090, 1)
else
selfSay("Você Não tem os itens necessarios.")
end
end
return true
end
endnpcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 

Postado
  • Autor

[10/02/2016 13:56:24] [Error - Npc interface] 
[10/02/2016 13:56:24] data/npc/scripts/trocaitems.lua
[10/02/2016 13:56:24] Description: 
[10/02/2016 13:56:24] data/npc/scripts/trocaitems.lua:39: attempt to index global 'endnpcHandler' (a nil value)
[10/02/2016 13:56:24] [Warning - NpcScript::NpcScript] Cannot load script: data/npc/scripts/trocaitems.lua

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.6k

Informação Importante

Confirmação de Termo