Jump to content

Recommended Posts

Hello :joyous: , I want a creature to -like chester- have an inventory that's made accesible to all players but with only one slot.

 

Here's the code I have :

inst:AddComponent("container")inst.components.container:WidgetSetup("chester")

It works just fine but it of course gives me 9 slots.

 

How to make it a one slot container?  :joyous:

 

Ok, so to prove you guys I'm not asking you to completely do "this thing I want", here's what I got after further investigation : 

 

-I'm now aware that I need to make a new anim file, beginning for some reason with "ui" (example: "ui_rabbitchest_1x1"

-I need to make a new WidgetSetup like "chester" or apply a new sort of container in a smiliar way

-Here's some code I got from the Large Chest mod :

local function makeChest()    local container =    {        widget =        {            slotpos = {},            animbank = "ui_largechest_5x5",            animbuild = "ui_largechest_5x5",            pos = GLOBAL.Vector3(0, 200, 0),            side_align_tip = 160,        },        type = "chest",    }    for y = 3, -1, -1 do        for x = -1, 3 do            table.insert(container.widget.slotpos, GLOBAL.Vector3(80 * x - 80 * 2 + 80, 80 * y - 80 * 2 + 80, 0))        end    end    return containerend
I don't really understand how to setup a "pos", a "side_align_tip" (actually, I'm not even that sure of what this really is) or how to properly change an "animbank" (I do know how to change the "animbuild" name)
 
I also don't have a clue what this is : 
    for y = 3, -1, -1 do        for x = -1, 3 do            table.insert(container.widget.slotpos, GLOBAL.Vector3(80 * x - 80 * 2 + 80, 80 * y - 80 * 2 + 80, 0))        end    end

And this is an example of how to actually make the WidgetSetup, right?

AddPrefabPostInit("world_network", function(inst)    if containers.widgetsetup ~= containers_widgetsetup_custom then        OVERRIDE_WIDGETSETUP = true        local containers_widgetsetup_base2 = containers.widgetsetup        function containers.widgetsetup(container, prefab)            containers_widgetsetup_base2(container, prefab)            if container.type == "largechest" then                container.type = "chest"            end        end    end    if containers.MAXITEMSLOTS < MAXITEMSLOTS then        containers.MAXITEMSLOTS = MAXITEMSLOTS    endend)

So here's what I know, now what to do with it to get a 1x1 container for my creature? :)

 

Thanks in advance

 

 

@Thibooms,

i have a creature with one slot in my mod too, here's the related code:

in your prefab above the main functions:

local containers = require("containers")local overlordslot ={    widget =    {        slotpos = {	Vector3(0,64+32+8+4,0), 					--Vector3(0,32+4,0),					--Vector3(0,-(32+4),0), 					--Vector3(0,-(64+32+8+4),0)					},        animbank = "ui_cookpot_1x4",        animbuild = "ui_cookpot_1x4",        pos = Vector3(200,0,0)    },    --issidewidget = true,    type = "chest",}local widgetsetup_old = containers.widgetsetupfunction containers.widgetsetup(container, prefab, data, ...) if container.inst.prefab == "overlord" or prefab == "overlord" then        for k, v in pairs(overlordslot) do            container[k] = v        end        container:SetNumSlots(container.widget.slotpos ~= nil and #container.widget.slotpos or 0)        return    end      return widgetsetup_old(container, prefab, data, ...)end
in the mainfunction of the prefab near the other componentstuff:

	inst:AddComponent("container")	inst.components.container:WidgetSetup("overlord", overlordslot)
and u probably want to add this in it's Stategraph somewhere in the deathstate:

inst.components.container:Close() inst.components.container:DropEverything()
ofc replace overlord with your prefabname. Edited by Seiai

I also don't have a clue what this is :

for y = 3, -1, -1 do             for x = -1, 3 do                  table.insert(container.widget.slotpos, GLOBAL.Vector3(80 * x - 80 * 2 + 80, 80 * y - 80 * 2 + 80, 0))             end     end
this is pretty much what i do in

slotpos = {    Vector3(0,64+32+8+4,0),                     --Vector3(0,32+4,0),                    --Vector3(0,-(32+4),0),                     --Vector3(0,-(64+32+8+4),0)                    }
but instead of having to list all the slots and their positions yourself, u generate them with a loop and some math^^ Edited by Seiai

I don't really understand how to setup a "pos", a "side_align_tip" (actually, I'm not even that sure of what this really is) or how to properly change an "animbank" (I do know how to change the "animbuild" name)

pos and side_align_tip are just to position the widget and the slots in relation to the widget.

side_align_tip is i guess the position of backpacks on the screen, so not really needed for containers in the gameworld.

animbank and animbuild are related to the custom animationfile u could make, but since u dont seem to have done anything related yet, u will probably be satisfied with my solution anyway :razz:

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
×
  • Create New...