The title says it all. I'm not the most fluent in lua, I just do this for fun and as a challenge, and I do manage fairly okay for the most part. Right now though I'm working on a character mod with some abilities I've never messed around with and ran into an issue I'd like a second opinion on.
Basically what I'm trying to do is make it so that the character gets slower and weaker at low sanity. I've got code, it doesn't give me an error message. But I very strongly suspect it's not actually doing anything/what it should, or that the scaling and effect is way weaker than I'd like. There's no glitching or anything but especially the walking speed (easier to tell) doesn't seem to be changing at all, no matter how i change the values. It's somewhat of a patchwork code. Could someone check it if there's any noticeable flaws I missed? Or any other way for me to fix it? Or is there a smarter way to do this?
-- ABOVE LOCAL COMMON_POSTINIT
-- sanity damage and speed scaling
local function sanitydelta(inst)
if inst.components.sanity.current >= 100 then
inst.components.combat.damagemultiplier = 1
inst.components.locomotor.SetExternalSpeedMultiplier = 1.5
elseif inst.components.sanity.current > 75 then
inst.components.combat.damagemultiplier = 0.75
inst.components.locomotor.SetExternalSpeedMultiplier = 1
elseif inst.components.sanity.current < 50 then
inst.components.combat.damagemultiplier = 0.50
inst.components.locomotor.SetExternalSpeedMultiplier = 0.50
-- IN LOCAL MASTER_POSTINIT:
inst:ListenForEvent("sanitydelta", sanitydelta) -- sanity damage and speed scaling
And then just in case it might be necessary, here's the whole prefab folder. I'd appreciate any at all help and tips!