gnubeardo Posted December 24, 2014 Share Posted December 24, 2014 Hello, I've been working on porting storm cellar and I think I'm quite close. I can build the storm cellar, and I can open it. The slots show (5x16) grid. The only problem is that I can only fill up the first 9 spaces. I think the reason is obvious, because I'm no longer setting the numslots. When I try to set numslots it complains "Cannot change read only property". I looked at the freezer mod, where in vanilla it has 12 slots but in DST it only has 9; in the mod code the stuff where it sets the size of the freezer is commented out. How do we set the number of slots of a container? scripts/prefabs/cellar.luarequire "prefabutil" local assets={Asset("ANIM", "anim/cellar.zip"),} local function onopen(inst) inst.SoundEmitter:PlaySound("dontstarve/wilson/chest_open") inst.AnimState:PlayAnimation("open")end local function onclose(inst) inst.AnimState:PlayAnimation("closed")inst.SoundEmitter:PlaySound("dontstarve/wilson/chest_close") end local function onhammered(inst, worker)inst.components.lootdropper:DropLoot()inst.components.container:DropEverything()--SpawnPrefab("collapse_small").Transform:SetPosition(inst.Transform:GetWorldPosition())inst.SoundEmitter:PlaySound("dontstarve/common/destroy_metal")inst:Remove()end local function onhit(inst, worker)inst.AnimState:PlayAnimation("hit")inst.components.container:DropEverything()inst.AnimState:PushAnimation("closed", false)inst.components.container:Close() end local function onbuilt(inst)inst.AnimState:PlayAnimation("place")inst.AnimState:PushAnimation("closed") end local slotpos = {}for y = 4, 0, -1 dofor x = 0, 15 dotable.insert(slotpos, Vector3( 80 * x -346 * 2 + 90, 80 * y - 100 * 2 + 40, 0))endend local function fn(Sim)local inst = CreateEntity()inst:AddTag("structure") inst.entity:AddTransform()inst.entity:AddAnimState()inst.entity:AddSoundEmitter()inst.entity:AddNetwork() -- MakeObstaclePhysics(inst, 1.5) local minimap = inst.entity:AddMiniMapEntity()minimap:SetIcon( "cellar.tex" ) MakeSnowCoveredPristine(inst) if not TheWorld.ismastersim then return inst end inst.entity:SetPristine() inst.AnimState:SetBank("cellar") inst.AnimState:SetBuild("cellar") inst.AnimState:PlayAnimation("closed", true) inst:AddComponent("inspectable") inst:AddComponent("container")inst.components.container:WidgetSetup("treasurechest") -- inst.components.container:SetNumSlots(#slotpos) inst.components.container.onopenfn = onopen inst.components.container.onclosefn = onclose-- inst.components.container.widget.bgimage = "images/inventoryimages/ui_chest_5x16.tex"-- inst.components.container.widget.bgatlas = "images/inventoryimages/ui_chest_5x16.xml" inst.components.container.widget.slotpos = slotpos-- inst.components.container.numslots = #slotpos inst.components.container.widget.animbank = "images/inventoryimages/ui_chest_5x16" inst.components.container.widget.animbuild = "images/inventoryimages/ui_chest_5x16" inst.components.container.widget.pos = Vector3(-200,250,0) inst.components.container.side_align_tip = 160 inst:AddComponent("lootdropper") inst:AddComponent("workable") inst.components.workable:SetWorkAction(ACTIONS.HAMMER) inst.components.workable:SetWorkLeft(1) inst.components.workable:SetOnFinishCallback(onhammered) inst.components.workable:SetOnWorkCallback(onhit) return instend return Prefab( "common/cellar", fn, assets),MakePlacer("common/cellar_placer", "cellar", "cellar", "closed") Also here is my modmain.lualocal Spot = GetModConfigData("Spot") PrefabFiles = {"cellar",} Assets = {Asset( "IMAGE", "minimap/cellar.tex" ),Asset( "ATLAS", "minimap/cellar.xml" ),-- Asset("ATLAS", "images/inventoryimages/ui_chest_3x4.xml"),Asset("ATLAS", "images/inventoryimages/cellar.xml"),} AddMinimapAtlas("minimap/cellar.xml") STRINGS = GLOBAL.STRINGSRECIPETABS = GLOBAL.RECIPETABSRecipe = GLOBAL.RecipeIngredient = GLOBAL.IngredientTECH = GLOBAL.TECH GLOBAL.STRINGS.NAMES.CELLAR = "Storm Cellar" STRINGS.RECIPE_DESC.CELLAR = "Just like my basement at home,full of junk" GLOBAL.STRINGS.CHARACTERS.GENERIC.DESCRIBE.CELLAR = "I like it" local cellar = GLOBAL.Recipe("cellar",{Ingredient("cutstone", 20),Ingredient("goldenshovel", 1),Ingredient("turf_woodfloor", 20)},RECIPETABS.TOWN, TECH.NONE, "cellar_placer" ) cellar.atlas = "images/inventoryimages/cellar.xml" local containers = GLOBAL.require("containers")local oldwidgetsetup = containers.widgetsetup containers.widgetsetup = function(container, prefab)if not prefab and container.inst.prefab == "cellar" thenprefab = "treasurechest"end oldwidgetsetup(container, prefab)end Vector3 = GLOBAL.Vector3 local function CellarPost(inst) if GetModConfigData("Spot")==("Default") then inst.components.container.widgetpos = Vector3(-210,250,0)else if GetModConfigData("Spot")==("JustDownSome") then inst.components.container.widgetpos = Vector3(-200,200,0) end endendAddPrefabPostInit("cellar", CellarPost) This is where I've gotten so far, image is also attachedimgur link: http://i.imgur.com/7bFyiJb.png Thanks! Link to comment Share on other sites More sharing options...
gnubeardo Posted December 24, 2014 Author Share Posted December 24, 2014 Sorry the formatting is broken, I tried to put it in code tags, I guess I should have used spoiler tags. I can't figure out how to edit my original post. Link to comment Share on other sites More sharing options...
rezecib Posted December 24, 2014 Share Posted December 24, 2014 (edited) containers.widgetsetup = function(container, prefab)if not prefab and container.inst.prefab == "cellar" thenprefab = "treasurechest"end oldwidgetsetup(container, prefab)end This would be why-- it's only actually setting up the slots for the first 9 because that's what a treasurechest has. You'll have to do more extensive modification of containers.lua, although if I remember correctly from the last time I looked at it, further modification is pretty messy right now. And you can't edit your post until you have 5 posts in. Perhaps Peter will fix it for you meanwhile Edited December 24, 2014 by rezecib Link to comment Share on other sites More sharing options...
gnubeardo Posted December 24, 2014 Author Share Posted December 24, 2014 Thanks a lot for your timely reply. That's what I was thinking, that I have to edit the containers.lua. But I'm a little confused, how can I edit that file and distribute it in a mod? Isn't that file a part of the game and can't be distributed with a mod? I'll still try to fix that up so I can use it. Thanks. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now