• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

Problem with npc missions

jareczekjsp

Member
Joined
Jan 30, 2023
Messages
185
Reaction score
9
GitHub
Jarek123
Hello guys I move my server from tfs 0.4 to 1.5 by nekiro and I have little problem can somebody help me ?please


error
Lua:
Lua Script Error: [Npc interface]
data/npc/scripts/island.lua:onCreatureSay
data/npc/scripts/island.lua:82: attempt to call global 'getItemInfo' (a nil value)
stack traceback:
        [C]: in function 'getItemInfo'
        data/npc/scripts/island.lua:82: in function 'getItemsFromTable'
        data/npc/scripts/island.lua:181: in function 'callback'
        data/npc/lib/npcsystem/npchandler.lua:415: in function 'onCreatureSay'
        data/npc/scripts/island.lua:10: in function <data/npc/scripts/island.lua:10>
 
Solution
Okay, you can either use getItemDescriptions(itemId) that'd output all these information or you can call these separatelly like:
Lua:
local itemType = ItemType(itemId)

local name = itemType:getName()
local pluralName = itemType:getPluralName()
local article = itemType:getArticle()

So getItemsFromTable could look somehow like:
Lua:
local function getItemsFromTable(items)
    local names = {}
    for _, item in ipairs(items) do
        local itemType = ItemType(item.id)
        local count = item.count
        local name = count > 1 and itemType:getPluralName() or itemType:getName()

        local text = (count > 1 and count or itemType:getArticle()) .. " " .. name
        table.insert(names, text)
    end

    return...
There's simply no such function called getItemInfo in TFS 1.x
As it used to return bunch of information about item you need to replace it with some specific one.
But without the island.lua script (line 82 and below) I'm unable to tell more.
 
Lua:
-- Collecting items missions by Limos
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

local missions = {
   [1] = {items = {
     {id = 6527, count = 200},
     {id = 9980, count = 100},
     {id = 2349, count = 100},
     {id = 10558, count = 200},
     {id = 2328, count = 100}
     },
     message = "Great, I need alot of items, but you can start with",
     level = 2000, -- minimum level voor this mission
     rewarditem = {id = 2160, count = 100},
     rewardexp = 500000
   },
   [2] = {items = {
     {id = 6527, count = 200},
     {id = 9980, count = 100},
     {id = 2349, count = 100},
     {id = 10558, count = 200},
     {id = 2328, count = 100}
     },
     message = "Thank you, the next items are",
     level = 2000,
     rewarditem = {id = 2157, count = 5},
     rewardexp = 1500000
   },
   [3] = {items = {
     {id = 6527, count = 200},
     {id = 9980, count = 100},
     {id = 2349, count = 100},
     {id = 10558, count = 200},
     {id = 2328, count = 100}
     },
     message = "Awesome, now get",
     level = 2000,
     rewarditem = {id = 5957, count = 2},
     rewardexp = 4000000
   },
   [4] = {items = {
     {id = 6527, count = 200},
     {id = 9980, count = 100},
     {id = 2349, count = 100},
     {id = 10558, count = 200},
     {id = 2328, count = 50}
     },
     message = "Thanks, now I need",
     level = 2000,
     rewarditem = {id = 6527, count = 100},
     rewardexp = 30000000
   },
   [5] = {items = {
     {id = 6527, count = 200},
     {id = 9980, count = 50},
     {id = 2328, count = 100},
     {id = 2157, count = 100},
     {id = 2349, count = 25},
     {id = 2157, count = 100}
     },
     message = "Good, only a few items left,",
     level = 2000,
     rewarditem = {id = 2091, count = 1},
     rewardexp = 80000000
   }
}

local storage = 45559

local function getItemsFromTable(itemtable)
     local text = ""
     for v = 1, #itemtable do
         count, info = itemtable[v].count, getItemInfo(itemtable[v].id)
         local ret = ", "
         if v == 1 then
             ret = ""
         elseif v == #itemtable then
             ret = " and "
         end
         text = text .. ret
         text = text .. (count > 1 and count or info.article).." "..(count > 1 and info.plural or info.name)
     end
     return text
end

