Jump to content

Recommended Posts

I'm looking for help regarding adding custom items to custom character. The item itself works fine as a local mod, the problem is the game refuses to find prefab file when added to mainmod.lua of the character mod. Im sure its not just problem of missmatched names as i tried with many items, including the simplest prefab possible wich is just

local function fn()
    local inst = CreateEntity()
    inst.entity:AddTransform()
    inst.entity:AddAnimState()
    inst.entity:AddNetwork()
    inst:AddTag("testitem")
    return inst
end

return Prefab("testitem", fn)

It still results in an error during server loading:

[string "scripts/mainfunctions.lua"]:160: Error loading file prefabs/testitem

    no file '../mods/workshop-3356122492/scripts/prefabs/testitem.lua' (checked with custom loader)
    no file '../mods/workshop-3141123167/scripts/prefabs/testitem.lua' (checked with custom loader)
    no file 'scripts/prefabs/testitem.lua' (checked with custom loader)
    no file 'scriptlibs/prefabs/testitem.lua' (checked with custom loader)

I am convinced that I'm just missing a few lines of code to make everything work together, but I am unable to figure it out or find a solution.

Once again, the items themselves work fine as a separate mod, with all the sprites displaying correctly and the code functioning as expected. Any help would be greatly appreciated, as I am completely stuck and unable to make progress on the mod.

Hi there!

Might be due to the order in which mods are loaded. If you require something trom another mod, be sure to have your mod load after it by setting a lower priority in your modinfo.lua. The default is 0, so if the mod you're referencing has no priority set, any negative value will do.

-- Anywhere in your modinfo.lua
priority = 42

Good luck!

  • Like 1

Thank you for the quick answer, but I'm afraid that it is not the case. I'm trying to merge local mod (item) into character mod into a single modmain, so the character have items to craft much like other survivors. It's not ment to be separate mod and having it as one was for testing purposes only.

Once again thank You for the answer, and rest assured that I tested if your sugestion brings the problem to an end. It unfortunately did not, and I'm sorry for not making it clear that the problem occurs after I try to merge files.

  • Sanity 1

If the above advice does not help, you would have much better results uploading your mod that crashes to a post here so people can examine your code and find the problem directly. It can be hard to work out what has happened without that.

Edited by Chesed
  • Like 1
2 hours ago, oregu said:

Have you tried defining your prefab files on modmain?

  Reveal hidden contents
PrefabFiles = 
{
	"testitem",
}

 

Yes, that is why the serwer can't start, As soon as I remove the prefab from the list in modmain everything works fine. For some reason game don't find prefab. (Yes the file is in prefab folder)

Chesed your post opened my eyes to something, the log DO say that it for some reason try to read diffrent mods. I was focused on the fact that it does not find prefab that I didn't read numbers. Thank you, as for your request I have no idea what thoose mods should be. I will invastigate on my end, it might be the cause for all of this.

[string "scripts/mainfunctions.lua"]:160: Error loading file prefabs/testitem

    no file '../mods/workshop-3356122492/scripts/prefabs/testitem.lua' (checked with custom loader)
    no file 'scripts/prefabs/testitem.lua' (checked with custom loader)
    no file 'scriptlibs/prefabs/testitem.lua' (checked with custom loader)
LUA ERROR stack traceback:
        =[C] in function 'assert'
        scripts/mainfunctions.lua(160,1)
        =(tail call) ?
        =[C] in function 'xpcall'
        scripts/mods.lua(188,1)
        scripts/mods.lua(665,1) in function 'RegisterPrefabs'
        scripts/gamelogic.lua(316,1) in function 'LoadAssets'
        scripts/gamelogic.lua(1088,1) in function 'cb'
        scripts/shardindex.lua(214,1) in function 'OnLoadSaveDataFile'
        scripts/shardindex.lua(219,1)
        =[C] in function 'GetPersistentString'
    ...
        =[C] in function 'GetPersistentString'
        scripts/saveindex.lua(285,1) in function 'Load'
        scripts/gamelogic.lua(1324,1) in function 'callback'
        scripts/playerprofile.lua(1747,1) in function 'Set'
        scripts/playerprofile.lua(1587,1)
        =[C] in function 'GetPersistentString'
        scripts/playerprofile.lua(1585,1) in function 'Load'
        scripts/gamelogic.lua(1323,1) in main chunk
        =[C] in function 'require'
        scripts/mainfunctions.lua(1387,1)    
