GRNNOperator Posted September 14, 2023 Share Posted September 14, 2023 (edited) For example: Lose 1 hunger everytime you chop, mine, pick, hammer, etc. I've searched it up and found no results. Edited September 14, 2023 by GRNNOperator Only tried 2 methods but none of them worked. Link to comment https://forums.kleientertainment.com/forums/topic/150958-how-do-i-make-a-character-lose-hunger-when-working/ Share on other sites More sharing options...
Sneaky Axolxtl Posted September 15, 2023 Share Posted September 15, 2023 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 Link to comment https://forums.kleientertainment.com/forums/topic/150958-how-do-i-make-a-character-lose-hunger-when-working/#findComment-1665185 Share on other sites More sharing options...
Hamurlik Posted September 15, 2023 Share Posted September 15, 2023 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. Link to comment https://forums.kleientertainment.com/forums/topic/150958-how-do-i-make-a-character-lose-hunger-when-working/#findComment-1665223 Share on other sites More sharing options...
GRNNOperator Posted September 15, 2023 Author Share Posted September 15, 2023 Thank you for helping! I have one small problem though, when using action queue or spamming click when working, it uses way more hunger than if you hold. Is this something I can fix with my mod? Link to comment https://forums.kleientertainment.com/forums/topic/150958-how-do-i-make-a-character-lose-hunger-when-working/#findComment-1665302 Share on other sites More sharing options...
Hamurlik Posted September 16, 2023 Share Posted September 16, 2023 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. Link to comment https://forums.kleientertainment.com/forums/topic/150958-how-do-i-make-a-character-lose-hunger-when-working/#findComment-1665316 Share on other sites More sharing options...
GRNNOperator Posted September 16, 2023 Author Share Posted September 16, 2023 Thank you! This worked perfectly! Link to comment https://forums.kleientertainment.com/forums/topic/150958-how-do-i-make-a-character-lose-hunger-when-working/#findComment-1665344 Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now