Here is the error i am having... Below the error is the code i am trying to use.
What i am trying to do is use a "Token" to buy an item from the npc, everything works i just get an error , I'm not 100% sure why i am getting this error.... Can anyone help?
Server version is TFS 1.2 as seen in the title of this post. (Client is 10.98 if it even matters.)
(["item 1] = {buyId = 2457, costId = 6527, costCount = 10}, the error with ["item 1"] is not it.. i messed it up while editing the post.)
EDIT!
Ok, so i found the problems... First problem was getItemInfo was not working with 1.2 for some reason.... so i changed it to getItemName, now it works.
Second issue was with (npcTable[string.lower(msg)].costId).plural the .plural was not working at all, so i fixed this by simply deleting it, Now the script works good.. no more errors.
Lua Script Error: [Npc interface]
data/npc/scripts/itemseller.luanCreatureSay
data/npc/scripts/itemseller.lua:47: attempt to call global 'getItemInfo' (a nil
value)
stack traceback:
[C]: in function 'getItemInfo'
data/npc/scripts/itemseller.lua:47: in function 'callback'
data/npc/lib/npcsystem/npchandler.lua:411: in function 'onCreatureSay'
data/npc/scripts/itemseller.lua:
21: in function <data/npc/scripts/itemseller.lua:21>
data/npc/scripts/itemseller.luanCreatureSay
data/npc/scripts/itemseller.lua:47: attempt to call global 'getItemInfo' (a nil
value)
stack traceback:
[C]: in function 'getItemInfo'
data/npc/scripts/itemseller.lua:47: in function 'callback'
data/npc/lib/npcsystem/npchandler.lua:411: in function 'onCreatureSay'
data/npc/scripts/itemseller.lua:
21: in function <data/npc/scripts/itemseller.lua:21>
Lua:
local npcTable = {
-- ["item name (what player will say)"] = {buyId = id of the item they are buying, costId = id of the currency used to buy, costCount = how many of the currency required to buy},
["item 1] = {buyId = 2457, costId = 6527, costCount = 10},
["item 2"] = {buyId = 2463, costId = 6527, costCount = 10},
["item 3"] = {buyId = 2647, costId = 6527, costCount = 10},
["item 4"] = {buyId = 2643, costId = 6527, costCount = 10},
["item 5"] = {buyId = 2512, costId = 6527, costCount = 10},
["item 6"] = {buyId = 2383, costId = 6527, costCount = 8},
["item 7"] = {buyId = 2184, costId = 6527, costCount = 8},
["item 8"] = {buyId = 2455, costId = 6527, costCount = 8},
}
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local talkState = {}
local talkChoice = {}
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 (msgcontains(msg, "hello") or msgcontains(msg, "hi")) and (not npcHandler:isFocused(cid)) then
selfSay("Hello, in exchange for tokens I can craft helmet, armor, legs, boots, shield, sword, crossbow, or wand. Just tell me the tier and item you would like me to craft. Example: {item 1}", cid)
talkState[talkUser] = 0
talkChoice[talkUser] = 0
npcHandler:addFocus(cid)
elseif(not npcHandler:isFocused(cid)) then
return false
end
if(msgcontains(msg, 'bye')) then
talkState[talkUser] = 0
talkChoice[talkUser] = 0
npcHandler:say("Goodbye, ".. getCreatureName(cid) ..".", cid)
npcHandler:releaseFocus(cid)
elseif(npcTable[string.lower(msg)]) then
selfSay("Are you sure you would like me to craft ".. string.lower(msg) .." for you? It will cost you ".. npcTable[string.lower(msg)].costCount .." ".. getItemInfo(npcTable[string.lower(msg)].costId).plural ..".", cid)
talkState[talkUser] = 1
talkChoice[talkUser] = string.lower(msg)
elseif(msgcontains(msg, 'yes') and talkState[talkUser] == 1) then
if(npcTable[talkChoice[talkUser]]) then
if(doPlayerRemoveItem(cid, npcTable[talkChoice[talkUser]].costId, npcTable[talkChoice[talkUser]].costCount)) then
doPlayerAddItem(cid, npcTable[talkChoice[talkUser]].buyId, 1)
selfSay("Here you go. Try not to break it!", cid)
talkState[talkUser] = 0
talkChoice[talkUser] = 0
else
selfSay("Sorry, you don't have enough tokens.", cid)
talkState[talkUser] = 0
talkChoice[talkUser] = 0
end
end
elseif(msgcontains(msg, 'no') and talkState[talkUser] == 1) then
selfSay("Good, I didn't want to craft anything for you anyway!", cid)
talkState[talkUser] = 0
talkChoice[talkUser] = 0
end
return true
end
npcHandler:setMessage(MESSAGE_WALKAWAY, "Goodbye.")
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
What i am trying to do is use a "Token" to buy an item from the npc, everything works i just get an error , I'm not 100% sure why i am getting this error.... Can anyone help?
Server version is TFS 1.2 as seen in the title of this post. (Client is 10.98 if it even matters.)
(["item 1] = {buyId = 2457, costId = 6527, costCount = 10}, the error with ["item 1"] is not it.. i messed it up while editing the post.)
EDIT!
Ok, so i found the problems... First problem was getItemInfo was not working with 1.2 for some reason.... so i changed it to getItemName, now it works.
Second issue was with (npcTable[string.lower(msg)].costId).plural the .plural was not working at all, so i fixed this by simply deleting it, Now the script works good.. no more errors.
Last edited: