JackSlender Posted March 9, 2014 Share Posted March 9, 2014 Hey, guys, I am currently creating a mod that adds a custom container in the hand slot, but I am having a problem with it: when you load the save log, the container doesn't open until you remove it from the hand slot and put it back in. I know there were some problems with custom containers introduced with the most recent patch, so I wanted to check if anyone knows how to fix this or if it's just an error with the patch. Thanks for your time in advance. Link to comment https://forums.kleientertainment.com/forums/topic/32562-custom-container-error/ Share on other sites More sharing options...
JackSlender Posted March 10, 2014 Author Share Posted March 10, 2014 Bump Link to comment https://forums.kleientertainment.com/forums/topic/32562-custom-container-error/#findComment-428341 Share on other sites More sharing options...
squeek Posted March 10, 2014 Share Posted March 10, 2014 Post the prefab's code. Hard to guess at what the problem could be. Link to comment https://forums.kleientertainment.com/forums/topic/32562-custom-container-error/#findComment-428374 Share on other sites More sharing options...
JackSlender Posted March 15, 2014 Author Share Posted March 15, 2014 Sorry it took me so long to get back. The problem is actually with the equipslot. For some odd reason, it doesn't act the same way if you equip it in the hand slot rather than the body slot. If anyone knows how to fix this, please tell me. Link to comment https://forums.kleientertainment.com/forums/topic/32562-custom-container-error/#findComment-432188 Share on other sites More sharing options...
squeek Posted March 15, 2014 Share Posted March 15, 2014 Can't do much without being able to see the code. Link to comment https://forums.kleientertainment.com/forums/topic/32562-custom-container-error/#findComment-432349 Share on other sites More sharing options...
JackSlender Posted March 16, 2014 Author Share Posted March 16, 2014 Yeah, sorry about that. The file should be attached. By the way, warner is a component. Link to comment https://forums.kleientertainment.com/forums/topic/32562-custom-container-error/#findComment-432567 Share on other sites More sharing options...
squeek Posted March 16, 2014 Share Posted March 16, 2014 Yeah, sorry about that. The file should be attached. By the way, warner is a component.The forum gives me the error: "You do not have permission to view this attachment." when I try to download the attachment. I can still download other attachments, so I'm not sure what's up. Link to comment https://forums.kleientertainment.com/forums/topic/32562-custom-container-error/#findComment-432630 Share on other sites More sharing options...
JackSlender Posted March 16, 2014 Author Share Posted March 16, 2014 Strange. I'll just post it here then. Another thing about this: I tried switching the code to use the body slot and it worked fine. The hand slot must not initialize the item in the same way on start up.local Assets ={ Asset("ANIM", "anim/myprefab.zip"), Asset("ANIM", "anim/swap_myprefab.zip"), Asset("ATLAS", "images/inventoryimages/myprefab.xml"),}local slotpos = {}for y = 0, 3 do table.insert(slotpos, Vector3(0, -y*75 + 114 ,0))endlocal widgetbuttoninfo = { text = "Scan", position = Vector3(0, -165, 0), fn = function(inst) inst.components.warner:Scan() end,}local function onnear(inst) if not inst.components.inventoryitem:IsHeld() then inst:DoTaskInTime(3, function() scared=false end) inst.components.talker:Say("You came back!") inst.AnimState:PushAnimation("idle_happy_hold", true) endendlocal function onfar(inst) inst.components.talker:Say("Come back!") inst.AnimState:PushAnimation("idle_scared", true)endlocal function OnInv(inst) inst.components.talker:IgnoreAll()endlocal function OnDrop(inst) inst.components.talker:StopIgnoringAll()endlocal function OnSave(inst)endlocal function OnLoad(inst, data) local owner = inst.components.inventoryitem.owner if inst.components.inventoryitem:IsHeld() then inst.components.talker:IgnoreAll() elseif inst.components.equippable:IsEquipped() then inst.components.talker:StopIgnoringAll() elseif not inst.components.inventoryitem:IsHeld() then inst.components.talker:StopIgnoringAll() endendlocal function fn(Sim) local function OnEquip(inst, owner) owner.AnimState:OverrideSymbol("swap_object", "swap_myprefab", "swap_myprefab") owner.AnimState:Show("ARM_carry") owner.AnimState:Hide("ARM_normal") inst.components.container:Open(owner) inst.components.talker:StopIgnoringAll() inst.components.talker.offset = Vector3(0,-350,0) inst.components.talker.fontsize = 28 inst.components.talker:Say("Let's go!") owner.components.inventory:SetOverflow(inst) end local function OnUnequip(inst, owner) inst.task = nil owner.AnimState:Hide("ARM_carry") owner.AnimState:Show("ARM_normal") inst.components.talker.offset = Vector3(0,-100,0) inst.components.talker.fontsize = 20 owner.components.inventory:SetOverflow(nil) inst.components.container:Close(owner) inst.components.talker:IgnoreAll() end local inst = CreateEntity() inst.entity:AddTransform() inst.entity:AddAnimState() inst.entity:AddSoundEmitter() inst.isHolding = false MakeInventoryPhysics(inst) inst.AnimState:SetBank("myprefab") inst.AnimState:SetBuild("myprefab") inst.AnimState:SetScale(1.3, 1.3, 1.3) inst.AnimState:PlayAnimation("idle_happy", true) inst:AddComponent("talker") inst.components.talker.fontsize = 20 inst.components.talker.font = TALKINGFONT inst.components.talker.colour = Vector3(75/255, 150/255, 75/255) inst.components.talker.offset = Vector3(0,-100,0) inst:AddComponent("inventoryitem") inst.components.inventoryitem.atlasname = "images/inventoryimages/myprefab.xml" inst.components.inventoryitem:SetOnPickupFn(OnInv) inst.components.inventoryitem:SetOnDroppedFn(OnDrop) inst:AddComponent("equippable") inst.components.equippable.equipslot = EQUIPSLOTS.HANDS inst.components.equippable:SetOnEquip( OnEquip ) inst.components.equippable:SetOnUnequip( OnUnequip ) inst:AddComponent("inspectable") inst:AddComponent("playerprox") inst.components.playerprox:SetDist(4, 7) inst.components.playerprox:SetOnPlayerNear(onnear) inst.components.playerprox:SetOnPlayerFar(onfar) inst:AddComponent("container") inst.components.container:SetNumSlots(#slotpos) inst.components.container.widgetslotpos = slotpos inst.components.container.widgetanimbank = "ui_cookpot_1x4" inst.components.container.widgetanimbuild = "ui_cookpot_1x4" inst.components.container.widgetpos = Vector3(-330,-330,0) inst.components.container.side_widget = true inst.components.container.side_align_tip = 100 inst.components.container.widgetbuttoninfo = widgetbuttoninfo local function good(inst) inst.components.talker:Say("Hey! There's a boon around here!") end local function bad(inst) inst.components.talker:Say("Watch out! There's a monster around here!") end local function nothing(inst) inst.components.talker:Say("There's nothing interesting around here...") end local function king(inst) inst.components.talker:Say("I think the pig king is around here!") end local function den(inst) inst.components.talker:Say("There's a monster den around here! Be careful!") end inst:AddComponent("warner") inst.components.warner:SetOnFoundGoodFn(good) inst.components.warner:SetOnFoundBadFn(bad) inst.components.warner:SetOnFoundNothingFn(nothing) inst.components.warner:SetOnFoundDenFn(den) inst.components.warner:SetOnFoundKingFn(king) inst:ListenForEvent("donetalking", function() inst.SoundEmitter:KillSound("talk") end) inst:ListenForEvent("ontalk", function() inst.SoundEmitter:PlaySound("dontstarve/characters/woodie/lucytalk_LP", "talk") end) inst.OnLoad = OnLoad return instendSTRINGS.NAMES.MYPREFAB = "prefab"STRINGS.CHARACTERS.GENERIC.DESCRIBE.MYPREFAB = "Prefab! I'll never lose you!"return Prefab( "common/inventory/myprefab", fn, Assets) Link to comment https://forums.kleientertainment.com/forums/topic/32562-custom-container-error/#findComment-432718 Share on other sites More sharing options...
squeek Posted March 16, 2014 Share Posted March 16, 2014 (edited) I'd put a print statement in your OnEquip callback, something like: print("OnEquip called for "..tostring(inst).." owned by "..tostring(owner))Then load the game and try to find that line either in the console log or log.txt. If it shows up, then you know the problem is inside your OnEquip callback somewhere. If it doesn't then you know that the problem is somewhere in the equippable/inventory components. Edited March 16, 2014 by squeek Link to comment https://forums.kleientertainment.com/forums/topic/32562-custom-container-error/#findComment-432929 Share on other sites More sharing options...
JackSlender Posted March 16, 2014 Author Share Posted March 16, 2014 (edited) Yeah, it calls it. The problem is something with the Open function of the container. Don't quite know what, though. EDIT: I think I've found a solution. When I call the Open function with a slight delay (DoTaskInTime) it seems to work. My guess is that the prefab needs a second to initialize itself before it can properly get the owner of the prefab to execute the function properly with. Thanks for all your help, btw. Edited March 16, 2014 by JackSlender Link to comment https://forums.kleientertainment.com/forums/topic/32562-custom-container-error/#findComment-433037 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