tpmove Posted April 5, 2024 Share Posted April 5, 2024 (edited) I am a novice mod maker and have learned how to create a handheld item. But now I want to make a building, and I don't know what its necessary components are. Its basic function is to have four compartments, place an item, and then click the button to convert it to another item in the backpack item column. Edited April 7, 2024 by tpmove The problem has been resolved Link to comment https://forums.kleientertainment.com/forums/topic/155454-solvedi-need-help-with-mods-production/ Share on other sites More sharing options...
tpmove Posted April 5, 2024 Author Share Posted April 5, 2024 After studying, I have now realized how to place it on the ground, but how to make it open like a box and put items inside? Link to comment https://forums.kleientertainment.com/forums/topic/155454-solvedi-need-help-with-mods-production/#findComment-1709377 Share on other sites More sharing options...
tpmove Posted April 6, 2024 Author Share Posted April 6, 2024 Now I have implemented it as a box, which generates a set of ice when I close it, but when I open the dedicated server, it will report an error This is the error log [00:01:41]: [string "scripts/widgets/containerwidget.lua"]:31: attempt to index local 'widget' (a nil value) LUA ERROR stack traceback: scripts/widgets/containerwidget.lua:31 in (method) Open (Lua) <25-158> scripts/screens/playerhud.lua:367 in (upvalue) OpenContainerWidget (Lua) <352-373> scripts/screens/playerhud.lua:381 in (method) OpenContainer (Lua) <375-383> scripts/components/container_replica.lua:438 in (method) Open (Lua) <424-451> scripts/components/container_replica.lua:145 in (field) fn (Lua) <137-151> scripts/scheduler.lua:186 in (method) OnTick (Lua) <164-216> scripts/scheduler.lua:409 in (global) RunScheduler (Lua) <407-415> scripts/update.lua:240 in () ? (Lua) <224-298> This is my code,it looks very messy require "prefabutil" local assets = { Asset("ANIM", "anim/testcookpot.zip"), Asset("ANIM", "anim/swap_testcookpot.zip"), Asset("ANIM", "anim/testcookpot_placer.zip"), Asset("ANIM", "anim/swap_testcookpot_placer.zip"), Asset("ANIM", "anim/ui_chest_3x3.zip"), Asset("ATLAS", "images/inventoryimages/testbuild.xml"), } local prefabs = { "collapse_small", } local function onopen(inst) inst.AnimState:PlayAnimation("idle") inst.SoundEmitter:PlaySound("dontstarve/common/icebox_open") end local function onclose(inst) inst.AnimState:PlayAnimation("idle") inst.SoundEmitter:PlaySound("dontstarve/common/icebox_close") for i = 1, 40, 1 do inst.components.container:GiveItem(SpawnPrefab("ice")) --GiveItem()有四个参数第一个是物品名字,第二个是生成位置 end end local function onhammered(inst, worker) inst.components.lootdropper:DropLoot() inst.components.container:DropEverything() local fx = SpawnPrefab("collapse_small") fx.Transform:SetPosition(inst.Transform:GetWorldPosition()) fx:SetMaterial("metal") inst:Remove() end local function onhit(inst, worker) inst.AnimState:PlayAnimation("idle") inst.components.container:DropEverything() inst.AnimState:PushAnimation("idle", false) inst.components.container:Close() end local function onbuilt(inst) inst.AnimState:PlayAnimation("idle") -- inst.AnimState:PushAnimation("closed", false) inst.SoundEmitter:PlaySound("dontstarve/common/icebox_craft") end local function fn() local inst = CreateEntity() inst.entity:AddTransform() -- 添加变换组件,一般只需要添加组件就行了 inst.entity:AddAnimState() -- 添加动画组件 inst.entity:AddSoundEmitter() --添加声音组件 inst.entity:AddNetwork() -- 添加网络组件 inst:AddTag("structure") inst:AddTag("chest") MakeObstaclePhysics(inst, .5) -- 设置物品拥有一般物品栏物体的物理特性,这是一个系统封装好的函数,内部已经含有对物理引擎的设置 inst.AnimState:SetBank("testcookpot") -- 设置动画属性 Bank lotus_umbrella inst.AnimState:SetBuild("testcookpot") -- 设置动画属性 Build lotus_umbrella inst.AnimState:PlayAnimation("idle") -- 设置默认播放动画为idle -- 以下这几句是设置网络状态的,并且作为一个分界线,从这个if then 块往上是主客机通用代码,往下则是只限于主机使用的代码。 if not TheWorld.ismastersim then return inst end inst.entity:SetPristine() inst:AddComponent("container") --容器组件 inst.components.container:WidgetSetup("icebox") inst.components.container.onopenfn = onopen --打开时调用函数 inst.components.container.onclosefn = onclose --关闭时调用函数 inst.components.container.skipclosesnd = true inst.components.container.skipopensnd = true inst:AddComponent("lootdropper") inst:AddComponent("workable") inst.components.workable:SetWorkAction(ACTIONS.HAMMER) inst.components.workable:SetWorkLeft(2) inst.components.workable:SetOnFinishCallback(onhammered) inst.components.workable:SetOnWorkCallback(onhit) inst:ListenForEvent("onbuilt", onbuilt) return inst end return Prefab("testcookpot", fn, assets, prefabs), MakePlacer("common/testcookpot_placer", "testcookpot_placer", "testcookpot_placer", "idle", true) Link to comment https://forums.kleientertainment.com/forums/topic/155454-solvedi-need-help-with-mods-production/#findComment-1709498 Share on other sites More sharing options...
Haruhi Kawaii Posted April 6, 2024 Share Posted April 6, 2024 52 minutes ago, tpmove said: Now I have implemented it as a box, which generates a set of ice when I close it, but when I open the dedicated server, it will report an error This is the error log [00:01:41]: [string "scripts/widgets/containerwidget.lua"]:31: attempt to index local 'widget' (a nil value) LUA ERROR stack traceback: scripts/widgets/containerwidget.lua:31 in (method) Open (Lua) <25-158> scripts/screens/playerhud.lua:367 in (upvalue) OpenContainerWidget (Lua) <352-373> scripts/screens/playerhud.lua:381 in (method) OpenContainer (Lua) <375-383> scripts/components/container_replica.lua:438 in (method) Open (Lua) <424-451> scripts/components/container_replica.lua:145 in (field) fn (Lua) <137-151> scripts/scheduler.lua:186 in (method) OnTick (Lua) <164-216> scripts/scheduler.lua:409 in (global) RunScheduler (Lua) <407-415> scripts/update.lua:240 in () ? (Lua) <224-298> This is my code,it looks very messy require "prefabutil" local assets = { Asset("ANIM", "anim/testcookpot.zip"), Asset("ANIM", "anim/swap_testcookpot.zip"), Asset("ANIM", "anim/testcookpot_placer.zip"), Asset("ANIM", "anim/swap_testcookpot_placer.zip"), Asset("ANIM", "anim/ui_chest_3x3.zip"), Asset("ATLAS", "images/inventoryimages/testbuild.xml"), } local prefabs = { "collapse_small", } local function onopen(inst) inst.AnimState:PlayAnimation("idle") inst.SoundEmitter:PlaySound("dontstarve/common/icebox_open") end local function onclose(inst) inst.AnimState:PlayAnimation("idle") inst.SoundEmitter:PlaySound("dontstarve/common/icebox_close") for i = 1, 40, 1 do inst.components.container:GiveItem(SpawnPrefab("ice")) --GiveItem()有四个参数第一个是物品名字,第二个是生成位置 end end local function onhammered(inst, worker) inst.components.lootdropper:DropLoot() inst.components.container:DropEverything() local fx = SpawnPrefab("collapse_small") fx.Transform:SetPosition(inst.Transform:GetWorldPosition()) fx:SetMaterial("metal") inst:Remove() end local function onhit(inst, worker) inst.AnimState:PlayAnimation("idle") inst.components.container:DropEverything() inst.AnimState:PushAnimation("idle", false) inst.components.container:Close() end local function onbuilt(inst) inst.AnimState:PlayAnimation("idle") -- inst.AnimState:PushAnimation("closed", false) inst.SoundEmitter:PlaySound("dontstarve/common/icebox_craft") end local function fn() local inst = CreateEntity() inst.entity:AddTransform() -- 添加变换组件,一般只需要添加组件就行了 inst.entity:AddAnimState() -- 添加动画组件 inst.entity:AddSoundEmitter() --添加声音组件 inst.entity:AddNetwork() -- 添加网络组件 inst:AddTag("structure") inst:AddTag("chest") MakeObstaclePhysics(inst, .5) -- 设置物品拥有一般物品栏物体的物理特性,这是一个系统封装好的函数,内部已经含有对物理引擎的设置 inst.AnimState:SetBank("testcookpot") -- 设置动画属性 Bank lotus_umbrella inst.AnimState:SetBuild("testcookpot") -- 设置动画属性 Build lotus_umbrella inst.AnimState:PlayAnimation("idle") -- 设置默认播放动画为idle -- 以下这几句是设置网络状态的,并且作为一个分界线,从这个if then 块往上是主客机通用代码,往下则是只限于主机使用的代码。 if not TheWorld.ismastersim then return inst end inst.entity:SetPristine() inst:AddComponent("container") --容器组件 inst.components.container:WidgetSetup("icebox") inst.components.container.onopenfn = onopen --打开时调用函数 inst.components.container.onclosefn = onclose --关闭时调用函数 inst.components.container.skipclosesnd = true inst.components.container.skipopensnd = true inst:AddComponent("lootdropper") inst:AddComponent("workable") inst.components.workable:SetWorkAction(ACTIONS.HAMMER) inst.components.workable:SetWorkLeft(2) inst.components.workable:SetOnFinishCallback(onhammered) inst.components.workable:SetOnWorkCallback(onhit) inst:ListenForEvent("onbuilt", onbuilt) return inst end return Prefab("testcookpot", fn, assets, prefabs), MakePlacer("common/testcookpot_placer", "testcookpot_placer", "testcookpot_placer", "idle", true) Try this if not TheWorld.ismastersim then inst.OnEntityReplicated = function(inst) inst.replica.container:WidgetSetup("icebox") end return inst end Link to comment https://forums.kleientertainment.com/forums/topic/155454-solvedi-need-help-with-mods-production/#findComment-1709502 Share on other sites More sharing options...
tpmove Posted April 6, 2024 Author Share Posted April 6, 2024 Wow, that's great. It worked. Thank you! Link to comment https://forums.kleientertainment.com/forums/topic/155454-solvedi-need-help-with-mods-production/#findComment-1709503 Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now