Jump to content

Recommended Posts

I've been working on a mod and have gotten stuck, so if anyone has any insights that could help it'd be greatly appreciated. Essentially what I'd like to create is a structure with the storage/GUI layout capabilities of a crock pot. That means four slots along with a button at the bottom, and each slot can only hold one item.

 

At the moment, I can't even get any sort of GUI to show up when I attempt to open a modded structure marked as a container, and I've tried using a couple of the existing storage mods as a guide but to no luck. Anything I try just ends up crashing at one point or another, and I've given up trying to figure it out on my own/have cleaned the prefab out so that it's just a basic structure with all the visuals in tact/functionality.

 

So, for a more detailed explanation of what I'd like to eventually get to, once I get basic crock pot storage functionality, I'd like the structure to only hold items belonging to the mod, which would be tagged similarly to non-teleportato items. I'd also like the 'cook' functionality to work regardless of how many items are in the structure. Instead of 'cook', the machine is meant to have a 'charge' function, so it won't combine the four items but merely reset them to their full-powered state after about 15-30 seconds have passed. That said, I'll need to edit the button function to allow it the machine to function regardless of if it's full or not.

~~~~~

That's about the extent of how I want the structure to work, and I think I know how to do a good portion of it just from looking at the teleportato/crock pot's files, but I can't get any sort of storage GUI to function and would like some help with that aspect at least. And if you read all that, thanks for your time~

 

Oh, and if all you could help with is just recreating the crock pot with a modded structure that would probably be enough for me to get the rest of the way after banging my head against it some more, I've just been working for 6-7 hours between this and another of the items in the mod, and I'm tired/wanting a break to ask for help. xD

Edited by polygone

I am currently working on a Blacksmith mod.

I created an placable item named Furnace that can refine 3 minerals to create one new item.

 

I can't do all the code for you, but I think my code can help you a lot =)

 

Here is a part of my modmain.lua :

 

Some assets I made. Don't use mine, it won't work for you.

	Asset("ANIM", "anim/furnace.zip"),	Asset("ATLAS", "images/inventoryimages/furnace.xml"),        Asset("IMAGE", "images/inventoryimages/furnace.tex"),

The setting of the furnace :

local require = GLOBAL.requirelocal STRINGS = GLOBAL.STRINGSlocal OldIsRecipeValid = GLOBAL.IsRecipeValidlocal function IsRecipeValid(recipe)	return OldIsRecipeValid(recipe) and		((GLOBAL.ThePlayer and GLOBAL.ThePlayer:HasTag(recipe.name.."_builder")) or not recipe.tagneeded)endGLOBAL.IsRecipeValid = IsRecipeValidlocal Recipe = GLOBAL.Recipelocal RECIPETABS = GLOBAL.RECIPETABSlocal TECH = GLOBAL.TECH-- This will allow a player to make a furnacelocal recipes = {	Recipe("furnace", {Ingredient("cutstone", 4), Ingredient("charcoal", 6), Ingredient("goldnugget", 6)}, RECIPETABS.TOWN, TECH.SCIENCE_TWO,"furnace_placer" ),}-- This is for the images one the tab to create the furnacefor k,v in pairs(recipes) do    v.tagneeded = true    v.atlas = "images/inventoryimages/" .. v.name .. ".xml"end-- This is the setting of the furnace as a container_G = GLOBALlocal params={} params.furnace ={    widget =    {        slotpos =        {            _G.Vector3(0, 32 + 4, 0),            _G.Vector3(0, -(32 + 4), 0),             _G.Vector3(0, -(64 + 32 + 8 + 4), 0),        },        animbank = "background",        animbuild = "background",        pos = _G.Vector3(100, 0, 0),        side_align_tip = 100,        buttoninfo =        {            text = "Refine",            position = _G.Vector3(0, -165, 0),        }    },    acceptsstacks = false,    type = "cooker",}-- This test what items can go in the furnacefunction params.furnace.itemtestfn(container, item, slot)    if item.prefab == "flint" or	item.prefab == "rocks" or	item.prefab == "ash" or	item.prefab == "charcoal" or	item.prefab == "iron" or	item.prefab == "goldnugget" or	item.prefab == "moonrocknugget" or	item.prefab == "sharp_crystal"	then        return true    end	return falseend

