Jump to content

[need help] Item invisible in the inventory?


Recommended Posts

Hi again)

I've managed to code a character and an item, however, the item remains invisible while in the inventory tab. It can be described, it can be dropped (and then shows up), so everything works, except it doesn't have a pic in the inventory.

The code i'm using runs as follows

local assets =
{
    Asset("ANIM", "anim/oldcase.zip"), -- a standard asset
    Asset("ATLAS", "images/inventoryimages/oldcase.xml")    -- a custom asset, found in the mod folder
}
local function fn()
    local inst = CreateEntity()

    inst.entity:AddTransform()
    inst.entity:AddAnimState()
    inst.entity:AddNetwork()

 MakeInventoryPhysics(inst)
    
    inst.AnimState:SetBank("oldcase")
    inst.AnimState:SetBuild("oldcase")
    inst.AnimState:PlayAnimation("idle", true)

    inst:AddComponent("fuel")
    inst.components.fuel.fuelvalue = TUNING.SMALL_FUEL
    
    inst:AddComponent("inventoryitem")
    inst.components.inventoryitem.atlasname = "images/inventoryimages/oldcase.xml"

    inst:AddComponent("inspectable")
 return inst
    end


return Prefab("oldcase", fn, assets)

So... I was trying to use [Tutorial] The Artist's Guide To Character/item Modding  as a reference, but alas...

Can anybody suggest what's wrong? Thank you for your help!

Link to comment
Share on other sites

Thank you for your replies.

My xml looks exactly the same, hmm. However, I'm not too sure if using the same u1, u2, v1, v2 values for both custom items is ok? What do those values mean anyway? I looked at another mod, downloaded from steam workshop, and it has something like

u1="0.0078125" u2="0.9921875" v1="0.0078125" v2="0.9921875"

Adding the line inst.components.inventoryitem.imagename = "oldcase" didn't help, unfortunately(

Link to comment
Share on other sites

An "atlas" is a xml file that tells the game where to find a specific image, the "texture" is the file that contains the image or images (or "elements") and the u1, u2, v1 and v2 values correspond to the coordinates in the range 0-1 of the region where the image itself is found. Simply put, u1=0, u2=1, v1=0, v2=1 means "the whole texture corresponds to a single element", and u1=0.0078125, u2=0.9921875, v1=0.0078125, v2=0.9921875 means "ignore the outer pixels" (since 1/128 = 0.0078125 and 1-1/128 = 0.9921875). This is done so for performance reasons: when loading and accessing many images, it's better to have a single physical image (i.e. the file containing the images) and dividing it into several logical images (the "elements") that are then used. See for example data/images/inventoryimages.xml and inventoryimages.tex, where you have several hundred individual images packed into just two files, the atlas and the texture. Of course, none of this is relevant or helpful when you only have a couple of images in your mod.

--

I just noticed your prefab is missing the mastersim check, which is necessary in DST - the tutorial you mention in the OP is for single player and most of it is the same, but this check is necessary. Add this to your fn after the AnimState calls and before adding components:

inst.entity:SetPristine()

if not TheWorld.ismastersim then
	return inst
end

I'm not sure it'll solve the issue at hand, though. If it doesn't, would you care to share your oldcase.tex so I can see if I can manage to get it to show up?

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