zUsername Posted January 21, 2016 Share Posted January 21, 2016 My problem is: - Item in Inventory auto drop on load. More details: I put item in inventory then Save & Quit. Then I going to load my saved game again and my item drop on the ground instead of staying in my inventory. Here my code: local function ondeploy(inst, pt, deployer) local pot = SpawnPrefab("portablecookpot") if pot ~= nil then pt = Vector3(pt.x, 0, pt.z) pot.Physics:SetCollides(false) pot.Physics:Teleport(pt.x, pt.y, pt.z) pot.Physics:SetCollides(true) --pot.Transform:SetPosition(pt:Get()) pot.AnimState:PlayAnimation("place") pot.AnimState:PlayAnimation("idle_empty", false) pot.SoundEmitter:PlaySound("dontstarve/common/place_structure_stone") inst:Remove() end end local function item_droppedfn(inst) if inst.components.deployable and inst.components.deployable:CanDeploy(inst:GetPosition()) then inst.components.deployable:Deploy(inst:GetPosition(), inst) end end local function itemfn(Sim) local inst = CreateEntity() inst.entity:AddTransform() inst.entity:AddAnimState() inst.entity:AddNetwork() inst.entity:AddMiniMapEntity() MakeInventoryPhysics(inst) inst:AddTag("irreplaceable") inst.AnimState:SetBank("cook_pot_warly") inst.AnimState:SetBuild("cook_pot_warly") inst.AnimState:PlayAnimation("idle_empty") inst.MiniMapEntity:SetIcon("portablecookpot.tex") if not TheWorld.ismastersim then return inst end inst.entity:SetPristine() inst:AddComponent("inspectable") inst:AddComponent("inventoryitem") inst.components.inventoryitem:SetOnDroppedFn(item_droppedfn) inst.components.inventoryitem.imagename = "portablecookpot" inst.components.inventoryitem.atlasname = "images/inventoryimages/portablecookpot.xml" inst:AddComponent("deployable") inst.components.deployable:SetDeployMode(DEPLOYMODE.DEFAULT) inst.components.deployable.ondeploy = ondeploy MakeHauntableLaunch(inst) return inst end Thanks in advance. Link to comment Share on other sites More sharing options...
zUsername Posted January 21, 2016 Author Share Posted January 21, 2016 (edited) Please help me. Edited January 21, 2016 by zUsername Link to comment Share on other sites More sharing options...
Muche Posted January 21, 2016 Share Posted January 21, 2016 That's because your item is irreplaceable. From prefabs/player_common.lua: --Player cleanup usually called just before save/delete --just before the the player entity is actually removed local function OnDespawn(inst) ... inst.components.inventory:DropEverythingWithTag("irreplaceable") ... end Everything with that tag is not saved with the player, it drops from the inventory to the ground upon despawning/quitting. If it were on dedicated server, another player could find it on the ground and take it (temporarily until their despawning/quitting). Link to comment Share on other sites More sharing options...
zUsername Posted January 21, 2016 Author Share Posted January 21, 2016 2 hours ago, Muche said: That's because your item is irreplaceable. From prefabs/player_common.lua: --Player cleanup usually called just before save/delete --just before the the player entity is actually removed local function OnDespawn(inst) ... inst.components.inventory:DropEverythingWithTag("irreplaceable") ... end Everything with that tag is not saved with the player, it drops from the inventory to the ground upon despawning/quitting. If it were on dedicated server, another player could find it on the ground and take it (temporarily until their despawning/quitting). Thanks you very much. BIG THANKS. Link to comment 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