Jump to content

Tree planting sanity gain for a mod character


Recommended Posts

So I'm trying to work on a mod character, cool yeah. I've gotten it so far to be stable and was thinking on how this character, who will end up losing sanity by the bunches, could gain back some.
I was told to try the pinecone planting thing Woodie has but so far cannot seen to get the coding to work right.

Woodie's Code:

local function ondeployitem(inst, data)
    if data.prefab == "pinecone" or data.prefab == "acorn" then
        --inst.components.beaverness:DoDelta(TUNING.WOODIE_PLANT_TREE_GAIN)
        inst.components.sanity:DoDelta(TUNING.SANITY_TINY)
    end
end

Character Code:
(This is currently under the    local master_postinit = function(inst)  I tried it elsewhere with similar issues of it just not working.)

    inst.ondeployitem = function(inst)
        if data.prefab == "pinecone" or data.prefab == "acorn" then
            --inst.components.beaverness:DoDelta(TUNING.WOODIE_PLANT_TREE_GAIN)
            inst.components.sanity:DoDelta(TUNING.SANITY_TINY)
        end
    end

I had made minor edits in hopes it would work. There's no crashing but it simply is just not working.

Any tips? :(

Link to comment
Share on other sites

1 hour ago, Muche said:

Woodie uses the ondeployitem function by calling inst:ListenForEvent("deployitem", ondeployitem); how are you referencing the function in your character's code?

Written above currently under the characters prefab sheet. I'll try the   listenforevent   code later and report if anything changes. Thank you for some info! :D  

Link to comment
Share on other sites

11 hours ago, Muche said:

Woodie uses the ondeployitem function by calling inst:ListenForEvent("deployitem", ondeployitem); how are you referencing the function in your character's code?

Sadly still not working. I've tried rewording the code a few times and move it around the file.

My current code is:

    inst:ListenForEvent("deployitem", function()
        if data.prefab == "pinecone" or data.prefab == "acorn" then
            inst.components.sanity:DoDelta(TUNING.SANITY_TINY)
        end

I had also kept the ondeplyitem in the parenthesis and also tried having the deploy item and such underneath. Both times I was told it was not declared.
----------------------------------------------

Instead what I did was found another mod where a character could plant things for sanity. It currently works and it's customizable. :D

Spoiler

 local PlantList = {
    pinecone = {sanity = 5},
    acorn = {sanity = 10},
    dug_sapling = {sanity = 5}}
    function lucondeploy(inst, pt, deployer)
        if deployer and deployer:HasTag("lumberjane") then --If the person planting the thing is a lumberjane
            for k,v in pairs(PlantList) do
                if k == inst.prefab then
                    if deployer.components.sanity then
                        deployer.components.sanity:DoDelta(v.sanity) --then raise the sanity
                    end
                end
            end
        end
    end
    function DeployReplacementFunc(inst)
        local old = inst.components.deployable.ondeploy
        if inst.components.deployable then
            inst.components.deployable.ondeploy =
                function(inst,pt,deployer)
                    lucondeploy(inst,pt,deployer)
                    if old then
                        old(inst,pt,deployer)
                    end
                end
        end
    end
    for k,v in pairs(PlantList) do
        AddPrefabPostInit(k,DeployReplacementFunc)
    end

  

 

Link to comment
Share on other sites

12 minutes ago, osmRhodey said:

Sadly still not working. I've tried rewording the code a few times and move it around the file.

My current code is:


    inst:ListenForEvent("deployitem", function()
        if data.prefab == "pinecone" or data.prefab == "acorn" then
            inst.components.sanity:DoDelta(TUNING.SANITY_TINY)
        end

I had also kept the ondeplyitem in the parenthesis and also tried having the deploy item and such underneath. Both times I was told it was not declared.

deployitem event is being fired in Deployable:Deploy by

deployer:PushEvent("deployitem", { prefab = prefab })

EntityScript translates it into calling your function with parameters (deployer, { prefab = prefab }). Your function takes no parameters (i.e. ignores them). Try

inst:ListenForEvent("deployitem", function(inst, data)
    if data.prefab == "pinecone" or data.prefab == "acorn" then
        inst.components.sanity:DoDelta(TUNING.SANITY_TINY)
    end
end)

 

Link to comment
Share on other sites

23 minutes ago, Muche said:

deployitem event is being fired in Deployable:Deploy by


deployer:PushEvent("deployitem", { prefab = prefab })

EntityScript translates it into calling your function with parameters (deployer, { prefab = prefab }). Your function takes no parameters (i.e. ignores them). Try


inst:ListenForEvent("deployitem", function(inst, data)
    if data.prefab == "pinecone" or data.prefab == "acorn" then
        inst.components.sanity:DoDelta(TUNING.SANITY_TINY)
    end
end)

 

I posted it into the prefab, assuming it was meant like this

deployer:PushEvent("deployitem", { prefab = prefab })    
    inst:ListenForEvent("deployitem", function(inst, data)
    if data.prefab == "pinecone" or data.prefab == "acorn" then
        inst.components.sanity:DoDelta(TUNING.SANITY_TINY)
    end
end)

and it still states it is not declared. for now I might just stick with the current coding I had found seeing as it works. :(
If any new information comes up or any new ideas I'm all ears.

Link to comment
Share on other sites

14 minutes ago, osmRhodey said:

I posted it into the prefab, assuming it was meant like this


deployer:PushEvent("deployitem", { prefab = prefab })    
    inst:ListenForEvent("deployitem", function(inst, data)
    if data.prefab == "pinecone" or data.prefab == "acorn" then
        inst.components.sanity:DoDelta(TUNING.SANITY_TINY)
    end
end)

and it still states it is not declared. for now I might just stick with the current coding I had found seeing as it works. :(
If any new information comes up or any new ideas I'm all ears.

Oh my.

If you use this in your prefab like that, of course destroyer and prefab will not be declared. They are declared in Deployable:Deploy.

inst:ListenForEvent("deployitem", function(inst, data)
    if data.prefab == "pinecone" or data.prefab == "acorn" then
        inst.components.sanity:DoDelta(TUNING.SANITY_TINY)
    end
end)

should be enough. Or, if you're feeling fancy and want it to look like it is used for Woodie

local function ondeployitem(inst, data)
    if data.prefab == "pinecone" or data.prefab == "acorn" then
        inst.components.sanity:DoDelta(TUNING.SANITY_TINY)
    end
end

inst:ListenForEvent("deployitem", ondeployitem)

 

Edited by Muche
Link to comment
Share on other sites

Thank you actually! Much smaller than what I had! :)

This is now what I'm using and it works fine!

	inst:ListenForEvent("deployitem", function(inst, data)
		if data.prefab == "pinecone" or data.prefab == "dug_sapling" then
        inst.components.sanity:DoDelta(TUNING.SANITY_TINY)
		end
		if data.prefab == "acorn" then
		inst.components.sanity:DoDelta(10)
		end
	end)

 

Now i return back to looking for the coding for the woodcutter tag. :'(
Thanks again!

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