Jump to content

(solved) Creating a custom map - inventory image problem


Recommended Posts

Hello, everyone.

Lately I've doing progress in the construction of my custom character, but now I'm stucked in something I really don't understand and didn't see nothing like this in tutorials or others MODS.

I'm trying to create a custom item for my character called "star chart". It act similar to Map Scroll, but could me crafted using the Cartography tab only at night.

I was able to create the item, set it up in modmain.lua, set the assets about it, but as I'm a noob with LUA, I Just copied the "mapscroll.lua" script and pasted in my "star_chart.lua" script, changing some lines.

In game, everything works fine until the moment I craft the "star_chart". It appear in the Cartography tab, but when I craft it, a invisible item comes to my inventory. It is there, but I can't see it. I can drop the item and learn, but I can't see the item in inventory, neither on the ground. Can't see the name and inspect neither.

As I don't understand how to create a like map item, I thing the problem is in "star_chart.lua".

Here is what I got in Client_Log.txt

Spoiler

[00:00:45]: 1 uploads added to server. From server_temp
[00:00:45]: Telling Client our new session identifier: 0515ECB05D17E3CC
[00:00:48]: Best lobby region is aws/US (ping 162)
[00:00:48]: Registering master server in US lobby
[00:00:48]: Validating portal[1] <-> <nil>[1] (inactive)	
[00:00:48]: Validating portal[2] <-> <nil>[2] (inactive)	
[00:00:48]: Validating portal[3] <-> <nil>[3] (inactive)	
[00:00:48]: Attempting to send resume request
[00:00:48]: Resuming user: session/0515ECB05D17E3CC/A7NTEA9MI04E
[00:00:48]: ReceiveResumeNotification
[00:00:48]: Deleting user: session/0515ECB05D17E3CC/A7NTEA9MI04E/0000000003
[00:00:48]: Validating portal[4] <-> <nil>[4] (inactive)	
[00:00:48]: Validating portal[5] <-> <nil>[5] (inactive)	
[00:00:48]: Validating portal[6] <-> <nil>[6] (inactive)	
[00:00:48]: Validating portal[7] <-> <nil>[7] (inactive)	
[00:00:48]: Validating portal[8] <-> <nil>[8] (inactive)	
[00:00:48]: Validating portal[9] <-> <nil>[9] (inactive)	
[00:00:49]: Validating portal[10] <-> <nil>[10] (inactive)	
[00:00:54]: Spawn request: wachs from [Host] Joy Machs
[00:00:54]: Skin request: () (body_cardigan_black_jet) () (legs_pants_basic_black_scribble) (feet_sneakers_orange_carrot)
[00:00:54]: Could not find anim [anim] in bank [sanity2]
[00:00:54]: Spawning player at: [Fixed] (-202.00, 0.00, 170.00)	
[00:00:54]: Serializing user: session/0515ECB05D17E3CC/A7NTEA9MI04E/0000000003
[00:00:54]: Deserializing tile data (425 x 425)
[00:00:58]: Registering master server in US lobby
[00:01:17]: WARNING! Could not find region 'star_chart.tex' from atlas 'images/inventoryimages2.xml'. Is the region specified in the atlas?
[00:01:17]: Looking for default texture 'default.tex' from atlas 'images/inventoryimages2.xml'.
[00:01:17]: WARNING! Could not find region 'default.tex' from atlas 'images/inventoryimages2.xml'. Is the region specified in the atlas?
[00:01:17]: Error Looking for default texture in from atlas 'images/inventoryimages2.xml'.
[00:01:17]: WARNING! Could not find region 'star_chart.tex' from atlas 'images/inventoryimages2.xml'. Is the region specified in the atlas?
[00:01:17]: Looking for default texture '' from atlas 'images/inventoryimages2.xml'.
[00:01:17]: Error Looking for default texture in from atlas 'images/inventoryimages2.xml'.
[00:01:17]: WARNING! Could not find region 'star_chart.tex' from atlas 'images/inventoryimages2.xml'. Is the region specified in the atlas?
[00:01:17]: Looking for default texture '' from atlas 'images/inventoryimages2.xml'.
[00:01:17]: Error Looking for default texture in from atlas 'images/inventoryimages2.xml'.
[00:01:23]: DoRestart:	true	
[00:01:25]: Serializing user: session/0515ECB05D17E3CC/A7NTEA9MI04E/0000000003
[00:01:25]: Serializing world: session/0515ECB05D17E3CC/0000000003
[00:01:25]: Removing server from US lobby
[00:01:25]: ModWorkshop::CancelDownloads clearing all unfinished downloads
[00:01:25]: Collecting garbage...
[00:01:25]: lua_gc took 0.29 seconds
[00:01:26]: ~ShardLuaProxy()
[00:01:26]: ~cEventLeaderboardProxy()
[00:01:26]: ~ItemServerLuaProxy()
[00:01:26]: ~InventoryLuaProxy()
[00:01:26]: ~NetworkLuaProxy()
[00:01:26]: ~SimLuaProxy()
[00:01:26]: ModWorkshop::CancelDownloads clearing all unfinished downloads
[00:01:26]: lua_close took 0.43 seconds
[00:01:26]: ReleaseAll
[00:01:26]: ReleaseAll Finished
[00:01:26]: cGame::StartPlaying
[00:01:26]: LOADING LUA
[00:01:26]: DoLuaFile scripts/main.lua
[00:01:26]: DoLuaFile loading buffer scripts/main.lua
[00:01:26]:   taskgrouplist:	default	Together	
[00:01:26]:   taskgrouplist:	classic	Classic	
[00:01:26]:   taskgrouplist:	cave_default	Underground	
[00:01:26]:   taskgrouplist:	lavaarena_taskset	The Forge	
[00:01:26]:   taskgrouplist:	quagmire_taskset	The Gorge	
[00:01:26]: running main.lua

 

