Deadsweet Posted May 3, 2023 Share Posted May 3, 2023 Obligatory "I'm super new to modding but I'm trying to learn". I'm still trying to grasp Lua by watching tutorials and trawling through DST's code. Currently, I'm trying to make an adjustment to a preexisting mod character by introducing a downside as follows: If it is day and sanity is lower than 90, then increase grogginess once per minute. The idea is to have the character fall asleep during the day if their sanity gets to around 60% of their max sanity (which is 150, 60% of that is 90). I've tried looking at the grogginess file in the game's code but have trouble understanding it. Even the mechanic of grogginess is rather confusing to me (if grogginess is over 10 seconds you fall asleep? I think that's how it works? Beyond that I know nothing). Here's my attempt at trying to implement this sort of mechanic (apologies in advance for inexperience) -- Sleepiness local grog_function = inst.components.grogginess:AddGrogginess(50) local grog_repetition = DoPeriodicTask(60, grog_function) local sanity_thresh = inst.components.sanity.current If TheWorld.state.isday and sanity_thresh <= 140 then grog_repetition else return end The sanity threshold for when the sleepiness kicks in was changed to 140 for ease of testing. But when I tried testing it out, the world wouldn't even load (error in code). How can I implement this and where did I go wrong? Link to comment https://forums.kleientertainment.com/forums/topic/147595-add-grogginess-when-certain-conditions-are-met/ Share on other sites More sharing options...
GodIess Posted May 5, 2023 Share Posted May 5, 2023 (edited) local function OnIsDay(inst, isday) if isday and inst.task == nil then inst.task = inst:DoPeriodicTask(60, function(inst) if inst.components.sanity and inst.components.grogginess and inst.components.sanity:GetRealPercent() <= .6 then inst.components.grogginess:AddGrogginess(10, 10) end end) elseif inst.task ~= nil then inst.task:Cancel() inst.task = nil end end I recommend you to use inst:WatchWorldState("isday", OnIsDay) Edited May 5, 2023 by GodIess Link to comment https://forums.kleientertainment.com/forums/topic/147595-add-grogginess-when-certain-conditions-are-met/#findComment-1633705 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