KirbyJParasol Posted July 25, 2017 Share Posted July 25, 2017 Not sure why, but this hat disappears when I equip it. The graphics show me wearing it, but it's not in my toolbar. Furthermore, if I equip another hat, the first just disappears. Any idea what part of this code is breaking? local assets= { Asset("ANIM", "anim/hat_ushanka.zip"), Asset("IMAGE", "images/inventoryimages/hat_ushanka.tex"), Asset("ATLAS", "images/inventoryimages/hat_ushanka.xml") } local function onequip(inst, owner) owner.AnimState:OverrideSymbol("swap_hat", "hat_ushanka", "swap_hat") owner.AnimState:Show("HAT") owner.AnimState:Show("HEAD_HAT") owner.AnimState:Hide("HAIR_NOHAT") owner.AnimState:Hide("HAIR") if owner:HasTag("player") then owner.AnimState:Hide("HEAD") owner.AnimState:Show("HEAD_HAT") end if inst.components.fueled then inst.components.fueled:StartConsuming() end end local function onunequip(inst, owner) owner.AnimState:Hide("HAT") owner.AnimState:Hide("HEAD_HAT") owner.AnimState:Show("HAIR_NOHAT") owner.AnimState:Show("HAIR") if owner:HasTag("player") then owner.AnimState:Show("HEAD") owner.AnimState:Hide("HEAD_HAT") end if inst.components.fueled then inst.components.fueled:StopConsuming() end end local function fn(Sim) local inst = CreateEntity() local trans = inst.entity:AddTransform() local anim = inst.entity:AddAnimState() MakeInventoryPhysics(inst) inst:AddTag("hat") anim:SetBank("strawhat") anim:SetBuild("hat_ushanka") anim:PlayAnimation("anim") inst:AddComponent("inspectable") inst:AddComponent("inventoryitem") inst.components.inventoryitem.imagename = "hat_ushanka" inst.components.inventoryitem.atlasname = "images/inventoryimages/hat_ushanka.xml" inst:AddComponent("equippable") inst.components.equippable.equipslot = EQUIPSLOTS.HEAD inst.components.equippable.dapperness = TUNING.DAPPERNESS_MED inst.components.equippable:SetOnEquip( onequip ) inst.components.equippable:SetOnUnequip( onunequip ) inst:AddComponent("insulator") inst.components.insulator:SetInsulation(TUNING.INSULATION_LARGE) inst:AddComponent("waterproofer") inst.components.waterproofer:SetEffectiveness(TUNING.WATERPROOFNESS_SMALL) inst:AddComponent("fueled") inst.components.fueled.fueltype = FUELTYPE.USAGE inst.components.fueled:InitializeFuelLevel(TUNING.BEEFALOHAT_PERISHTIME) inst.components.fueled:SetDepletedFn(inst.Remove) return inst end return Prefab( "common/inventory/hat_ushanka", fn, assets) Link to comment https://forums.kleientertainment.com/forums/topic/80831-hat-disappears-on-equip/ Share on other sites More sharing options...
ZupaleX Posted July 25, 2017 Share Posted July 25, 2017 Let me guess, this mod comes from standard Don't Starve at the first place? Link to comment https://forums.kleientertainment.com/forums/topic/80831-hat-disappears-on-equip/#findComment-941636 Share on other sites More sharing options...
Lumina Posted July 25, 2017 Share Posted July 25, 2017 (edited) 2 hours ago, KirbyJParasol said: The graphics show me wearing it, but it's not in my toolbar. Usually this kind of problem comes because you don't have an inventory image. If the hat exist, but isn't shown in the toolbar, verify your inventory image (right name, no mispelling, assets declared somewhere, etc). If the hat really disappears, i don't know. Edited July 25, 2017 by Lumina Link to comment https://forums.kleientertainment.com/forums/topic/80831-hat-disappears-on-equip/#findComment-941673 Share on other sites More sharing options...
ZupaleX Posted July 25, 2017 Share Posted July 25, 2017 Actually there is another bigger issue here. There is not check for if the code is run on the client or the host. All the components will be added to the client here and that means big problems. Link to comment https://forums.kleientertainment.com/forums/topic/80831-hat-disappears-on-equip/#findComment-941674 Share on other sites More sharing options...
KirbyJParasol Posted July 25, 2017 Author Share Posted July 25, 2017 (edited) I think this is a port from singleplayer Don't Starve...? I'm trying to make a long unsupported mod actually work right, so I don't know the development process in depth, but I DO know that he released the singleplayer version before the multiplayer. So yeah he probably ported it straight over. The graphics do exist for the toolbar, because sometimes it works right. Just nowhere near consistently. I have no idea how to check for client/host code. Edited July 26, 2017 by KirbyJParasol Link to comment https://forums.kleientertainment.com/forums/topic/80831-hat-disappears-on-equip/#findComment-941699 Share on other sites More sharing options...
ZupaleX Posted July 26, 2017 Share Posted July 26, 2017 Read this post and let me know if it helps Link to comment https://forums.kleientertainment.com/forums/topic/80831-hat-disappears-on-equip/#findComment-941747 Share on other sites More sharing options...
Lumina Posted July 26, 2017 Share Posted July 26, 2017 Also, you will need this line : inst.entity:AddNetwork() After : local anim = inst.entity:AddAnimState() Link to comment https://forums.kleientertainment.com/forums/topic/80831-hat-disappears-on-equip/#findComment-941793 Share on other sites More sharing options...
KirbyJParasol Posted July 29, 2017 Author Share Posted July 29, 2017 (edited) Double posting because my earlier testing was incorrect Edited July 29, 2017 by KirbyJParasol Link to comment https://forums.kleientertainment.com/forums/topic/80831-hat-disappears-on-equip/#findComment-942420 Share on other sites More sharing options...
KirbyJParasol Posted July 29, 2017 Author Share Posted July 29, 2017 Alright, so most of the code works. Hat is working with correct stats, is craftable, doesn't turn invisible, etc. HOWEVER. If I ever drop the hat on the ground, all three other players immediately crash. Here's the code and the error message: local assets= { Asset("ANIM", "anim/hat_ushanka.zip"), Asset("IMAGE", "images/inventoryimages/hat_ushanka.tex"), Asset("ATLAS", "images/inventoryimages/hat_ushanka.xml") } local function onequip(inst, owner) owner.AnimState:OverrideSymbol("swap_hat", "hat_ushanka", "swap_hat") owner.AnimState:Show("HAT") owner.AnimState:Show("HEAD_HAT") owner.AnimState:Hide("HAIR_NOHAT") owner.AnimState:Hide("HAIR") if owner:HasTag("player") then owner.AnimState:Hide("HEAD") owner.AnimState:Show("HEAD_HAT") end if inst.components.fueled then inst.components.fueled:StartConsuming() end end local function onunequip(inst, owner) owner.AnimState:Hide("HAT") owner.AnimState:Hide("HEAD_HAT") owner.AnimState:Show("HAIR_NOHAT") owner.AnimState:Show("HAIR") if owner:HasTag("player") then owner.AnimState:Show("HEAD") owner.AnimState:Hide("HEAD_HAT") end if inst.components.fueled then inst.components.fueled:StopConsuming() end end local function fn(Sim) local inst = CreateEntity() local trans = inst.entity:AddTransform() local anim = inst.entity:AddAnimState() inst.entity:AddNetwork() MakeInventoryPhysics(inst) inst:AddTag("hat") anim:SetBank("strawhat") anim:SetBuild("hat_ushanka") anim:PlayAnimation("anim") if not TheWorld.ismastersim then return inst end inst:AddComponent("inspectable") inst:AddComponent("inventoryitem") inst.components.inventoryitem.imagename = "hat_ushanka" inst.components.inventoryitem.atlasname = "images/inventoryimages/hat_ushanka.xml" inst:AddComponent("equippable") inst.components.equippable.equipslot = EQUIPSLOTS.HEAD inst.components.equippable.dapperness = TUNING.DAPPERNESS_MED inst.components.equippable:SetOnEquip( onequip ) inst.components.equippable:SetOnUnequip( onunequip ) inst:AddComponent("insulator") inst.components.insulator:SetInsulation(TUNING.INSULATION_LARGE) inst:AddComponent("waterproofer") inst.components.waterproofer:SetEffectiveness(TUNING.WATERPROOFNESS_SMALL) inst:AddComponent("fueled") inst.components.fueled.fueltype = FUELTYPE.USAGE inst.components.fueled:InitializeFuelLevel(TUNING.BEEFALOHAT_PERISHTIME) inst.components.fueled:SetDepletedFn(inst.Remove) return inst end return Prefab( "common/inventory/hat_ushanka", fn, assets) Link to comment https://forums.kleientertainment.com/forums/topic/80831-hat-disappears-on-equip/#findComment-942443 Share on other sites More sharing options...
Lumina Posted July 29, 2017 Share Posted July 29, 2017 Try adding : if not TheWorld.ismastersim then return inst end inst.entity:SetPristine() the " inst.entity:SetPristine() " line. I don't think it would avoid the crash but it's probably better to have the line. Link to comment https://forums.kleientertainment.com/forums/topic/80831-hat-disappears-on-equip/#findComment-942459 Share on other sites More sharing options...
ZupaleX Posted July 29, 2017 Share Posted July 29, 2017 (edited) The SetPristine goes before returning the instance when you run on the host usually. Not sure what it's doing exactly because it's a C-side function and we don't have access to it, but my guess considering where and when it appears in the original prefab codes and the name is to say that before this point, the host and client are identical and after that the differences will appear. I don't think it it what cause the deserialization between the host and client, I believe it happens after, but I cannot be certain. Edited July 29, 2017 by ZupaleX Link to comment https://forums.kleientertainment.com/forums/topic/80831-hat-disappears-on-equip/#findComment-942584 Share on other sites More sharing options...
Lumina Posted July 29, 2017 Share Posted July 29, 2017 Yes, i don't know why i have it after and not before, probably a mistake i repeated from somewhere. But the line is important. I don't think it's causing the crash itself, but at the moment i don't see any other difference between my working-and-not-crashing hat in my mod and this one except the pristine line (but i'm bad at seeing errors in code). Link to comment https://forums.kleientertainment.com/forums/topic/80831-hat-disappears-on-equip/#findComment-942586 Share on other sites More sharing options...
ZupaleX Posted July 30, 2017 Share Posted July 30, 2017 (edited) Could you link your complete mod please? The format is painful to look at on the forum page Edited July 30, 2017 by ZupaleX Link to comment https://forums.kleientertainment.com/forums/topic/80831-hat-disappears-on-equip/#findComment-942598 Share on other sites More sharing options...
KirbyJParasol Posted July 30, 2017 Author Share Posted July 30, 2017 (edited) SetPristine did not fix the crash. Note that this is not my personal mod, but another player's mod that has long since been abandoned, which I'm trying to fix. Download link of my most current version: https://www.dropbox.com/s/h2z3x56ro9sz88d/workshop-402531514.zip?dl=0 EDIT: It's worth noting that if I put the ushanka in a chest, and another player opens the chest, he immediately crashes to desktop. Edited July 30, 2017 by KirbyJParasol Link to comment https://forums.kleientertainment.com/forums/topic/80831-hat-disappears-on-equip/#findComment-942627 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