And here is my "star_chart.lua":

Spoiler

local assets =
{
    Asset("ANIM", "anim/star_chart.zip"),

    Asset("ATLAS", "images/inventoryimages/star_chart.xml"),
    Asset("IMAGE", "images/inventoryimages/star_chart.tex"),
}

local function OnBuilt(inst, builder)
    inst.components.maprecorder:RecordMap(builder)
end

local function OnTeach(inst, learner)
    learner:PushEvent("learnmap", { map = inst })
end

local function OnDataChanged(inst)
    local maprecorder = inst.components.maprecorder

    inst.components.inspectable:SetDescription(
        maprecorder:HasData() and
        subfmt(STRINGS.MAPRECORDER.MAPDESC, {
            author = maprecorder.mapauthor or STRINGS.MAPRECORDER.UNKNOWN_AUTHOR,
            day = maprecorder.mapday ~= nil and tostring(maprecorder.mapday) or STRINGS.MAPRECORDER.UNKNOWN_DAY,
            location = maprecorder.maplocation ~= nil and STRINGS.MAPRECORDER.LOCATION[string.upper(maprecorder.maplocation)] or STRINGS.MAPRECORDER.LOCATION.DEFAULT,
        }) or
        nil
    )

    if maprecorder.maplocation == "cave" then
        inst.AnimState:SetBuild("star_chart")
        inst.components.inventoryitem:ChangeImageName("star_chart")
    else
        inst.AnimState:SetBuild("star_chart")
        inst.components.inventoryitem:ChangeImageName()
    end
end

local function fn()
    local inst = CreateEntity()

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

    MakeInventoryPhysics(inst)

    inst.AnimState:SetBank("mapscroll")
    inst.AnimState:SetBuild(TheWorld.worldprefab == "cave" and "mapscroll_cave" or "mapscroll")
    inst.AnimState:PlayAnimation("idle")

    MakeInventoryFloatable(inst, "med", nil, 0.85)

    inst.entity:SetPristine()

    if not TheWorld.ismastersim then
        return inst
    end

    inst:AddComponent("inspectable")
    inst:AddComponent("maprecorder")
    inst.components.maprecorder:SetOnTeachFn(OnTeach)
    inst.components.maprecorder:SetOnDataChangedFn(OnDataChanged)

    inst:AddComponent("inventoryitem")
    if TheWorld.worldprefab == "cave" then
        inst.components.inventoryitem:ChangeImageName("mapscroll_cave")
    end

    inst:AddComponent("fuel")
    inst.components.fuel.fuelvalue = TUNING.SMALL_FUEL

    MakeSmallBurnable(inst, TUNING.SMALL_BURNTIME)
    MakeSmallPropagator(inst)

    MakeHauntableLaunch(inst)

    inst.OnBuiltFn = OnBuilt

    return inst
