Jump to content

Modding inventory_classified


Recommended Posts

I am trying to mod one of the function within the inventory_classified. However, it seems that it doesn't run/execute properly. It will run properly if i use the full file replace. The mod that i made is the Extra Equip Slots. I have attached the mod file as well. Could anyone help me resolve this issue?

 

What i ran

AddPrefabPostInit("inventory_classified", function(inst)
    local function GetOverflowContainer(inst)
        local item = inst.GetEquippedItem(inst, GLOBAL.EQUIPSLOTS.BACK)
        return item ~= nil and item.replica.container or nil
    end
    if not IsServer then
        inst.GetOverflowContainer = GetOverflowContainer
    end
end)

[code]

 

Sidenote: 

This part of the code controls the part where client craft/build something when the materials are placed within the backpack. Since this file is a classified file, it only affects the clients.

 

 

 

eqs1.4.zip

Link to comment
Share on other sites

@xVars, I went through the game's files, and found this in inventory_classified.lua:

local function Has(inst, prefab, amount)    local count =        inst._activeitem ~= nil and        inst._activeitem.prefab == prefab and        Count(inst._activeitem) or 0    if inst._itemspreview ~= nil then        for i, v in ipairs(inst._items) do            local item = inst._itemspreview[i]            if item ~= nil and item.prefab == prefab then                count = count + Count(item)            end        end    else        for i, v in ipairs(inst._items) do            local item = v:value()            if item ~= nil and item ~= inst._activeitem and item.prefab == prefab then                count = count + Count(item)            end        end    end    local overflow = GetOverflowContainer(inst)    if overflow ~= nil then        local overflowhas, overflowcount = overflow:Has(prefab, amount)        count = count + overflowcount    end    return count >= amount, countend

This function is called by the builder replica to check if the player has enough of the ingredients to craft. However, as you can see, the GetOverflowContainer function is called in this function, and for some reason, it's not the one you changed in your modmain that is called. This is why it doesn't check the backpack for ingredients.

 

To fix this, I tried to override this function in the AddPrefabPostInit of inventory_classified, the same way you did with GetOverflowContainer, while making sure the GetOverflowContainer function called is the correct one. And it worked! :-)

 

Though you have to define the Count function yourself, as it is not accessible outside of the prefab's file:

local function Count(item)    return item.replica.stackable ~= nil and item.replica.stackable:StackSize() or 1end
Edited by Jjmarco
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
  • Create New...