Jump to content

Easy Peasy Question

Recommended Posts

So this is probably a simple fix but I'm silly :indecisiveness:


As a host, When I drop this item on the floor it goes into the idle position as most items do.

As a client, When the item is dropped it WHOOSHES across the floor, and rockets out of your screen for some reason.


Why does it whosh away in the wind?


The code bit:

local assets={    Asset("ANIM", "anim/arcwand.zip"),    Asset("ANIM", "anim/swap_arcwand.zip"),     Asset("ATLAS", "images/inventoryimages/arcwand.xml"),    Asset("IMAGE", "images/inventoryimages/arcwand.tex"),}prefabs = {	"staff",	"staffcastfx",    "stafflight",}local function createlight(staff, target, pos)    local light = SpawnPrefab("stafflight")    light.Transform:SetPosition(pos:Get())    local caster = staff.components.inventoryitem.owner    if caster ~= nil and caster.components.sanity ~= nil then        caster.components.sanity:DoDelta(-TUNING.SANITY_MEDLARGE)    endendlocal function yellow_reticuletargetfn()    return Vector3(ThePlayer.entity:LocalToWorldSpace(5, 0, 0))endlocal function fn()     local function OnEquip(inst, owner)        owner.AnimState:OverrideSymbol("swap_object", "swap_arcwand", "swap_arcwand")        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()    local sound = inst.entity:AddSoundEmitter()    MakeInventoryPhysics(inst)		inst.entity:AddTransform()	inst.entity:AddAnimState()	inst.entity:AddSoundEmitter()    inst.entity:AddNetwork()    	inst:AddTag("arcwand")	    inst:AddComponent("reticule")    inst.components.reticule.targetfn = yellow_reticuletargetfn    inst.components.reticule.ease = true    if not TheWorld.ismastersim then        return inst    end         anim:SetBank("arcwand")    anim:SetBuild("arcwand")    anim:PlayAnimation("idle")		inst.fxcolour = {223/255, 208/255, 69/255}    inst.castsound = "dontstarve/common/staffteleport"		inst.entity:AddLight()    inst.Light:Enable(true)    inst.Light:SetRadius(1)    inst.Light:SetFalloff(.6)    inst.Light:SetIntensity(0.9)    inst.Light:SetColour(255/255,49/255,153/255)     inst:AddComponent("inspectable")         inst:AddComponent("inventoryitem")    inst.components.inventoryitem.imagename = "arcwand"    inst.components.inventoryitem.atlasname = "images/inventoryimages/arcwand.xml"		inst:AddComponent("spellcaster")    inst.components.spellcaster:SetSpellFn(createlight)    inst.components.spellcaster.canuseonpoint = true         inst:AddComponent("equippable")    inst.components.equippable:SetOnEquip( OnEquip )    inst.components.equippable:SetOnUnequip( OnUnequip )		inst:AddTag("sharp")		inst:AddComponent("weapon")    inst.components.weapon:SetDamage(45)		if not inst.components.characterspecific then    inst:AddComponent("characterspecific")end		inst.components.characterspecific:SetOwner("arc")    inst.components.characterspecific:SetStorable(true)    inst.components.characterspecific:SetComment("This seems heavier than they look.")     return instendreturn  Prefab("common/inventory/arcwand", fn, assets, prefabs)

Link to comment
Share on other sites

@rons0n, Hmm... not totally sure why that's happening, but I do remember seeing this problem before. You could move the SetBank, SetBuild, PlayAnimation part above the "not TheWorld.ismastersim" part. You should also be calling inst.entity:SetPristine() after that.


Another thing to note is that the characterspecific component doesn't actually do anything right now and will be disappearing when the RoG branch gets merged.

Link to comment
Share on other sites

@rezecib Thanks for the reply!


But all your suggestions above did not unfortunately fix the client having her item swooped away into who-knows-what. I wonder why it would do this? I will do further testing and see what I can do.


On regards on the characterspecific component, I'm using Ksizor's custom one that makes it unable to be grabbed by anyone but the specified character.

Link to comment
Share on other sites

