omeneeghoul Posted June 26, 2024 Share Posted June 26, 2024 So, hello there! I am very new to modding and most of the things for the character (sprites, some code) have been done, but the character is very empty. I have a lot of ideas for this character, but I want to create the main traits/perks that he has. The first one is what I've already done - increasing damage and speed at low sanity. But that's not all... I tried to look for similar things on the forum, but I don't really understand how to make these perks: - The first idea for this character is quite simple: the character does things slower than the default speed. He also gets a little sanity from crafting (20 for example). - The second idea is much more complicated: the character loses/gains sanity over two game days. He loses -300 sanity, but the player can restore it in the usual ways. And then, in the next cycle, he also gets full (+300). I would like to make it more random, but it can be very difficult to keep codes from conflicting. So, because of this, a "timer" system would be better. After "losing sanity" comes "gaining sanity" and so on. Mood swings, if you will. I will be very happy if you can guide me, thank you! Link to comment https://forums.kleientertainment.com/forums/topic/157552-slow-crafting-and-sanity-swings/ Share on other sites More sharing options...
alainmcd Posted July 5, 2024 Share Posted July 5, 2024 Welcome to the forums! On 6/26/2024 at 1:48 PM, omeneeghoul said: the character does things slower than the default speed Unfortunately, I don't believe that's feasible. Action speed is hardcoded with the actions, so you'd have to manually modifiy every action you wish to alter. You'd have to add a special case only for your character, otherwise all characters would receive the same buff/debuff whenever your mod is enabled. -- On 6/26/2024 at 1:48 PM, omeneeghoul said: He also gets a little sanity from crafting That's easier. Many components offer the possibility to add a callback when an action is completed (e.g. onfinished). The builder component doesn't, but we can add it anyway by wrapping the MakeRecipe function: -- In your character .lua file, in the master_postinit fn: local old_MakeRecipe = inst.components.builder.MakeRecipe inst.components.builder.MakeRecipe = function(...) local ret = old_MakeRecipe(unpack(arg)) if ret then inst.components.sanity.DoDelta(TUNING.SANITY_MEDLARGE) end return ret end The ellipsis allows us to not worry about the arguments the MakeRecipe function actually handles. Note that here we are adding sanity whenever crafting succeeds, including when learning new recipes. If you'd rather not have the double bonus, you could for example compensate for it creating a wrapper for the UnlockRecipe function of the same builder component. -- On 6/26/2024 at 1:48 PM, omeneeghoul said: a "timer" system Exactly. Use the task scheduler: -- All of this goes in the master_postinit function in your character .lua file: inst.sanityCyclePositive = true local function sanityTask() if not inst then return end inst.components.sanity.SetPercent(inst.sanityCyclePositive and YOUR_CHARACTERS_MAX_SANITY or 0) inst.sanityCyclePositive = not inst.sanityCyclePositive inst:DoTaskInTime( TUNING.TOTAL_DAY_TIME * 1.5 + math.random(TUNING.TOTAL_DAY_TIME), -- This should make the next call between 1.5 and 2.5 days later. sanityTask ) end inst:DoTaskInTime( TUNING.TOTAL_DAY_TIME * 1.5 + math.random(TUNING.TOTAL_DAY_TIME), sanityTask ) DoTaskInTime takes care of the scheduling, you just need a task to create the following task (the DoTaskInTime call within the sanityTask function). You might want or need to add a check that the player is not dead when setting the sanity. -- Disclaimer: all code untested. I hope this at least gets you in the right direction. Happy modding! 1 Link to comment https://forums.kleientertainment.com/forums/topic/157552-slow-crafting-and-sanity-swings/#findComment-1732917 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