end

return Prefab("star_chart", fn, assets)

 

Can someone help me checking this lines? I'm almost finishing my character and I'm looking for a solution to this "problem".

Edited by Joy Machs
The problem was solved with the member's sugestion.
Link to comment
Share on other sites

3 hours ago, Omaremad74 said:

Try putting this as a line

 

 

Thanks to your insight, I could manage fix somethings. Thanks a lot.

I added this lines to my "star_chart.lua":

 

Quote

inst.components.inventoryitem.imagename = "star_chart"
inst.components.inventoryitem.atlasname = "images/inventoryimages/star_chart.xml"

This lines fixed the inventory icon problem, but not the "on ground" image. So I looked a little bit more in "mapscroll.lua" script and figured some others lines I needed to change "mapscroll" to "star_chart".

To finish my character, as a star gazer, he can't be able to craft this map during the day and dusk. Only at night of the forest world. He can't be able to craft in any time inside caves.

So the idea is: Everytime he tries to craft the "star_chart" during day, dusk or caves, he would say something like:
"I can't draw what I can't see..."

I think it would be better them have a message for the day/dusk and another for the caves... I don't really know.

There is a way I can reach this result?

Edited by Joy Machs
Link to comment
Share on other sites

5 hours ago, Joy Machs said:

Thanks to your insight, I could manage fix somethings. Thanks a lot.

I added this lines to my "star_chart.lua":

 

This lines fixed the inventory icon problem, but not the "on ground" image. So I looked a little bit more in "mapscroll.lua" script and figured some others lines I needed to change "mapscroll" to "star_chart".

To finish my character, as a star gazer, he can't be able to craft this map during the day and dusk. Only at night of the forest world. He can't be able to craft in any time inside caves.

So the idea is: Everytime he tries to craft the "star_chart" during day, dusk or caves, he would say something like:
"I can't draw what I can't see..."

I think it would be better them have a message for the day/dusk and another for the caves... I don't really know.

There is a way I can reach this result?

Did you rename the build files? You cant just rename animation files

Link to comment
Share on other sites

1 hour ago, Omaremad74 said:

Did you rename the build files? You cant just rename animation files

As I said before, I'm not familiar with the Lua language, so I just copy/paste the lines from the "mapscroll.lua" script, changed some lines and tested to see if everything works. My "star_chart.lua" script is a little dirty now because I don't really know what is useful to keep and what I can take off from the code.

Here is my "star_chart.lua":

Spoiler

local assets =
{
    Asset("ANIM", "anim/star_chart.zip"),

    Asset("ATLAS", "images/inventoryimages/star_chart.xml"),
    Asset("IMAGE", "images/inventoryimages/star_chart.tex"),
}

local function OnBuilt(inst, builder)
    inst.components.maprecorder:RecordMap(builder)
end

local function OnTeach(inst, learner)
    learner:PushEvent("learnmap", { map = inst })
end

local function OnDataChanged(inst)
    local maprecorder = inst.components.maprecorder

    inst.components.inspectable:SetDescription(
        maprecorder:HasData() and
        subfmt(STRINGS.MAPRECORDER.MAPDESC, {
            author = maprecorder.mapauthor or STRINGS.MAPRECORDER.UNKNOWN_AUTHOR,
            day = maprecorder.mapday ~= nil and tostring(maprecorder.mapday) or STRINGS.MAPRECORDER.UNKNOWN_DAY,
            location = maprecorder.maplocation ~= nil and STRINGS.MAPRECORDER.LOCATION[string.upper(maprecorder.maplocation)] or STRINGS.MAPRECORDER.LOCATION.DEFAULT,
        }) or
        nil
    )

