edw1111 Posted January 22, 2020 Share Posted January 22, 2020 (edited) Hello guys, i try to make my own mask , which ll decrease sanity and increase current health. I found line of code for sanity, which work on my mask: inst.components.equippable.dapperness = -1 but i can't find similar code for hp regeneration.Please help. Thanks. i tried to use inst.components.health:StartRegen(1, 1) , but nothing changed Edited January 22, 2020 by edw1111 Link to comment https://forums.kleientertainment.com/forums/topic/115158-regeneration-on-item/ Share on other sites More sharing options...
Desblat Posted January 22, 2020 Share Posted January 22, 2020 There is no such a function currently, you will need to make it by yourself. You will need to track player equiping the item and start a task, if player unequips item you cancel task. This goes into OnEquip code: --- 1st we must remove regen task if there is one already so we don't create memory leak if owner.item_regen_task then owner.item_regen_task:Cancel() owner.item_regen_task = nil end ---- 2nd add regen local period = 1 owner.item_regen_task = owner:DoPeriodicTask(period, function() ownder.components.health:DoDelta(1) end) This goes into OnUnEquip code: ---- remove regen if owner.item_regen_task then owner.item_regen_task:Cancel() owner.item_regen_task = nil end 1 1 Link to comment https://forums.kleientertainment.com/forums/topic/115158-regeneration-on-item/#findComment-1300993 Share on other sites More sharing options...
Hornete Posted January 22, 2020 Share Posted January 22, 2020 2 hours ago, Desblat said: There is no such a function currently, you will need to make it by yourself. It does exist though function Health:StartRegen(amount, period, interruptcurrentregen) Link to comment https://forums.kleientertainment.com/forums/topic/115158-regeneration-on-item/#findComment-1301026 Share on other sites More sharing options...
Ultroman Posted January 23, 2020 Share Posted January 23, 2020 20 hours ago, Hornete said: It does exist though function Health:StartRegen(amount, period, interruptcurrentregen) AFAIK, StartRegen cannot stack. It will always overwrite the currently running regen, and since the game uses it, e.g. for jellybeans (IIRC), I would not recommend using it for your purposes. Desblat's suggestion is great. Simple and effective, and will also be applied properly when loading the character. 1 Link to comment https://forums.kleientertainment.com/forums/topic/115158-regeneration-on-item/#findComment-1301305 Share on other sites More sharing options...
Hornete Posted January 23, 2020 Share Posted January 23, 2020 2 minutes ago, Ultroman said: AFAIK, StartRegen cannot stack. It will always overwrite the currently running regen, and since the game uses it, e.g. for jellybeans (IIRC), I would not recommend using it for your purposes. Desblat's suggestion is great. Simple and effective, and will also be applied properly when loading the character. Ah, thatd make sense. Thanks for the explanation! Link to comment https://forums.kleientertainment.com/forums/topic/115158-regeneration-on-item/#findComment-1301307 Share on other sites More sharing options...
Ultroman Posted January 23, 2020 Share Posted January 23, 2020 16 minutes ago, Hornete said: Ah, thatd make sense. Thanks for the explanation! No problem. It's some weird code, IMO. In their comments, it sounds like they're saying they made it able to handle several regens, but what happens is: If there is already a regen running If "interruptcurrentregen" is true, then Cancel the current task. If there is no current regen anymore, create a new one, BUT if there IS a regen running already, it just replaces "amount" and "period" on the existing task and lets it continue running. The only thing their special "interruptcurrentregen" bool allows us to do, is rely on the regen task not being cancelled when replaced. This sound like a good thing, but I don't see any use case where I'd use it. If I was relying on when the task was finished, it'd mess things up when some other code applies a new StartRegen. Suddenly, it'd look like my regen lasted longer than it should have and is giving a wrong amount of regen, when really I just ate a jellybean which swapped out those important values. 1 1 Link to comment https://forums.kleientertainment.com/forums/topic/115158-regeneration-on-item/#findComment-1301322 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