Jump to content

Recommended Posts

Hi! So I'm working on my moded character Wramp, and one of his perks was going to be a suitcase that can store Dress items. I got the suitcase ingame and it works! But I have no idea how to maker it only accept certain items. Any help would be awesome!

image.png.9d52f73e61ca8edf22a6aecc8c9fcfff.png

9 hours ago, Doodle Monster said:

this file is unavailable

9 hours ago, Doodle Monster said:

I don't really know how to make my own Widget; so I just reused chester's. Hopefully that dosen't change anything.

you'll probably want to make your own so you can make use of the itemtestfn for containers

Got it! So Inorder to make my own Widget I would need to do something like this?

I don't *really* know what i'm looking at; my end goal would be a Widget that is exactly like the normal chest

(I borrowed this code from another mod, it is not mine)

GLOBAL.setfenv(1, GLOBAL)
local params = require("containers").params
local widget_toolbox = {
    widget =
    {
        slotpos = {},
        animbank = "ui_toolbox_3x3",
        animbuild = "ui_toolbox_3x3",
        pos = Vector3(0, 200, 0),
        side_align_tip = 160,
    },
    type = "chest",
}
for y = 2, 0, -1 do
    for x = 0, 2 do
        table.insert(widget_toolbox.widget.slotpos, Vector3(80 * x - 80 * 2 + 80, 80 * y - 80 * 2 + 80, 0))
    end
end

@Merkyrrie Sorry for the ping! I'm guessing I need the Widget inorder to use something like this;

(I took this from a mod it is not mine)

function widget_toolbox.itemtestfn(container, item, slot)
    return
        item.prefab == "sewing_tape" or
        item.prefab == "winona_catapult_item" or
        item.prefab == "winona_spotlight_item" or
        item.prefab == "winona_battery_low_item" or
        item.prefab == "winona_battery_high_item" or
        item.prefab == "winona_remote" or
        item.prefab == "inspectacleshat" or
        item.prefab == "winona_storage_robot" or
        item.prefab == "winona_teleport_pad_item" or
        item.prefab == "winona_telebrella"
end
3 hours ago, Doodle Monster said:

I'll try and reupload the prefab file; hopefully it lets you download it.

wramp_suitcase.luaUnavailable

It did not :? but thats fine

 

3 hours ago, Doodle Monster said:

Got it! So Inorder to make my own Widget I would need to do something like this?

I don't *really* know what i'm looking at; my end goal would be a Widget that is exactly like the normal chest

(I borrowed this code from another mod, it is not mine)

GLOBAL.setfenv(1, GLOBAL)
local params = require("containers").params
local widget_toolbox = {
    widget =
    {
        slotpos = {},
        animbank = "ui_toolbox_3x3",
        animbuild = "ui_toolbox_3x3",
        pos = Vector3(0, 200, 0),
        side_align_tip = 160,
    },
    type = "chest",
}
for y = 2, 0, -1 do
    for x = 0, 2 do
        table.insert(widget_toolbox.widget.slotpos, Vector3(80 * x - 80 * 2 + 80, 80 * y - 80 * 2 + 80, 0))
    end
end

 

3 hours ago, Doodle Monster said:

@Merkyrrie Sorry for the ping! I'm guessing I need the Widget inorder to use something like this;

(I took this from a mod it is not mine)

function widget_toolbox.itemtestfn(container, item, slot)
    return
        item.prefab == "sewing_tape" or
        item.prefab == "winona_catapult_item" or
        item.prefab == "winona_spotlight_item" or
        item.prefab == "winona_battery_low_item" or
        item.prefab == "winona_battery_high_item" or
        item.prefab == "winona_remote" or
        item.prefab == "inspectacleshat" or
        item.prefab == "winona_storage_robot" or
        item.prefab == "winona_teleport_pad_item" or
        item.prefab == "winona_telebrella"
end

Both of these are correct yeah, maybe not quite how I'd have done it but they'll work for you. I personally wouldn't do a long line of conditionals checking prefab names like this mod does but you can set the test function up however works for you.