And the name for the fonction you want to apply when using the button :

function params.furnace.widget.buttoninfo.fn(inst)

Now this is from the prefab furnace.lua :

local function fn(Sim)      local inst = CreateEntity()    inst.entity:AddTransform()	inst.entity:AddAnimState()	inst.entity:AddSoundEmitter()	inst.entity:AddLight()	inst.entity:AddNetwork()		inst.entity:SetPristine()    	if not TheWorld.ismastersim then        return inst    end		MakeObstaclePhysics(inst, .5)		inst.Light:Enable(false)    inst.Light:SetRadius(.6)    inst.Light:SetFalloff(1)    inst.Light:SetIntensity(.5)    inst.Light:SetColour(235/255,62/255,12/255) 	    inst.AnimState:SetBank("furnace")    inst.AnimState:SetBuild("furnace")    inst.AnimState:PlayAnimation("idle")     inst:AddComponent("inspectable")	inst:AddTag("structure")		inst:AddComponent("container")    inst.components.container:WidgetSetup("furnace")	inst.components.container.widgetanimbank = "background"    inst.components.container.widgetanimbuild = "background"	inst.components.container.onopenfn = onopen    inst.components.container.onclosefn = onclose		inst:AddComponent("playerprox")    inst.components.playerprox:SetDist(3,5)    inst.components.playerprox:SetOnPlayerFar(onfar)		    return instendreturn  Prefab("common/furnace", fn, assets, prefabs),		MakePlacer( "common/furnace_placer", "furnace", "furnace", "idle" )

I hope it helps =)

 

Pyrobolser

 

Now this is from the prefab furnace.lua :

	inst:AddComponent("container")    inst.components.container:WidgetSetup("furnace")	inst.components.container.widgetanimbank = "background"    inst.components.container.widgetanimbuild = "background"	inst.components.container.onopenfn = onopen    inst.components.container.onclosefn = onclose

I hope it helps =)

 

Pyrobolser

 

For the widgetanimbank/widgetanimbuild, what is that supposed to be in reference to? If there are supposed to be files in some directory within the mod for the gui that could be what's breaking.

 

I just end up with this error when trying to actually open the container:

[sring "scripts/widgets/containerwidget.lua:]:29: attempt to index local 'widget' (a nil value)

"background" is a custom anim/image I made. It's in the asset "anim/furnace.zip". It is for the background of the container menu (without the 3 item slot and the button).

 

I think you can comment out or suppr lines 68 & 69.

    inst.components.container.widgetanimbank = "background"    inst.components.container.widgetanimbuild = "background"
 

Same goes for :

 

        animbank = "background",        animbuild = "background",
 

But you know if you just copy past the code I gave you, it won't work. It is just some part of the file, not all the code.

Edited by Pyrobolser

Commented out those bits, still the same error. And I know just copy/pasta won't work, I just took the bits pertaining to the container section itself. Then I edited furnace with the name of my structure/set up dummy functions for onopen and onclose.

 

I could even comment out all the code I added to the structure.lua, but it still gives the same error so it's something up with the widget in the modmain.lua, I just don't know what it could be about the widget that's causing it. I'm systematically turning things off and on with comments to see if I can coax it into even giving a different error message, but it doesn't seem to want to do anything.

 

e/ I got it functioning as a chest! I took a hint from the Cellar door mod and switched the global vectors to a tileable table, so now I have that much functioning. Next step would be converting the container to include a button, which /should/ be simple as adding the button functions back/changing the type to a cooker instead of a chest.

 

e// Got it all fixed up and working as desired. Thanks for the help!~ ^^

Edited by polygone

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...