Jump to content

SOLVED: Transforming/Replacing one object with another via trading


Recommended Posts

Hi.

The idea here is for the character - Wort - to be able to "infect" trees by giving them spores, resulting in them being replaced by mushroom trees. Everything was going according to plan until the transformation itself.

I've colored the problem lines red. They're copied from beequeenhive, and searching the forum brought me to an older thread suggesting the very same code for a similar goal. I've tried phrasing it so many ways and no dice. Hoping some fresh eyes might lend their wisdom.

Thanks for reading.

Ah, the dangers of working into the small hours of the morning. The code is fine. The problem is the prefab name for the red mushtree is "mushtree_medium", not "mushroom_tree_medium." I just didn't notice because the line telling me so was above the error message, and my sleep deprived self never looked up.

 

local function TradeSporesPostInit(inst)
if not inst.components.tradable then    inst:AddComponent("tradable")end
end
AddPrefabPostInit("spore_medium", TradeSporesPostInit)

 

local function FungalInfectionPostInit(inst)

local function ShouldAcceptItem(inst, item, giver)
    return item.prefab == "spore_medium"
    and giver.prefab == "wort"
end

local function OnGetItem(inst, giver, item)
    if item ~= nil and item.prefab == "spore_medium" then
        item:Remove()
        
        SpawnPrefab("spat_splash_fx_full").Transform:SetPosition(inst:GetPosition():Get())
        inst.SoundEmitter:PlaySound("dontstarve/creatures/spat/spit_hit")
        inst.SoundEmitter:PlaySound("dontstarve/cave/mushtree_tall_grow_2")
        

    local x, y, z = inst.Transform:GetWorldPosition()
    inst:Remove()

    local infection = SpawnPrefab("mushroom_tree_medium")
    infection.Transform:SetPosition(x, y, z)

    end
end
    inst:AddComponent("trader")
    inst.components.trader:SetAcceptTest(ShouldAcceptItem)
    inst.components.trader.onaccept = OnGetItem
end
AddPrefabPostInit("evergreen", FungalInfectionPostInit)

Edited by Birdskull
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
 Share

×
  • Create New...