Kooby Posted August 28, 2016 Share Posted August 28, 2016 Yo, me again. I'm almost done with my mod, however, i only need one last thing. My character is supposed to have sanity regen, aswell as immunity to sanity lowering things if its hunger is max or near (300 is its max hunger, i want the range for considered near be 290-300), and sanity to go down when hunger is below 100 (0-99 range of hunger to be exact). Currently, my code is the following: local function hungerpain(inst) if inst.components.hunger.current >= (290) and inst.components.hunger.current < 300 then inst.components.locomotor.walkspeed = (TUNING.WILSON_WALK_SPEED * 1.4) inst.components.locomotor.runspeed = (TUNING.WILSON_RUN_SPEED * 1.4) inst.components.sanity.neg_aura_mult = 0 inst.components.sanity.night_drain_mult = 0 inst.components.sanity.dapperness = ( TUNING.DAPPERNESS_MED * 1.20 ) elseif inst.components.hunger.current >= (150) and inst.components.hunger.current <(300) then inst.components.locomotor.walkspeed = (TUNING.WILSON_WALK_SPEED * 1.2) inst.components.locomotor.runspeed = (TUNING.WILSON_RUN_SPEED * 1.2) inst.components.sanity.neg_aura_mult = 0.5 inst.components.sanity.night_drain_mult = 0.5 elseif inst.components.hunger.current <= (100) and inst.components.hunger.current < (149) then inst.components.locomotor.walkspeed = (TUNING.WILSON_WALK_SPEED * 1) inst.components.locomotor.runspeed = (TUNING.WILSON_RUN_SPEED * 1) inst.components.sanity.neg_aura_mult = 1 inst.components.sanity.night_drain_mult = 1 elseif inst.components.hunger.current <= (0) and inst.components.hunger.current < (99) then inst.components.locomotor.walkspeed = (TUNING.WILSON_WALK_SPEED * 0.8) inst.components.locomotor.runspeed = (TUNING.WILSON_RUN_SPEED * 0.8) inst.components.sanity.neg_aura_mult = 1.2 inst.components.sanity.night_drain_mult = 1.2 inst.components.sanity.dapperness = ( TUNING.DAPPERNESS_MED * -1.00 ) end end As you can see, i also have speed stuff, but that seems to work as it should, however, sanity does not seem to regen at all (could be that it just doesn't have the arrow pointing up to say it's regenerating tho). So i would love some help with this, thanks. Link to comment Share on other sites More sharing options...
rezecib Posted August 28, 2016 Share Posted August 28, 2016 @Kooby You don't need parentheses around your numbers like that. I doubt it's causing a problem, but they definitely don't need to be there. Your current code will make it so that at certain hunger values none of the effects will apply (specifically at hunger values of 300, 149, and 99). Instead of having two parts to each of the if blocks, just check them in order: >= 290, >= 150, >= 100, >= 0. Some of yours also say <= when I think you mean >=. Also, for walkspeed and runspeed, it's much better to use the speed multiplier system now. You can do it like so: (and it's much more resistant to other speed modifiers overwriting yours) inst.components.locomotor:SetExternalSpeedMultiplier(inst, "hungerspeed", 1.4) --this defines it initially inst.components.locomotor:SetExternalSpeedMultiplier(inst, "hungerspeed", 1.2) --doing it again will override the earlier call inst.components.locomotor:RemoveExternalSpeedMultiplier(inst, "hungerspeed") --this gets rid of it, whatever it was set to It looks like everything you have should "work", though. For the purposes of testing you could always crank it up a lot to make sure it's working (like add a *100). Link to comment Share on other sites More sharing options...
Kooby Posted August 28, 2016 Author Share Posted August 28, 2016 51 minutes ago, rezecib said: @Kooby You don't need parentheses around your numbers like that. I doubt it's causing a problem, but they definitely don't need to be there. Your current code will make it so that at certain hunger values none of the effects will apply (specifically at hunger values of 300, 149, and 99). Instead of having two parts to each of the if blocks, just check them in order: >= 290, >= 150, >= 100, >= 0. Some of yours also say <= when I think you mean >=. Also, for walkspeed and runspeed, it's much better to use the speed multiplier system now. You can do it like so: (and it's much more resistant to other speed modifiers overwriting yours) inst.components.locomotor:SetExternalSpeedMultiplier(inst, "hungerspeed", 1.4) --this defines it initially inst.components.locomotor:SetExternalSpeedMultiplier(inst, "hungerspeed", 1.2) --doing it again will override the earlier call inst.components.locomotor:RemoveExternalSpeedMultiplier(inst, "hungerspeed") --this gets rid of it, whatever it was set to It looks like everything you have should "work", though. For the purposes of testing you could always crank it up a lot to make sure it's working (like add a *100). Whoops, i guess i might have dun goofed a little bit on the code. Thanks. Anything on the Sanity regen stuff though? it's the only issue i have i want to fix before finally uploading to the Workshop Link to comment Share on other sites More sharing options...
rezecib Posted August 28, 2016 Share Posted August 28, 2016 8 minutes ago, Kooby said: Anything on the Sanity regen stuff though? it's the only issue i have i want to fix before finally uploading to the Workshop As I said, what you have there looks like it should work to me. That's what I was suggesting you try cranking up the values a lot to make it really obvious whether they are or aren't. Link to comment Share on other sites More sharing options...
Kooby Posted August 28, 2016 Author Share Posted August 28, 2016 8 minutes ago, rezecib said: As I said, what you have there looks like it should work to me. That's what I was suggesting you try cranking up the values a lot to make it really obvious whether they are or aren't. The sanity drain prevention doesn't really seem to work at all Link to comment Share on other sites More sharing options...
. . . Posted August 28, 2016 Share Posted August 28, 2016 (edited) local function hungerdelta(inst) if inst.components.hunger.current >= 290 then -- Over 290. inst.components.locomotor.walkspeed = (TUNING.WILSON_WALK_SPEED * 1.4) inst.components.locomotor.runspeed = (TUNING.WILSON_RUN_SPEED * 1.4) inst.components.sanity.neg_aura_mult = 0 inst.components.sanity.night_drain_mult = 0 inst.components.sanity.dapperness = ( TUNING.DAPPERNESS_MED * 1.20 ) ----------------------------------------------------------------------------------] elseif inst.components.hunger.current <= 289.99 then -- Under 290. inst.components.locomotor.walkspeed = (TUNING.WILSON_WALK_SPEED * 1.2) inst.components.locomotor.runspeed = (TUNING.WILSON_RUN_SPEED * 1.2) inst.components.sanity.neg_aura_mult = 0.5 inst.components.sanity.night_drain_mult = 0.5 inst.components.sanity.dapperness = 0 * TUNING.DAPPERNESS_MED ----------------------------------------------------------------------------------] elseif inst.components.hunger.current <= 150 then -- Under 150. inst.components.locomotor.walkspeed = (TUNING.WILSON_WALK_SPEED * 1) inst.components.locomotor.runspeed = (TUNING.WILSON_RUN_SPEED * 1) inst.components.sanity.neg_aura_mult = 1 inst.components.sanity.night_drain_mult = 1 inst.components.sanity.dapperness = 0 * TUNING.DAPPERNESS_MED ----------------------------------------------------------------------------------] elseif inst.components.hunger.current <= 99 then -- Under 99. inst.components.locomotor.walkspeed = (TUNING.WILSON_WALK_SPEED * 0.8) inst.components.locomotor.runspeed = (TUNING.WILSON_RUN_SPEED * 0.8) inst.components.sanity.neg_aura_mult = 1.2 inst.components.sanity.night_drain_mult = 1.2 inst.components.sanity.dapperness = ( TUNING.DAPPERNESS_MED * -1.00 ) ----------------------------------------------------------------------------------] end end Put code above, inside character.lua above master_postinit. Put code below inside master_postinit. inst:ListenForEvent("hungerdelta", hungerdelta) This should definitely work for you, I think... Edited August 28, 2016 by SuperDavid Link to comment Share on other sites More sharing options...
Kooby Posted August 28, 2016 Author Share Posted August 28, 2016 Turns out i got the hunger wrong, it was actually 200, haha Link to comment Share on other sites More sharing options...
rezecib Posted August 28, 2016 Share Posted August 28, 2016 (edited) @SuperDavid Your conditions are wrong. With that code, only one of the first two conditions will be true, except for values between 289.99 and 290. You should just do something like this instead: local function hungerdelta(inst) if inst.components.hunger.current >= 290 then --290 or more elseif inst.components.hunger.current >= 150 then --150 to 290, because if it were >= 290 it would have ended above elseif inst.components.hunger.current >= 100 then --100 to 150 else --less than 100 end end And you want completely complementary conditions (that is, covering all cases), never ever do something like >= 290, <= 289.99. You can use the same number for both conditions: >=290, < 290. If you put the = it includes it, if you don't it doesn't. Edited August 28, 2016 by rezecib Link to comment Share on other sites More sharing options...
. . . Posted August 28, 2016 Share Posted August 28, 2016 (edited) 11 minutes ago, rezecib said: @SuperDavid Your conditions are wrong. With that code, only one of the first two conditions will be true, except for values between 289.99 and 290. You should just do something like this instead: local function hungerdelta(inst) if inst.components.hunger.current >= 290 then --290 or more elseif inst.components.hunger.current >= 150 then --150 to 290, because if it were >= 290 it would have ended above elseif inst.components.hunger.current >= 100 then --100 to 150 else --less than 100 end end And you want completely complementary conditions (that is, covering all cases), never ever do something like >= 290, <= 289.99. You can use the same number for both conditions: >=290, < 290. If you put the = it includes it, if you don't it doesn't. That's weird I use it like that & it works fine for me? I derped there for a second, I checked my code & I only have 2 different hunger levels so your way's obviously right ! Thanks for correcting me. Edited August 28, 2016 by SuperDavid Link to comment 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