Sign in to follow this  
reims9875

Why is my subject not working ?

Recommended Posts

reims9875    0

When I play with friends on the same server, the modification is enabled, but when I play one , my item works. As if the subject does not work, it is as if there is no subject.

Here is the item code.

 

local assets=

    Asset("ANIM", "anim/wedge_breeze.zip"),
    Asset("ANIM", "anim/swap_wedge_breeze.zip"), 

    Asset("ATLAS", "images/inventoryimages/wedge_breeze.xml"),
    Asset("IMAGE", "images/inventoryimages/wedge_breeze.tex"),
}

local prefabs = 
{
}

local function fn(colour)

    local function OnEquip(inst, owner)    
        --owner.AnimState:OverrideSymbol("swap_object", "swap_wedge_breezes", "purplestaff")
        owner.AnimState:OverrideSymbol("swap_object", "swap_wedge_breeze", "wedge_breeze")
        owner.AnimState:Show("ARM_carry") 
        owner.AnimState:Hide("ARM_normal")
end

    local function OnUnequip(inst, owner) 
        owner.AnimState:Hide("ARM_carry") 
        owner.AnimState:Show("ARM_normal") 
    end

    local inst = CreateEntity()
    local trans = inst.entity:AddTransform()
    local anim = inst.entity:AddAnimState()
    MakeInventoryPhysics(inst)
    
    anim:SetBank("wedge_breeze")
    anim:SetBuild("wedge_breeze")
    anim:PlayAnimation("idle")
    
    inst:AddTag("sharp")
    inst:AddTag("pointy")

    --weapon (from weapon component) added to pristine state for optimization
    inst:AddTag("weapon")

     MakeInventoryFloatable(inst, "med", 0.05, {1.1, 0.5, 1.1}, true, -9)

    inst.entity:SetPristine()

    if not TheWorld.ismastersim then
        return inst
        
    end

    inst:AddComponent("weapon")
    inst.components.weapon:SetDamage(TUNING.SPIKE_DAMAGE)

    -------

    inst:AddComponent("finiteuses")
    inst.components.finiteuses:SetMaxUses(TUNING.GLASSCUTTER.USES)
    inst.components.finiteuses:SetUses(TUNING.GLASSCUTTER.USES)
    
    inst.components.finiteuses:SetOnFinished(inst.Remove)

    inst.components.finiteuses:SetOnFinished(inst.Remove)

    inst:AddComponent("inspectable")
    
    inst:AddComponent("inventoryitem")

    inst.components.inventoryitem.imagename = "wedge_breeze"
    inst.components.inventoryitem.atlasname = "images/inventoryimages/wedge_breeze.xml"
    
    inst:AddComponent("equippable")
    inst.components.equippable:SetOnEquip( OnEquip )
    inst.components.equippable:SetOnUnequip( OnUnequip )
    inst.components.equippable.dapperness = TUNING.CRAZINESS_MED
    inst.components.equippable.is_magic_dapperness = true

    return inst
end

return  Prefab("common/inventory/wedge_breeze", fn, assets, prefabs)

 

Edited by reims9875

Share this post


Link to post
Share on other sites
HarryPPP    14

Hm, I couldn't quite understand, but I think I know what you mean...

As I can see, this code seems very similar to how they did on Don't Starve, which is pretty deprecated. I've updated the code to how it's written in Don't Starve Together, and also fixed your problem.

For an item to work on servers, you need to add "inst.entity:AddNetwork()" to your file. I've already done it below, you can just copy the code and it should work...

local assets=
{ 
    Asset("ANIM", "anim/wedge_breeze.zip"),
    Asset("ANIM", "anim/swap_wedge_breeze.zip"), 

    Asset("ATLAS", "images/inventoryimages/wedge_breeze.xml"),
    Asset("IMAGE", "images/inventoryimages/wedge_breeze.tex"),
}

local prefabs = 
{
}

local function OnEquip(inst, owner)    
	--owner.AnimState:OverrideSymbol("swap_object", "swap_wedge_breezes", "purplestaff")
	owner.AnimState:OverrideSymbol("swap_object", "swap_wedge_breeze", "wedge_breeze")
	owner.AnimState:Show("ARM_carry") 
	owner.AnimState:Hide("ARM_normal")
end

local function OnUnequip(inst, owner) 
	owner.AnimState:Hide("ARM_carry") 
	owner.AnimState:Show("ARM_normal") 
end

local function fn()
	local inst = CreateEntity()

    inst.entity:AddTransform()
    inst.entity:AddAnimState()
    inst.entity:AddNetwork()
	
	MakeInventoryPhysics(inst)
    
	inst.AnimState:SetBank("wedge_breeze")
	inst.AnimState:SetBuild("wedge_breeze")
	inst.AnimState:PlayAnimation("idle")
    
	inst:AddTag("sharp")
	inst:AddTag("pointy")

	--weapon (from weapon component) added to pristine state for optimization
	inst:AddTag("weapon")

	MakeInventoryFloatable(inst, "med", 0.05, {1.1, 0.5, 1.1}, true, -9)

	inst.entity:SetPristine()

	if not TheWorld.ismastersim then
		return inst
	end

	inst:AddComponent("weapon")
	inst.components.weapon:SetDamage(TUNING.SPIKE_DAMAGE)

    -------

	inst:AddComponent("finiteuses")
	inst.components.finiteuses:SetMaxUses(TUNING.GLASSCUTTER.USES)
	inst.components.finiteuses:SetUses(TUNING.GLASSCUTTER.USES)
	inst.components.finiteuses:SetOnFinished(inst.Remove)

	inst:AddComponent("inspectable")
    
	inst:AddComponent("inventoryitem")
	inst.components.inventoryitem.imagename = "wedge_breeze"
	inst.components.inventoryitem.atlasname = "images/inventoryimages/wedge_breeze.xml"
    
	inst:AddComponent("equippable")
	inst.components.equippable:SetOnEquip( OnEquip )
	inst.components.equippable:SetOnUnequip( OnUnequip )
	inst.components.equippable.dapperness = TUNING.CRAZINESS_MED
	inst.components.equippable.is_magic_dapperness = true

	return inst
end

return Prefab("wedge_breeze", fn, assets, prefabs)

If you have any more questions, don't mind asking!

Edited by HarryPPP

Share this post


Link to post
Share on other sites

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
Sign in to follow this