Maeve Raeve Posted August 21, 2024 Share Posted August 21, 2024 So, I've been working on a character of my own, and one of her mechanics is that she can power up damage while insane (less than 15% of max sanity), at the cost of a drastically increased hunger rate, however, for some reason, a while ago, this code completely broke down and for some reason won't work anymore? I resorted to removing the old code and rewriting the code that checks for the sanity myself, since I can't get in touch of who made the other code anymore, and yet, nothing works still, and it doesn't provide me with a crash, but the print commands I put on it to make sure it's doing something aren't showing up and the increased hunger rate also doesn't seem to be taking effect, just like with the old code. This is the new function I made for the sanity check, which is placed after "common_postinit" and before "master_postinit": local function SanityCheck(inst, data) local sanity = inst.components.sanity:GetPercent() if sanity <= 0.15 then print("going insane, increasing damage and hungerrate") inst.components.combat.damagemultiplier = 2 inst.components.hunger.hungerrate = TUNING.WILSON_HUNGER_RATE * 4 end if sanity > 0.15 then print("no longer insane, rolling back stats") inst.components.combat.damagemultiplier = 0.65 inst.components.hunger.hungerrate = 0.65 * TUNING.WILSON_HUNGER_RATE end end and put this inside "master_postinit" right at the end: inst:ListenForEvent("LSCheck", SanityCheck) This is clearly not working, as the prints won't show up on the console and the increased damage and hunger rate doesn't seem to be working either, and also, I just basically copied this code from another mod that worked... so I'm not entirely sure whether this is good code or not, as I don't know how to do anything in DST and my programming knowledge is really minimal. The old code for this was made by someone else, and used to be like this, and was put entirely inside "master_postinit" (this older code is also not doing anything, and I'm not really sure what all this is): inst:DoPeriodicTask(1, function() if inst.components.sanity.current == nil or inst.components.sanity.previous == nil then return end -- Insanity mechanic if inst.components.sanity.current <= 0.15 and inst.components.sanity.previous > 0.15 then print("going insane, increasing damage and hunger rate") inst.components.combat.damagemultiplier = 2 -- +100% melee dmg inst.components.hunger.hungerrate = 4 * TUNING.WILSON_HUNGER_RATE -- +250% hunger rate elseif inst.components.sanity.current > 0.15 and inst.components.sanity.previous <= 0.15 then print("no longer insane, rolling back stats") inst.components.combat.damagemultiplier = 0.65 inst.components.hunger.hungerrate = 0.65 * TUNING.WILSON_HUNGER_RATE end inst.components.sanity.previous = inst.components.sanity.current end) I've basically spent the entire day trying to figure out what I've been doing wrong with the code I made, and since there are no crashes, I've been really hopeless into finding out the issue without it, and now I'm tired and want to do something else out of my day, so I thought of dropping the code here in case I'm missing something obvious. Though I also included the old code just in case. If it really is hopeless, I might just start again from scratch, which is fine, just slightly more on the annoying side. Link to comment https://forums.kleientertainment.com/forums/topic/159127-sanity-percentage-check-not-doing-anything/ Share on other sites More sharing options...
Chesed Posted August 21, 2024 Share Posted August 21, 2024 (edited) Quote inst:ListenForEvent("LSCheck", SanityCheck) This is waiting for something called "LSCheck" to happen to run your code. I imagine it's a specific trigger in the other mod that does not exist in yours. Changing it to "sanitydelta" causes it to run for me. Quote inst:ListenForEvent("sanitydelta", SanityCheck) This will make it run as your character's sanity changes, so you'll see it print a lot, but this is the simplest way to make it work. I also put this line of code above my test character's stats in master_postinit, and I put your SanityCheck function above "local function onload", if it makes a difference. I genuinely can't remember if it does. Not sure about your old code, I just spotted this immediately. Edited August 21, 2024 by Chesed 1 Link to comment https://forums.kleientertainment.com/forums/topic/159127-sanity-percentage-check-not-doing-anything/#findComment-1741640 Share on other sites More sharing options...
Maeve Raeve Posted August 22, 2024 Author Share Posted August 22, 2024 19 hours ago, Chesed said: This is waiting for something called "LSCheck" to happen to run your code. I imagine it's a specific trigger in the other mod that does not exist in yours. Changing it to "sanitydelta" causes it to run for me. This will make it run as your character's sanity changes, so you'll see it print a lot, but this is the simplest way to make it work. I also put this line of code above my test character's stats in master_postinit, and I put your SanityCheck function above "local function onload", if it makes a difference. I genuinely can't remember if it does. Not sure about your old code, I just spotted this immediately. Thank you! This has worked yes! And also, I see, I should've noted that "LSCheck" isn't a real thing that can happen in base DST... though I guess I'm not necessarily sure what kind of valid strings can be put in there in base DST either... well, that's okay. Thank you, again! 1 Link to comment https://forums.kleientertainment.com/forums/topic/159127-sanity-percentage-check-not-doing-anything/#findComment-1741741 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