--    if maprecorder.maplocation == "cave" then
--        inst.AnimState:SetBuild("star_chart")
--        inst.components.inventoryitem:ChangeImageName("mapscroll_cave")
--    else
--        inst.AnimState:SetBuild("star_chart")
--        inst.components.inventoryitem:ChangeImageName()
--    end
end

local function fn()
    local inst = CreateEntity()

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

    MakeInventoryPhysics(inst)

    inst.AnimState:SetBank("star_chart")
    inst.AnimState:SetBuild(TheWorld.worldprefab == "cave" and "mapscroll_cave" or "star_chart")
    inst.AnimState:PlayAnimation("idle")

    MakeInventoryFloatable(inst, "med", nil, 0.85)

    inst.entity:SetPristine()

    if not TheWorld.ismastersim then
        return inst
    end

    inst:AddComponent("inspectable")
    inst:AddComponent("maprecorder")
    inst.components.maprecorder:SetOnTeachFn(OnTeach)
    inst.components.maprecorder:SetOnDataChangedFn(OnDataChanged)

    inst:AddComponent("inventoryitem")
    inst.components.inventoryitem.imagename = "star_chart"
    inst.components.inventoryitem.atlasname = "images/inventoryimages/star_chart.xml"
    --if TheWorld.worldprefab == "cave" then
   -- inst.components.inventoryitem:ChangeImageName("mapscroll_cave")
    --end

    inst:AddComponent("fuel")
    inst.components.fuel.fuelvalue = TUNING.SMALL_FUEL

    MakeSmallBurnable(inst, TUNING.SMALL_BURNTIME)
    MakeSmallPropagator(inst)

    MakeHauntableLaunch(inst)

    inst.OnBuiltFn = OnBuilt

    return inst
end

return Prefab("star_chart", fn, assets)

 

 

And here is the "mapscroll.lua" that I extracted the lines:

Spoiler

local assets =
{
    Asset("ANIM", "anim/mapscroll.zip"),
    Asset("ANIM", "anim/mapscroll_cave.zip"),
    Asset("INV_IMAGE", "mapscroll_cave"),
}

local function OnBuilt(inst, builder)
    inst.components.maprecorder:RecordMap(builder)
end

local function OnTeach(inst, learner)
    learner:PushEvent("learnmap", { map = inst })
end

local function OnDataChanged(inst)
    local maprecorder = inst.components.maprecorder

    inst.components.inspectable:SetDescription(
        maprecorder:HasData() and
        subfmt(STRINGS.MAPRECORDER.MAPDESC, {
            author = maprecorder.mapauthor or STRINGS.MAPRECORDER.UNKNOWN_AUTHOR,
            day = maprecorder.mapday ~= nil and tostring(maprecorder.mapday) or STRINGS.MAPRECORDER.UNKNOWN_DAY,
            location = maprecorder.maplocation ~= nil and STRINGS.MAPRECORDER.LOCATION[string.upper(maprecorder.maplocation)] or STRINGS.MAPRECORDER.LOCATION.DEFAULT,
        }) or
        nil
    )

    if maprecorder.maplocation == "cave" then
        inst.AnimState:SetBuild("mapscroll_cave")
        inst.components.inventoryitem:ChangeImageName("mapscroll_cave")
    else
        inst.AnimState:SetBuild("mapscroll")
        inst.components.inventoryitem:ChangeImageName()
    end
end