@rezecib, I applied the changes you suggested and it still flies in the wind. Rocketing out of orbit.


I guess my alternative is: Is there a way that when you drop your item you immediately pick it back up? Or cannot be dropped at all?

It's better than nothing haha

Link to comment
Share on other sites

@rons0n, I would try rebuilding it piece-wise. So start with a copy of the spear prefab, for example, and gradually change pieces. Best case, it completely eliminates the flying away issue, and worst case it tells you which piece of code is actually causing it.

Link to comment
Share on other sites

@rezecib, So a funny story...


I added everything bit by bit and sadly nothing prevailed.


I decided to give my item 'finite uses' and now the staff no longer speeds off to a distance. This was progress! But I wanted my staff to have infinite uses..and funny enough, It did?


I was spamming her spell, draining the uses of the staff. When it finally reached 0%, I could still spam the spell regardless.

So I'm not sure if this qualifies as a fix...lol

Edited by rons0n
Link to comment
Share on other sites

@rons0n, That's really strange o_o. Um.... maybe something in Ksizor's characterspecific component interacts with finiteuses in some way? I haven't worked with it. You could try setting the consumption of using it to zero? Although it will always display 100%.

Link to comment
Share on other sites

I cloned the yellow staff:

local assets = {	Asset("ANIM", "anim/staffs.zip"),	Asset("ANIM", "anim/swap_staffs.zip")}local prefabs = {	"staffcastfx",	"stafflight"}local function fn()	local inst = CreateEntity()	inst.entity:AddTransform()	inst.entity:AddAnimState()	inst.entity:AddSoundEmitter()	inst.entity:AddNetwork()	MakeInventoryPhysics(inst)	inst.AnimState:SetBank("staffs")	inst.AnimState:SetBuild("staffs")	inst.AnimState:PlayAnimation("yellowstaff")	inst:AddTag("nopunch")	inst:AddTag("sharp")	if not TheWorld.ismastersim then		return inst	end	inst.entity:SetPristine()		inst.fxcolour = {223/255, 208/255, 69/255}	inst.castsound = "dontstarve/common/staffteleport"		inst:AddComponent("equippable")	inst.components.equippable:SetOnEquip(function(inst, owner) 		owner.AnimState:OverrideSymbol("swap_object", "swap_staffs", "yellowstaff")		owner.AnimState:Show("ARM_carry") 		owner.AnimState:Hide("ARM_normal") 	end)	inst.components.equippable:SetOnUnequip(function(inst, owner)		owner.AnimState:Hide("ARM_carry")		owner.AnimState:Show("ARM_normal")	end)	inst:AddComponent("finiteuses")    inst.components.finiteuses:SetMaxUses(TUNING.YELLOWSTAFF_USES)    inst.components.finiteuses:SetUses(TUNING.YELLOWSTAFF_USES)	inst.components.finiteuses:SetOnFinished(function(inst)		inst.SoundEmitter:PlaySound("dontstarve/common/gem_shatter")		inst:Remove()	end)    inst:AddComponent("inventoryitem")	inst.components.inventoryitem.imagename = "yellowstaff"		inst:AddComponent("inspectable")	    inst:AddComponent("reticule")    inst.components.reticule.targetfn = function()		return Vector3(ThePlayer.entity:LocalToWorldSpace(5, 0, 0))	end    inst.components.reticule.ease = true		inst:AddComponent("spellcaster")	inst.components.spellcaster.canuseonpoint = true	inst.components.spellcaster:SetSpellFn(function(staff, target, pos)		local light = SpawnPrefab("stafflight")		light.Transform:SetPosition(pos:Get())		staff.components.finiteuses:Use(1)		local caster = staff.components.inventoryitem.owner		if caster and caster.components.sanity then			caster.components.sanity:DoDelta(-TUNING.SANITY_MEDLARGE)		end	end)		inst:AddComponent("weapon")	inst.components.weapon:SetDamage(45)		MakeHauntableLaunch(inst)	return instendreturn Prefab("common/inventory/copystaff", fn, assets, prefabs)


And nothing fast traveled away.

Link to comment
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

  • Create New...