Jump to content

Recommended Posts

When you want to perform a function when an event happens, you wanna look for the component that pushes the event, then have your character listen for it. For example, listening for the eating event would be inst:ListenForEvent("oneat"), functionname). I couldnt find the events you are looking for cuz im kinda dumb when it comes to components, but maybe this information can help.
If you find the event, you can put this in the master_postinit

Quote

 

    inst:ListenForEvent("eventname", function(inst, data)

        inst.components.hunger:DoDelta(-1)

    end)

 


I think if you give your character the tag inst:AddTag("hungrybuilder") in the common_postinit it will make them lose hunger when building

Try adding this into your character prefab:

local function OnWork(inst, data)
	if data.action.action == ACTIONS.CHOP or
		data.action.action == ACTIONS.MINE or
		data.action.action == ACTIONS.HAMMER or
		data.action.action == ACTIONS.DIG or
		data.action.action == ACTIONS.TILL
	then
		inst.components.hunger:DoDelta(-1)
	end
end

local function onbecamehuman(inst, data)
	inst:ListenForEvent("performaction", OnWork)
end

local function onbecameghost(inst, data)
	inst:ListenForEvent("performaction", OnWork)
end

local function master_postinit(inst)
	-- . . .
  

	inst:ListenForEvent("performaction", OnWork)
	inst:ListenForEvent("ms_respawnedfromghost", onbecamehuman)
	inst:ListenForEvent("ms_becameghost", onbecameghost)
end

(snippet modified from Uncompromising Mode's "init\init_character_changes\winona.lua" file.)

The three dots indicate other code you may have there. You can place the event listeners anywhere in the function.

And as Sneaky Axolxtl said, you can also add:

local function common_postinit(inst)
	-- . . .

	inst:AddTag("hungrybuilder")
end

To make the character lose some hunger when building things.

 

Keep in mind that master_postinit and common_postinit are different.

common_postinit runs on server AND client. This is where you add tags and graphics.

master_postinit runs ONLY on server. This is where you add components.

Oh, sorry. I should have tested that.

You could modify it so:

local function OnCooldown(inst)
	inst._cdtask = nil
end

local function OnWork(inst, data)
	local burnrate = inst.components.hunger.burnratemodifiers:Get()

	if
		data.action.action == ACTIONS.CHOP
		or data.action.action == ACTIONS.MINE
		or data.action.action == ACTIONS.HAMMER
		or data.action.action == ACTIONS.DIG
		or data.action.action == ACTIONS.TILL
	then
		if inst._cdtask == nil then
			inst._cdtask = inst:DoTaskInTime(0.3, OnCooldown)
			inst.components.hunger:DoDelta(-1 * burnrate, true)
		end
	end
end

(Snippet again modified from Uncompromising Mode's "init\init_character_changes\winona.lua" file.)

This will make sure -1 hunger applies with at least 0.3 seconds in between. You could mess with the numbers a bit, you could apply a very small hunger debuff but often, or a big hunger debuff but rarely.

Also notice that the hunger debuff here is multiplied by burnrate, so characters that for any reason burn less calories will also burn less while working. Not necessary, but probably good.

 

If you need to expand on this, you can use this for reference:

winona.lua

(Taken from uncompromising mode "\init\init_character_changes\winona.lua")

Winona in Uncompromising Mode consumes hunger when working, just like your character.

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