[00:00:11]: Disabling workshop-3356122492 (Glace - Refreshed) because it had an error.    

Turns out there is no mod conflict, and the whole thing is still just game not finding prefab file. Perhaps a longer segment of log that contains error from start to finish will shed more light.

I probably skimmed over something you said that your prefab is in modmain.lua. To my knowledge you can't make prefabs like that. Your prefab information must be in the scripts/prefabs file for it to work, not modmain.lua. So from where your modmain.lua is, there needs to be a scripts folder, and then a prefabs folder inside it, and then a file called testitem.lua inside that. I'm going to put the prefab file here because I notated it, and it might be useful to some. (Also included my modfile if you still cant get it to work)

Spoiler
-- using prefabs/bandage.lua  as example
-- This is just a pink honey poultice

local assets =
{
	Asset("ANIM", "anim/bandage.zip"),
	--[[
		If you are using a custom anim, from modmain.lua, it would be in your anim folder, like anim/testitem.zip
		And you have to put this in modmain.lua as well:
		Assets =
		{
			Asset("ANIM", "anim/testitem.zip"),
		}
	--]]
}

local function fn()
	local inst = CreateEntity() -- Is something in the world

	inst.entity:AddTransform() -- You can move the item
	inst.entity:AddAnimState() -- Item can change appearance
    inst.entity:AddNetwork() -- Can be on server

    MakeInventoryPhysics(inst) -- Responds to physics events like an item (for example it moves from a bearger slam)

    inst.AnimState:SetBank("bandage") -- Describes states for different animations (most inventory items are static though)
    inst.AnimState:SetBuild("bandage")
    inst.AnimState:PlayAnimation("idle") -- Only idle animation is referenced
	
	inst.AnimState:SetMultColour(1, 0, 1, 1) -- Makes it pink to distinguish from normal bandage (the only thing i modded about this object)
	inst.AnimState:SetAddColour(.1, .1, .1, 1)

    MakeInventoryFloatable(inst) -- Can float in water, i think

    inst.entity:SetPristine() -- Networking optimization; Everything from this point on is prone to change on the network, or something like that

    if not TheWorld.ismastersim then return inst end -- Everything from this point on only exists in-game (not on main menu for example)

    inst:AddComponent("stackable") -- Self explanitory
	inst.components.stackable.maxsize = TUNING.STACK_SIZE_SMALLITEM -- 40

    inst:AddComponent("inspectable") -- Self-explanitory

    inst:AddComponent("inventoryitem") -- Can go in your inventory

    inst:AddComponent("healer") -- Special item property
    inst.components.healer:SetHealthAmount(TUNING.HEALING_MEDLARGE) -- You can probably make component information their own function if it's too large

    MakeHauntableLaunch(inst) -- Haunting moves it

    return inst
end

return Prefab("testitem", fn, assets) -- Item is added into directory automatically (aka in console you can type "testitem")

 

 

serveritemtest.zip

Edited by oregu

Oh dear, was I this inprecise? What I mean is the file is in modfolder/scripts/prefabs, it is there, and yet when I add the "testitem" onto list of prefab files to read in "modmain", the game dosn't find it...

Is there any line of code that is REQUIRED for items that are made for custom character?

Still, that is a fantastic template for prefabs, and i would happily use it if You allow.

Other than that, if it's imposible to figure out a solution. Is it possible to make a separate mod that would add the items in "survivor" tab of crafting?

I encountered this issue while developing a mod in the workshop 322330 folder. I could modify Lua files but couldn't create new files or add them to the mod. When I realized the problem, I moved my mod to the mods folder.

  • Like 1

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