local function fn()
    local inst = CreateEntity()

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

    MakeInventoryPhysics(inst)

    inst.AnimState:SetBank("mapscroll")
    inst.AnimState:SetBuild(TheWorld.worldprefab == "cave" and "mapscroll_cave" or "mapscroll")
    inst.AnimState:PlayAnimation("idle")

    MakeInventoryFloatable(inst, "med", nil, 0.85)

    inst.entity:SetPristine()

    if not TheWorld.ismastersim then
        return inst
    end

    inst:AddComponent("inspectable")
    inst:AddComponent("maprecorder")
    inst.components.maprecorder:SetOnTeachFn(OnTeach)
    inst.components.maprecorder:SetOnDataChangedFn(OnDataChanged)

    inst:AddComponent("inventoryitem")
    if TheWorld.worldprefab == "cave" then
        inst.components.inventoryitem:ChangeImageName("mapscroll_cave")
    end

    inst:AddComponent("fuel")
    inst.components.fuel.fuelvalue = TUNING.SMALL_FUEL

    MakeSmallBurnable(inst, TUNING.SMALL_BURNTIME)
    MakeSmallPropagator(inst)

    MakeHauntableLaunch(inst)

    inst.OnBuiltFn = OnBuilt

    return inst
end

return Prefab("mapscroll", fn, assets)

 

 

