Jump to content

Recommended Posts

I added a custom mod item, but when I save and exit the server, and then re-enter it, the item disappears. The item's prefab is copied from singleplayer don't starve, so I assume there's something save-related that I need to add. Anyone know what is causing this?

As always: We can't fully help without seeing code, we can only offer suggestions as to what the problem could be. Does the item have the pristine stuff added to it? Is the item dropping on save & quit from being marked as an irreplacable item? I can't help with too much off the top of my head, I'm at work here so have none of my own code to look at to see what it could be either

Woops, I was pretty sure I posted it, sorry bout that.

 

local assets=
{
    Asset("ANIM", "anim/brainsword.zip"),
    Asset("ANIM", "anim/swap_brainsword.zip"),
 
    Asset("ATLAS", "images/inventoryimages/brainsword.xml"),
    Asset("IMAGE", "images/inventoryimages/brainsword.tex"),
}
local prefabs = 
{
"brainslash",
}
 
 
local function onattack(inst, owner, target)
        ThePlayer.components.sanity:DoDelta(-15)
inst.components.weapon:SetDamage((ThePlayer.components.sanity and ThePlayer.components.sanity.current or 0)*0.25)
end
 
 
local function fn()
 
    local function OnEquip(inst, owner)
        owner.AnimState:OverrideSymbol("swap_object", "swap_brainsword", "swap_brainsword")
        owner.AnimState:Show("ARM_carry")
        owner.AnimState:Hide("ARM_normal")
owner.components.combat.min_attack_period = 0.7
inst.components.weapon:SetDamage((ThePlayer.components.sanity and ThePlayer.components.sanity.current or 0)*0.25)
    end
 
    local function OnUnequip(inst, owner)
        owner.AnimState:Hide("ARM_carry")
        owner.AnimState:Show("ARM_normal")
owner.components.combat.min_attack_period =  0.5
    end
 
    local inst = CreateEntity()
    local trans = inst.entity:AddTransform()
    local anim = inst.entity:AddAnimState()
    local sound = inst.entity:AddSoundEmitter()
    MakeInventoryPhysics(inst)
     
     anim:SetBank("brainsword")
     anim:SetBuild("brainsword")
     anim:PlayAnimation("idle")
 
inst:AddTag("sharp")
 
    inst:AddComponent("weapon")
inst.components.weapon:SetDamage(0)
    inst.components.weapon:SetRange(4, 6)
    inst.components.weapon.onattack = onattack
 
inst:AddComponent("finiteuses")
    inst.components.finiteuses:SetMaxUses(TUNING.SPEAR_USES)
    inst.components.finiteuses:SetUses(TUNING.SPEAR_USES)
 
    inst.components.finiteuses:SetOnFinished(inst.Remove)
 
 
inst.entity:SetPristine()
 
    if not TheWorld.ismastersim then
        return inst
    end
 
    inst:AddComponent("inspectable")
 
    inst:AddComponent("inventoryitem")
    inst.components.inventoryitem.imagename = "brainsword"
    inst.components.inventoryitem.atlasname = "images/inventoryimages/brainsword.xml"
     
    inst:AddComponent("equippable")
    inst.components.equippable:SetOnEquip( OnEquip )
    inst.components.equippable:SetOnUnequip( OnUnequip )
 
    inst.components.weapon:SetProjectile("brainslash")
 
    MakeHauntableLaunch(inst)
 
    return inst
end
 
 
return  Prefab("common/inventory/brainsword", fn, assets, prefabs)
Edited by AfrostLord
local assets = {	Asset("ANIM", "anim/brainsword.zip"),	Asset("ANIM", "anim/swap_brainsword.zip"),	Asset("ATLAS", "images/inventoryimages/brainsword.xml"),	Asset("IMAGE", "images/inventoryimages/brainsword.tex"),}local prefabs = {	"brainslash",}local function onattack(inst, owner, target)	owner.components.sanity:DoDelta(-15)	inst.components.weapon:SetDamage((owner.components.sanity and owner.components.sanity.current or 0)*0.25)endlocal function OnEquip(inst, owner)	owner.AnimState:OverrideSymbol("swap_object", "swap_brainsword", "swap_brainsword")	owner.AnimState:Show("ARM_carry")	owner.AnimState:Hide("ARM_normal")	owner.components.combat.min_attack_period = 0.7	inst.components.weapon:SetDamage((owner.components.sanity and owner.components.sanity.current or 0)*0.25)endlocal function OnUnequip(inst, owner)	owner.AnimState:Hide("ARM_carry")	owner.AnimState:Show("ARM_normal")	owner.components.combat.min_attack_period = 0.5endlocal function fn()	local inst = CreateEntity()	inst.entity:AddTransform()	inst.entity:AddAnimState()	inst.entity:AddSoundEmitter()	MakeInventoryPhysics(inst)	inst.AnimState:SetBank("brainsword")	inst.AnimState:SetBuild("brainsword")	inst.AnimState:PlayAnimation("idle")	inst:AddTag("sharp")	inst.entity:SetPristine()	if not TheWorld.ismastersim then		return inst	end	inst:AddComponent("weapon")	inst.components.weapon:SetDamage(0)	inst.components.weapon:SetRange(4, 6)	inst.components.weapon.onattack = onattack		inst.components.weapon:SetProjectile("brainslash")	inst:AddComponent("finiteuses")	inst.components.finiteuses:SetMaxUses(TUNING.SPEAR_USES)	inst.components.finiteuses:SetUses(TUNING.SPEAR_USES)	inst.components.finiteuses:SetOnFinished(inst.Remove)	inst:AddComponent("inspectable")	inst:AddComponent("inventoryitem")	inst.components.inventoryitem.atlasname = "images/inventoryimages/brainsword.xml"	inst.components.inventoryitem.imagename = "brainsword"	inst:AddComponent("equippable")	inst.components.equippable:SetOnEquip( OnEquip )	inst.components.equippable:SetOnUnequip( OnUnequip )	MakeHauntableLaunch(inst)	return instendreturn Prefab("common/inventory/brainsword", fn, assets, prefabs)

 

Also, are you testing in a dedicated server?

If you do a c_spawn and don't press Ctrl to make "REMOTE:" appear, you will spawn the sword, but only client side.

So when the server restarts, or you exit and reenter, it won't be there.

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