Jump to content

Custom Survivor: Adding extra effects on crafting


Recommended Posts

Greetings!

My character will be able to craft Morsel from a Monster Meat. The perks I would like to apply on my custom survivor are:

1) The Morsel should be wet when crafted

2) The crafting survivor should get a small Hunger boost (5 points)

3) The crafting animation should be replaced with eating animation

If you could help me, or even just suggest me a reference for this, my heart would melt to the ground.

Thanks in advance!

Have a great day!

Link to comment
Share on other sites

Hello, I think you can do this

 

in yourcharacter.lua prefab above the master_postinit post this function

local function CraftMeat(inst, data)
	if data.item.prefab == "put the name of your custom meat prefab here" then
		inst.components.hunger:DoDelta(5) -- Gain 5 hunger
	end
end

then inside the master_postinit put this

inst:ListenForEvent("builditem", CraftMeat)

 

for the animation put this in your modmain.lua

AddStategraphPostInit("wilson", function(sg)
	local build = sg.actionhandlers[GLOBAL.ACTIONS.BUILD].deststate
	sg.actionhandlers[GLOBAL.ACTIONS.BUILD].deststate = function(inst, action,...)
		local recipe = action.recipe
		if recipe == "put the name of your custom meat prefab here" then
			return "eat"
		end
		return build(inst, action,...)
	end
end)

 

unfortunately i dont know how to make an item wet hopefully someone else will help you with that very soon cause i would like to know how to do that too

Edited by --- -.-
Link to comment
Share on other sites

@--- -.- Thanks for your help!

I think I've did a whoopsie somewhere, the animation replacement don't works for me.

I've tried it keeping the "wilson" and replacing it with my character's name, both neither of these options resulted with the right animation. May I ask for a quick fix?

Here's the current code:

Spoiler

AddStategraphPostInit("devourer", function(sg)
    local build = sg.actionhandlers[GLOBAL.ACTIONS.BUILD].deststate
    sg.actionhandlers[GLOBAL.ACTIONS.BUILD].deststate = function(inst, action,...)
        local recipe = action.recipe
        if recipe == "healthymonster1" then
            return "eat"
        end
        return build(inst, action,...)
    end
end)

 

Edited by C_Thun
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...