Here you can compare the lines and see what was done. I changed the Asset directories and traded "mapscroll" to "star_chart" in some cases. Traded "mapscroll_cave" to "none" too (because I don't really understand how to make the star chart only craftable in the night phase of the Forest World). That is what I'm trying to figure out now. The way it is now, I'm able to craft the item at any moment in the Forest World and Caves.

Link to comment
Share on other sites

38 minutes ago, Joy Machs said:

As I said before, I'm not familiar with the Lua language, so I just copy/paste the lines from the "mapscroll.lua" script, changed some lines and tested to see if everything works. My "star_chart.lua" script is a little dirty now because I don't really know what is useful to keep and what I can take off from the code.

Here is my "star_chart.lua":

  Hide contents


local assets =
{
    Asset("ANIM", "anim/star_chart.zip"),

    Asset("ATLAS", "images/inventoryimages/star_chart.xml"),
    Asset("IMAGE", "images/inventoryimages/star_chart.tex"),
}

local function OnBuilt(inst, builder)
    inst.components.maprecorder:RecordMap(builder)
end

local function OnTeach(inst, learner)
    learner:PushEvent("learnmap", { map = inst })
end

local function OnDataChanged(inst)
    local maprecorder = inst.components.maprecorder

    inst.components.inspectable:SetDescription(
        maprecorder:HasData() and
        subfmt(STRINGS.MAPRECORDER.MAPDESC, {
            author = maprecorder.mapauthor or STRINGS.MAPRECORDER.UNKNOWN_AUTHOR,
            day = maprecorder.mapday ~= nil and tostring(maprecorder.mapday) or STRINGS.MAPRECORDER.UNKNOWN_DAY,
            location = maprecorder.maplocation ~= nil and STRINGS.MAPRECORDER.LOCATION[string.upper(maprecorder.maplocation)] or STRINGS.MAPRECORDER.LOCATION.DEFAULT,
        }) or
        nil
    )

--    if maprecorder.maplocation == "cave" then
--        inst.AnimState:SetBuild("star_chart")
--        inst.components.inventoryitem:ChangeImageName("mapscroll_cave")
--    else
--        inst.AnimState:SetBuild("star_chart")
--        inst.components.inventoryitem:ChangeImageName()
--    end
end

local function fn()
    local inst = CreateEntity()

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

    MakeInventoryPhysics(inst)

    inst.AnimState:SetBank("star_chart")
    inst.AnimState:SetBuild(TheWorld.worldprefab == "cave" and "mapscroll_cave" or "star_chart")
    inst.AnimState:PlayAnimation("idle")

    MakeInventoryFloatable(inst, "med", nil, 0.85)

    inst.entity:SetPristine()

    if not TheWorld.ismastersim then
        return inst
    end

    inst:AddComponent("inspectable")
    inst:AddComponent("maprecorder")
    inst.components.maprecorder:SetOnTeachFn(OnTeach)
    inst.components.maprecorder:SetOnDataChangedFn(OnDataChanged)

    inst:AddComponent("inventoryitem")
    inst.components.inventoryitem.imagename = "star_chart"
    inst.components.inventoryitem.atlasname = "images/inventoryimages/star_chart.xml"
    --if TheWorld.worldprefab == "cave" then
   -- inst.components.inventoryitem:ChangeImageName("mapscroll_cave")
    --end

    inst:AddComponent("fuel")
    inst.components.fuel.fuelvalue = TUNING.SMALL_FUEL

    MakeSmallBurnable(inst, TUNING.SMALL_BURNTIME)
    MakeSmallPropagator(inst)

    MakeHauntableLaunch(inst)

    inst.OnBuiltFn = OnBuilt

    return inst
end

return Prefab("star_chart", fn, assets)

 

 

And here is the "mapscroll.lua" that I extracted the lines:

  Reveal hidden contents


local assets =
{
    Asset("ANIM", "anim/mapscroll.zip"),
    Asset("ANIM", "anim/mapscroll_cave.zip"),
    Asset("INV_IMAGE", "mapscroll_cave"),
}

local function OnBuilt(inst, builder)
    inst.components.maprecorder:RecordMap(builder)
end

local function OnTeach(inst, learner)
    learner:PushEvent("learnmap", { map = inst })
end

local function OnDataChanged(inst)
    local maprecorder = inst.components.maprecorder

    inst.components.inspectable:SetDescription(
        maprecorder:HasData() and
        subfmt(STRINGS.MAPRECORDER.MAPDESC, {
            author = maprecorder.mapauthor or STRINGS.MAPRECORDER.UNKNOWN_AUTHOR,
            day = maprecorder.mapday ~= nil and tostring(maprecorder.mapday) or STRINGS.MAPRECORDER.UNKNOWN_DAY,
            location = maprecorder.maplocation ~= nil and STRINGS.MAPRECORDER.LOCATION[string.upper(maprecorder.maplocation)] or STRINGS.MAPRECORDER.LOCATION.DEFAULT,
        }) or
        nil
    )

    if maprecorder.maplocation == "cave" then
        inst.AnimState:SetBuild("mapscroll_cave")
        inst.components.inventoryitem:ChangeImageName("mapscroll_cave")
    else
        inst.AnimState:SetBuild("mapscroll")
        inst.components.inventoryitem:ChangeImageName()
    end
end

local function fn()
    local inst = CreateEntity()

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

    MakeInventoryPhysics(inst)

    inst.AnimState:SetBank("mapscroll")
    inst.AnimState:SetBuild(TheWorld.worldprefab == "cave" and "mapscroll_cave" or "mapscroll")
    inst.AnimState:PlayAnimation("idle")

    MakeInventoryFloatable(inst, "med", nil, 0.85)

    inst.entity:SetPristine()

    if not TheWorld.ismastersim then
        return inst
    end

    inst:AddComponent("inspectable")
    inst:AddComponent("maprecorder")
    inst.components.maprecorder:SetOnTeachFn(OnTeach)
    inst.components.maprecorder:SetOnDataChangedFn(OnDataChanged)

    inst:AddComponent("inventoryitem")
    if TheWorld.worldprefab == "cave" then
        inst.components.inventoryitem:ChangeImageName("mapscroll_cave")
    end

    inst:AddComponent("fuel")
    inst.components.fuel.fuelvalue = TUNING.SMALL_FUEL

    MakeSmallBurnable(inst, TUNING.SMALL_BURNTIME)
    MakeSmallPropagator(inst)

    MakeHauntableLaunch(inst)

    inst.OnBuiltFn = OnBuilt

    return inst
end

return Prefab("mapscroll", fn, assets)

 

 

Here you can compare the lines and see what was done. I changed the Asset directories and traded "mapscroll" to "star_chart" in some cases. Traded "mapscroll_cave" to "none" too (because I don't really understand how to make the star chart only craftable in the night phase of the Forest World). That is what I'm trying to figure out now. The way it is now, I'm able to craft the item at any moment in the Forest World and Caves.

Alright so I'm at school so I cant explain as well but simply renaming animation files will not work, you need to rename the build file inside, you can do this by extracting it and renaming the scml files, you also need to rename the banks inside of the scml file too.

if you want the same exact look, keep the lines for anim assets and animstates

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