attempt to index global storage a nil value and more

Lopaskurwa

Banned User
Joined
Oct 6, 2017
Messages
694
Reaction score
32
So
i made i thread about craft system but since i marked as a best answer already i wont get working code even if code doesnt work.
35980
Have last question related with this system what if i want to add ability to craft same item but with different item requirement.
Lua:
    ['demon sword'] = {{'big sword', 1}, {'sword card', 1}, {'demon card', 3}},
    ['demon sword'] = {{'small sword', 1}, {'sword card', 2}, {'demon card', 4}},
As you can see it has same item name so what will happen? How to make it work properly ?

Lua:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)

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 config = { -- KEEP ALL LOWER CASE
    ['mage helmet'] = {{'addon doll', 1}, {'leaf', 1}, {'yalahari mask', 1}, {'outfiter', 1}, {'rs remover', 1}},
    ['knight donate uh'] = {{'addon doll', 1}, {'warlord sword', 1}, {'demon helmet', 1}, {'outfiter', 1}, {'rs remover', 1}},
    ['paladin donate uh/mr'] = {{{'addon doll', 1}, {'arbalest', 1}, {'demon helmet', 1}, {'outfiter', 1}, {'rs remover', 1}}},
}

craft_storage = craft_storage or {}

function Player:checkCraftItems(table)
    for _, item in ipairs(table) do
        if self:getItemCount(ItemType(item[1]):getId()) < item[2] then
            return false
        end
    end
    return true
end

function Player:removeCraftItems(table)
    for _, item in ipairs(table) do
        self:removeItem(ItemType(item[1]):getId(), item[2])
    end
end

function creatureSayCallback(cid, type, msg)
    if not npcHandler:isFocused(cid) then
        return false
    end

    local player = Player(cid)
    local msg = msg:lower()
    if npcHandler.topic[cid] < 1 then
        local craft_items = config[msg]
        if craft_items then
            local string = "To craft a " .. msg .. " you will need:"
            for key, item in pairs(craft_items) do
                local type = ItemType(item[1])
                if not type or type:getId() < 1 then print("Type does not exist with name " .. item[1]) return true end

                local article = item[2] == 1 and type:getArticle() or item[2]
                local name = item[2] == 1 and item[1] or type:getPluralName()
                if not next(craft_items, key) then
                    string = string .. " and " .. article .. " " .. name .. "."
                else
                    string = string .. " " .. article .. " " .. name .. ","
                end
            end
            npcHandler:say(string .. " Do you have them?", cid)
            npcHandler.topic[cid] = 1
            craft_storage[cid] = msg
        end
    elseif npcHandler.topic[cid] == 1 then
        local craft_items = config[craft_storage[cid]]
        if craft_items and msgcontains(msg, "yes") then
            local type = ItemType(storage[cid])
            if not type or type:getId() < 1 then print("Type does not exist with name " .. storage[cid]) return true end
            if player:checkCraftItems(craft_items) then
                player:removeCraftItems(craft_items)
                player:addItem(type:getId(), 1)
                npcHandler:say('Thank you very much! Come back anytime you want!!', cid)
            else
                npcHandler:say('You do not have the required items.', cid)
            end
        else
            npcHandler:say('Do not waste my time.', cid)
        end
        npcHandler.topic[cid] = 0
        craft_storage[cid] = nil
    end
    return true
end

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

Xikini

I whore myself out for likes
Premium User
Joined
Nov 17, 2010
Messages
4,090
Reaction score
2,153
There's no good way to do this, since there's no way for the system to differentiate the two from each other.
So, either you need to combine, and show both possible combination methods, or you need to iterate through your table and again, show both combination methods.

Or just rename it something like..
"demon sword"
"demon sword alternative method"
 
OP
Lopaskurwa

Lopaskurwa

Banned User
Joined
Oct 6, 2017
Messages
694
Reaction score
32
There's no good way to do this, since there's no way for the system to differentiate the two from each other.
So, either you need to combine, and show both possible combination methods, or you need to iterate through your table and again, show both combination methods.

Or just rename it something like..
"demon sword"
"demon sword alternative method"
So how to combine them and show those two possible combinations?
 
Top