For reference, the 'require' statement pulls the definition of containers from another file. Then you setup a table variable containing the parameters that a container needs and that the widget parameter needs which are all there. Animbank and animbuild set the UI of the container, pos is the position of the container's background, slotpos is a table of positions for each individual slot of the container which gets set in the for loop. Type = "chest" is the type of container it will be, you'd have to look at the other definitions in the container file to see all the options but chest is obviously correct for what you want. Itemtestfn is self-explanatory and returns true to accept and item and false to block an item.

As for the original question, @Merkyrrie answered it; Itemtestfn is there to test whether an item is supposed to be accepted or not. The mod you reference does it, sure, but it's a bit... messy.

For me personally, I'd do tables:

local AcceptedItems = {
    "prefab1",
    "prefab2",
    --"",
}

function yourprefab.itemtestfn(container, item, slot)
    if table.contains(AcceptedItems, item.prefab) then
        return true
    elseif item:HasTag("any_possible_tag") then
        return true
    end

    return false
end

(Note: table.contains() is not present in Lua by default and is made by Klei. You'd have to define the new function yourself elsewhere not DST.)

I think my Widget isn't working; when trying to open my container I crash

image.png.fb0de6a4fbe83ad22482c5209d801f73.png

I assume you have to put this in the script for the container to refrence the widget

inst:AddComponent("container")
    inst.components.container:WidgetSetup("wrampsuitcase")
    inst.components.container.onopenfn = onopen
    inst.components.container.onclosefn = onclose
    inst.components.container.skipclosesnd = true
    inst.components.container.skipopensnd = true
    inst.components.container.droponopen = true
Edited by Doodle Monster

Here's my code for the Widget

GLOBAL.setfenv(1, GLOBAL)
local params = require("containers").params
local widget_wrampsuitcase = {
    widget =
    {
        slotpos = {},
        pos = Vector3(0, 200, 0),
        side_align_tip = 160,
    },
    type = "chest",
}
for y = 2, 0, -1 do
    for x = 0, 2 do
        table.insert(widget_wrampsuitcase.widget.slotpos, Vector3(80 * x - 80 * 2 + 80, 80 * y - 80 * 2 + 80, 0))
    end
end

 

Edited by Doodle Monster

@Merkyrrie Is there any vanilla Continer Widgets I can look at? I'm just trying to make a exact copy of the regular chest; Hopefully you can see where I went wrong with my widget

 

Edited by Doodle Monster
5 hours ago, Doodle Monster said:

I think my Widget isn't working; when trying to open my container I crash

image.png.fb0de6a4fbe83ad22482c5209d801f73.png

I assume you have to put this in the script for the container to refrence the widget

inst:AddComponent("container")
    inst.components.container:WidgetSetup("wrampsuitcase")
    inst.components.container.onopenfn = onopen
    inst.components.container.onclosefn = onclose
    inst.components.container.skipclosesnd = true
    inst.components.container.skipopensnd = true
    inst.components.container.droponopen = true

Had this exact crash happen to someone else too so luckily for you I know how to fix it (though one of the two fixes I haven't figured out the logic behind)
Changing the name of the widget from wrampsuitcase to wramp_suitcase so it matches the prefab name might work, I've weirdly had success getting around this issue by matching names. However the 2nd option that should work if that doesn't is to do this:

-- Replacing the original version of this if statement in your prefab's function, not adding a second
	if not TheWorld.ismastersim then
  		inst:DoTaskInTime(0, function(inst)
      		inst.replica.container:WidgetSetup("wrampsuitcase") -- Sets up the widget for the client too
      	end)
        return inst
    end

 

Modmain

 

PrefabFiles = {
    "wramp_suitcase",
}
 
-- Load in some assets globally
Assets = {
    Asset("ATLAS", "images/inventoryimages/wramp_suitcase.xml"),
    Asset("IMAGE", "images/inventoryimages/wramp_suitcase.tex"),
}
 
-- Load our item icon XMLs into the Minimap!
AddMinimapAtlas("images/inventoryimages/wramp_suitcase.xml")
 
-- Declare global variables
local require = GLOBAL.require
local STRINGS = GLOBAL.STRINGS
local Ingredient = GLOBAL.Ingredient
local RECIPETABS = GLOBAL.RECIPETABS
local TECH = GLOBAL.TECH
 
-- Custom strings!
 
STRINGS.NAMES.WRAMP_SUITCASE = "Suit case"
STRINGS.RECIPE_DESC.WRAMP_SUITCASE = "For packing away any clothes."
STRINGS.CHARACTERS.GENERIC.DESCRIBE.WRAMP_SUITCASE = "This thing is heavy! What is in here?"
 
-- Custom recipes!
--[[
Default recipetabs:
RECIPETABS.TOOLS
RECIPETABS.LIGHT
RECIPETABS.SURVIVAL
RECIPETABS.FARM
RECIPETABS.SCIENCE
RECIPETABS.WAR
RECIPETABS.TOWN
RECIPETABS.SEAFARING
RECIPETABS.REFINE
RECIPETABS.MAGIC
RECIPETABS.DRESS
 
Default tech levels (science level you need to craft the item):
TECH.NONE
TECH.SCIENCE_ONE
TECH.SCIENCE_TWO
TECH.SCIENCE_THREE
TECH.MAGIC_TWO
TECH.MAGIC_THREE
]]
 
AddCharacterRecipe("wramp_suitcase",
{ -- recipes.lua or recipe.lua
    GLOBAL.Ingredient("decrease_sanity", 10),
    GLOBAL.Ingredient("nightmarefuel", 4)
},
GLOBAL.TECH.MAGIC_TWO, -- techtree.lua
{ -- recipe.lua
    builder_tag = "wramp_crafter",
    atlas = "images/inventoryimages/wramp_suitcase.xml", -- if this is an inventory item, only add this if you want the recipe image to be different than your inventory item image. otherwise, make an inventory item atlas for your item.
    image = "wramp_suitcase.tex",
},
{ -- recipes_filter.lua
    "DRESS",
})
 
GLOBAL.setfenv(1, GLOBAL)
local params = require("containers").params
local widget_wramp_suitcase = {
    widget =
    {
        slotpos = {},
        pos = Vector3(0, 200, 0),
        side_align_tip = 160,
    },
    type = "chest",
}
for y = 2, 0, -1 do
    for x = 0, 2 do
        table.insert(widget_wramp_suitcase.widget.slotpos, Vector3(80 * x - 80 * 2 + 80, 80 * y - 80 * 2 + 80, 0))
    end
end
 
--[[wramp_suitcase
 
    WRAMP_SUITCASE
]]
Edited by Doodle Monster

And the prefab file

local Assets = {
    -- Animation files for the item (showing it on the ground and swap symbols for the players).
    Asset("ANIM", "anim/wramp_suitcase_ground.zip"),
 
    -- Inventory image and atlas file used for the item.
    Asset("ATLAS", "images/inventoryimages/wramp_suitcase.xml"),
    Asset("IMAGE", "images/inventoryimages/wramp_suitcase.tex"),
}
 
local function onopen(inst)
    inst.SoundEmitter:PlaySound("qol1/ancientboat/chest_open_f2")
end
 
local function onclose(inst)
    inst.SoundEmitter:PlaySound("qol1/ancientboat/chest_close_f2")
end
 
local function OnPutInInventory(inst)
    inst.components.container:Close()
end
 
local function MainFunction()
    -- Functions which are performed both on Client and Server start here.
    local inst = CreateEntity()
   
    inst.entity:AddTransform()
    inst.entity:AddAnimState()
    inst.entity:AddNetwork()
    inst.entity:AddSoundEmitter()
   
    MakeInventoryPhysics(inst)
   
    -- Add minimap icon. Remember about its XML in modmain.lua!
    local minimap = inst.entity:AddMiniMapEntity()
    minimap:SetIcon("wramp_suitcase.tex")
   
    --[[ ANIMSTATE ]]--
    -- This is the name visible on the top of hierarchy in Spriter.
    inst.AnimState:SetBank("wramp_suitcase_ground")
    -- This is the name of your compiled*.zip file.
    inst.AnimState:SetBuild("wramp_suitcase_ground")
    -- This is the animation name while item is on the ground.
    inst.AnimState:PlayAnimation("anim")
 
    --[[ TAGS ]]--
    inst:AddTag("wramp_suitcase")
   
 
    MakeInventoryFloatable(inst, "small", 0.05, {1.2, 0.75, 1.2})
 
    inst.entity:SetPristine()
 
    if not TheWorld.ismastersim then
        inst:DoTaskInTime(0, function(inst)
            inst.replica.container:WidgetSetup("wramp_suitcase") -- Sets up the widget for the client too
        end)
      return inst
  end
 
    inst:AddComponent("inspectable")
 
    inst:AddComponent("container")
    inst.components.container:WidgetSetup("wramp_suitcase")
    inst.components.container.onopenfn = onopen
    inst.components.container.onclosefn = onclose
    inst.components.container.skipclosesnd = true
    inst.components.container.skipopensnd = true
    inst.components.container.droponopen = true
 
    inst:AddComponent("inventoryitem")
    inst.components.inventoryitem.imagename = "wramp_suitcase"
    inst.components.inventoryitem.atlasname = "images/inventoryimages/wramp_suitcase.xml"
    inst.components.inventoryitem:SetOnPutInInventoryFn(OnPutInInventory)
    inst.components.inventoryitem.canonlygoinpocket = true
 
    inst:AddComponent("lootdropper")
 
    --new new code
 
    MakeHauntableLaunch(inst)
 
    return inst
end
 
return  Prefab("common/inventory/wramp_suitcase", MainFunction, Assets)
3 hours ago, Doodle Monster said:

Modmain

 

PrefabFiles = {
    "wramp_suitcase",
}
 
-- Load in some assets globally
Assets = {
    Asset("ATLAS", "images/inventoryimages/wramp_suitcase.xml"),
    Asset("IMAGE", "images/inventoryimages/wramp_suitcase.tex"),
}
 
-- Load our item icon XMLs into the Minimap!
AddMinimapAtlas("images/inventoryimages/wramp_suitcase.xml")
 
-- Declare global variables
local require = GLOBAL.require
local STRINGS = GLOBAL.STRINGS
local Ingredient = GLOBAL.Ingredient
local RECIPETABS = GLOBAL.RECIPETABS
local TECH = GLOBAL.TECH
 
-- Custom strings!
 
STRINGS.NAMES.WRAMP_SUITCASE = "Suit case"
STRINGS.RECIPE_DESC.WRAMP_SUITCASE = "For packing away any clothes."
STRINGS.CHARACTERS.GENERIC.DESCRIBE.WRAMP_SUITCASE = "This thing is heavy! What is in here?"
 
-- Custom recipes!
--[[
Default recipetabs:
RECIPETABS.TOOLS
RECIPETABS.LIGHT
RECIPETABS.SURVIVAL
RECIPETABS.FARM
RECIPETABS.SCIENCE
RECIPETABS.WAR
RECIPETABS.TOWN
RECIPETABS.SEAFARING
RECIPETABS.REFINE
RECIPETABS.MAGIC
RECIPETABS.DRESS
 
Default tech levels (science level you need to craft the item):
TECH.NONE
TECH.SCIENCE_ONE
TECH.SCIENCE_TWO
TECH.SCIENCE_THREE
TECH.MAGIC_TWO
TECH.MAGIC_THREE
]]
 
AddCharacterRecipe("wramp_suitcase",
{ -- recipes.lua or recipe.lua
    GLOBAL.Ingredient("decrease_sanity", 10),
    GLOBAL.Ingredient("nightmarefuel", 4)
},
GLOBAL.TECH.MAGIC_TWO, -- techtree.lua
{ -- recipe.lua
    builder_tag = "wramp_crafter",
    atlas = "images/inventoryimages/wramp_suitcase.xml", -- if this is an inventory item, only add this if you want the recipe image to be different than your inventory item image. otherwise, make an inventory item atlas for your item.
    image = "wramp_suitcase.tex",
},
{ -- recipes_filter.lua
    "DRESS",
})
 
GLOBAL.setfenv(1, GLOBAL)
local params = require("containers").params
local widget_wramp_suitcase = {
    widget =
    {
        slotpos = {},
        pos = Vector3(0, 200, 0),
        side_align_tip = 160,
    },
    type = "chest",
}
for y = 2, 0, -1 do
    for x = 0, 2 do
        table.insert(widget_wramp_suitcase.widget.slotpos, Vector3(80 * x - 80 * 2 + 80, 80 * y - 80 * 2 + 80, 0))
    end
end
 
--[[wramp_suitcase
 
    WRAMP_SUITCASE
]]

Do you have a line in modmain like this

params.wramp_suitcase = widget_wramp_suitcase

 

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