heckmate Posted January 19, 2019 Share Posted January 19, 2019 I'm trying to make an object that, when eaten, temporarily makes you a giant, changing your size and max health, sanity, and hunger. Here's the function for that: Spoiler local function OnEaten(inst, eater) eater.Transform:SetScale(10, 10, 10) eater.components.health:SetMaxHealth(600) eater.components.hunger:SetMax(400) eater.components.sanity:SetMax(200) eater:DoTaskInTime(60, smallagain) end Above it I have another function called smallagain that returns you to your original size after 1 minute: Spoiler local function smallagain(inst) inst.Transform:SetScale(1, 1, 1) inst.components.health:SetMaxHealth(?) inst.components.hunger:SetMax(?) inst.components.sanity:SetMax(?) end So my question is, what's the value that should replace "?", since some characters have a dramatically different health than Wilson's default health (like Maxwell and Wolfgang)? I wouldn't want the effect to wear off and these characters to end up with a health of 150. Thanks in advance! Link to comment Share on other sites More sharing options...
YakumoYukari Posted January 19, 2019 Share Posted January 19, 2019 (edited) You want to make it get back to the character's default stats right? Unfortunately, SetMaxSomething() method nor stats components don't have a feature to store the one's "Default Max Stat". So you have to save the one's default status data when OnEaten calls. local function OnEaten(inst, eater) inst.oldmaxstats = { inst.components.health.maxhealth, inst.components.hunger.max, inst.components.sanity.max } eater.Transform:SetScale(10, 10, 10) eater.components.health:SetMaxHealth(600) eater.components.hunger:SetMax(400) eater.components.sanity:SetMax(200) eater:DoTaskInTime(60, smallagain) end local function smallagain(inst) local _old = inst.oldmaxstats inst.Transform:SetScale(1, 1, 1) inst.components.health:SetMaxHealth(_old[1]) inst.components.hunger:SetMax(_old[2]) inst.components.sanity:SetMax(_old[3]) end Kind of this code will work. You can create and store some values and then attach it to the entity. However, You have to consider more things if you want to make your food applies to all characters. 1) After being "Giant", the character's stats will be very low since you don't save the character's stats 'current percent' 2) Wolfgang's transformation or other scale-changeable characters will override your SetScale value. Use inst:ApplyScale() Instead. 3) Wickerbottom has 250 max sanity by default. Her sanity will be reduced if transform. I'd recommend to SetMax on OnEaten like eater.components.sanity:SetMax(math.max(inst.oldmaxstats[3], 200)) 4) If you go to the cave or disconnect during the effect will simply vanish some data as well as the effect itself. I think you have to use net_var and store its duration instead. 5) Setting the scale to (10, 10, 10) means your entity's moving speed will be x10 as well which will let it easily go through land borders. Edited April 4, 2019 by YakumoYukari Link to comment Share on other sites More sharing options...
heckmate Posted January 19, 2019 Author Share Posted January 19, 2019 hi, thank you very much for your reply! so I replaced the smallagain and OnEaten functions to include the oldmaxstats string, but whenever I try eating the item, it crashes the game and returns this error: Spoiler (line 23 is inst.oldmaxstats = { inst.components.health.MaxHealth, inst.components.hunger.max, inst.components.sanity.max }) And thanks for your advice about the sanity; I believe my workaround for that will be to simply make the Max sanity much higher than the default's (so 400 instead of 200, basically). I'll also try to change the scaling to ApplyScale instead. I don't think I'll be able to troubleshoot the caves thing, unfortunately. I'm extremely new at coding; the absolute extent of it comes from simply looking at the game files and other people's mods, and I wouldn't even know where to begin to do that. thanks again for your help though! Link to comment Share on other sites More sharing options...
YakumoYukari Posted January 19, 2019 Share Posted January 19, 2019 (edited) Oh all the inst.oldmax thingies should be eater instead Except for the one in smallagain Edited January 19, 2019 by YakumoYukari 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