function creatureSayCallback(cid, type, msg)

     local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid

     local xstorage = getPlayerStorageValue(cid, storage)
     local x = missions[xstorage]

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

     if msgcontains(msg, 'mission') then
         if xstorage == -1 then
             selfSay("I am a scientist and I am currently doing some research, do you think you can help me out?", cid)
             talkState[talkUser] = 1
         elseif x then
             if getPlayerLevel(cid) >= x.level then
                 selfSay("Did you get the {items} I asked you?", cid)
                 talkState[talkUser] = 1
             else
                 selfSay("Misja, którą ci dałem, dotyczy poziomu "..x.level..", wróć później.", cid)
             koniec
         w przeciwnym razie
             selfSay("Jeszcze raz dziękuję za wszystkie Twoje przedmioty, bardzo mi pomogły.", cid)
             npcHandler:releaseFocus(cid)
         koniec
     elseif msgcontains(msg, 'yes') i talkState[talkUser] == 1 wtedy
         jeśli xstorage == -1 to
             setPlayerStorageValue(cid, pamięć, 1)
             lokalny x = misje [getPlayerStorageValue (cid, pamięć)]
             selfSay(x.message.." "..getItemsFromTable(x.items)..", cid)
         inaczej jeśli x wtedy
             kwota lokalna = 0
             dla i = 1, #x.items tak
                 jeśli getPlayerItemCount(cid, x.items[i].id) >= x.items[i].count to
                     kwota = ilość + 1
                 koniec
             koniec
             jeśli ilość == #x.items to
                 dla i = 1, #x.items tak
                     doPlayerRemoveItem(cid, x.items[i].id, x.items[i].count)
                 koniec
                 jeśli x.rewarditem to
                     liczba lokalna, info = x.rewarditem.count, getItemInfo(x.rewarditem.id)
                     doPlayerAddItem(cid, x.rewarditem.id, liczba)
                     doPlayerSendTextMessage(cid, MESSAGE_EVENT_DEFAULT, "Otrzymałeś "..(liczba > 1 i liczba lub informacja.artykuł).." "..(liczba > 1 i info.plural lub info.name).."")
                 koniec
                 jeśli x.rewardexp to
                     doPlayerAddExp(cid, x.rewardexp)
                     doPlayerSendTextMessage(cid, MESSAGE_EVENT_DEFAULT, "Otrzymałeś doświadczenie "..x.rewardexp.."")
                 koniec
                 setPlayerStorageValue(cid, pamięć, xstorage + 1)
                 lokalny x = misje [getPlayerStorageValue (cid, pamięć)]
                 jeśli x to
                     selfSay(x.message.." "..getItemsFromTable(x.items)..", cid)
                 w przeciwnym razie
                     selfSay("Wielkie dzięki! Mogę już dokończyć poszukiwania.", cid)
                 koniec
             w przeciwnym razie
                 lokalny n = 0
                 dla i = 1, #x.items tak
                     jeśli getPlayerItemCount(cid, x.items[i].id) < x.items[i].count to
                         n = n + 1
                     koniec
                 koniec
                 tekst lokalny = „”
                 lokalny c = 0
                 dla v = 1, #x.items tak
                     count, info = x.items[v].count - getPlayerItemCount(cid, x.items[v].id), getItemInfo(x.items[v].id)
                     jeśli getPlayerItemCount(cid, x.items[v].id) < x.items[v].count to
                         do = do + 1
                         lokalny ret = ", "
                         jeśli c == 1 to
                             ret = ""
                         elseif c == n to
                             ret = " i "
                         koniec
                         tekst = tekst .. ret
                         tekst = tekst .. (liczba > 1 i liczba lub informacja.artykuł).." "..(liczba > 1 i informacja.plural lub informacja.nazwa)
                     koniec
                 koniec
                 selfSay("Nie masz wszystkich elementów, musisz jeszcze zdobyć "..tekst...".", cid)
             koniec
         koniec
         talkState[talkUser] = 0
     elseif msgcontains(msg, 'elementy') i x następnie
         selfSay("Elementy, o które Cię zapytałem to "..getItemsFromTable(x.items)..", cid)
     elseif msgcontains(msg, 'no') i talkState[talkUser] == 1 wtedy
         selfSay("No cóż, chyba nie w takim razie.", cid)
     koniec
     zwróć prawdę
koniec

npcHandler:setMessage(MESSAGE_FAREWELL, „Cześć!”)
npcHandler:setMessage(MESSAGE_WALKAWAY, „Cześć? Chyba…”)
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, stworzenieSayCallback)
npcHandler:addModule(FocusModule:new())
 
Okay, you can either use getItemDescriptions(itemId) that'd output all these information or you can call these separatelly like:
Lua:
local itemType = ItemType(itemId)

local name = itemType:getName()
local pluralName = itemType:getPluralName()
local article = itemType:getArticle()

So getItemsFromTable could look somehow like:
Lua:
local function getItemsFromTable(items)
    local names = {}
    for _, item in ipairs(items) do
        local itemType = ItemType(item.id)
        local count = item.count
        local name = count > 1 and itemType:getPluralName() or itemType:getName()

        local text = (count > 1 and count or itemType:getArticle()) .. " " .. name
        table.insert(names, text)
    end

    return table.concat(names, " and ")
end
 
Last edited:
Solution
Back
Top