Greyan777 Posted December 3, 2023 Share Posted December 3, 2023 Hello, this is my first time on this forum and also my first time doing a mod. I'm quite new to this. Let me explain the situation a little bit: My character is cold-blooded and, in theory, he should fall asleep at a low temperature. So, how to make it so that at a low temperature (zero degrees) he falls asleep, and wakes up when it rises? Non-seasonal hibernation (not in winter), it is at low temperatures. I've read a lot of the game files, but I haven't found anything similar in them, which is why I don't have the slightest idea how this can be done( Link to comment Share on other sites More sharing options...
_zwb Posted December 4, 2023 Share Posted December 4, 2023 So your character would sleep indefinitely until temperature rises above 0? Sounds bad in terms of gameplay experience tbh. If it's not permanent sleep, they would still stuck in a loop: too cold - sleep - wake up - still cold - sleep again. It's certainly possible but it would be buggy, could you go in details about this mechanic? Link to comment Share on other sites More sharing options...
Greyan777 Posted December 5, 2023 Author Share Posted December 5, 2023 Okay, wait a minute. Ahem, the idea of this character belongs to my co-author and he would like the reptile to fall asleep at a negative temperature. That is, until she rises, the character would sleep (perhaps this can be considered an endless sleep until someone warms him up. That is, he would not fall asleep, wake up and so on again). I mean... yes. Playing for him, you would have to monitor the character's body temperature more closely in winter (prepare an insulated hoodie, a thermal stone, maybe materials for a campfire with you just in case). Perhaps it would be more designed for coop, so that if anything in winter there would be someone who could warm it up. Something like that.. But if it really is going to be quite buggy, then I'd be interested in how it could be optimized (without loss as such, if possible) (I use a translator, so I apologize if there are any mistakes ><") Link to comment Share on other sites More sharing options...
_zwb Posted December 5, 2023 Share Posted December 5, 2023 You can do it like this in your character prefab file local function master_postinit(inst) local temperature = inst.components.temperature local onupdate = temperature.OnUpdate temperature.OnUpdate = function(...) -- If the character is freezing but not sleeping, make it sleep if temperature.IsFreezing() and not inst.sg:HasStateTag("sleeping") then inst.components.grogginess:AddGrogginess(3, 60) -- The second parameter is the time to sleep in seconds. end onupdate(...) end end Link to comment Share on other sites More sharing options...
Greyan777 Posted December 6, 2023 Author Share Posted December 6, 2023 Hm.. I tried to do it in the file, there were no errors, which is good, but.. he does not fall asleep, even grogginess does not appear. I tried changing the numeric values, but the character just freezes and no more I can roughly read the code and have an idea how it should work, but I don't quite understand what needs to be fixed to make it work Link to comment Share on other sites More sharing options...
Greyan777 Posted December 12, 2023 Author Share Posted December 12, 2023 I didn't quite understand how the function above works (or rather why it doesn't work), so I tried to find other solutions. After digging through the files, I achieved something like this: inst:ListenForEvent("temperaturedelta", function(inst,data) if inst.components.temperature.current <= 0 then inst.components.grogginess:AddGrogginess(3, 10) end end) Yes, he is not waking up now, in the future I will add the opposite event to this (if possible), but I have a question again.. When the temperature reaches 0 degrees, the character falls asleep instantly. I would like him to look sleepy for a while at first, and then fall down. Is there anything you can add or change? I'm very tight in this regard, but I really want to do something( 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