Dranix Posted January 11, 2017 Share Posted January 11, 2017 I'm making my own character for DST and I want him to have different max sanity during different seasons. The code I need should look something like this, I just don't how to make it. When new day check season if season is autumn set max sanity 60 if season is winter set max sanity 120 if season is spring set max sanity 60 if season is summer set max sanity 30 If you know how to make this code or something better please reply to this topic! Thank you! Link to comment Share on other sites More sharing options...
zUsername Posted January 11, 2017 Share Posted January 11, 2017 local function OnSeasonChange(inst, data) if TheWorld.state.season == "autumn" then inst.replica.sanity:SetMax(60) inst.replica.sanity:SetCurrent(60) elseif TheWorld.state.season == "winter" then inst.replica.sanity:SetMax(120) inst.replica.sanity:SetCurrent(120) elseif TheWorld.state.season == "spring" then inst.replica.sanity:SetMax(60) inst.replica.sanity:SetCurrent(60) elseif TheWorld.state.season == "summer" then inst.replica.sanity:SetMax(30) inst.replica.sanity:SetCurrent(30) end end inst:WatchWorldState("season", OnSeasonChange) Link to comment Share on other sites More sharing options...
Dranix Posted January 11, 2017 Author Share Posted January 11, 2017 (edited) 1 hour ago, zUsername said: local function OnSeasonChange(inst, data) if TheWorld.state.season == "autumn" then inst.replica.sanity:SetMax(60) inst.replica.sanity:SetCurrent(60) elseif TheWorld.state.season == "winter" then inst.replica.sanity:SetMax(120) inst.replica.sanity:SetCurrent(120) elseif TheWorld.state.season == "spring" then inst.replica.sanity:SetMax(60) inst.replica.sanity:SetCurrent(60) elseif TheWorld.state.season == "summer" then inst.replica.sanity:SetMax(30) inst.replica.sanity:SetCurrent(30) end end inst:WatchWorldState("season", OnSeasonChange) Thank you for the code but it doesn't seem to be working. I put the code under master_postinit , the same place where the normal set max things are. If I put it somewhere else the games crashes when loading the world or when choosing charater. This is the exact location of the code in my lua file. Spoiler -- This initializes for the server only. Components are added here. local master_postinit = function(inst) -- choose which sounds this character will play inst.soundsname = "wolfgang" -- Uncomment if "wathgrithr"(Wigfrid) or "webber" voice is used --inst.talker_path_override = "dontstarve_DLC001/characters/" -- Stats inst.components.health:SetMaxHealth(180) inst.components.hunger:SetMax(200) inst.components.sanity:SetMax(60) inst.components.eater.strongstomach = true -- Damage multiplier (optional) inst.components.combat.damagemultiplier = 1 -- Hunger rate (optional) inst.components.hunger.hungerrate = 0.685 * TUNING.WILSON_HUNGER_RATE --Food local eater = inst.components.eater eater:SetDiet({ FOODGROUP.OMNI }, { FOODTYPE.MEAT }) eater.ignoresspoilage = true --Thick Fur inst.components.temperature.inherentinsulation = 200 inst.components.temperature.inherentsummerinsulation = 0 --changing max sanity local function OnSeasonChange(inst, data) if TheWorld.state.season == "autumn" then inst.replica.sanity:SetMax(60) inst.replica.sanity:SetCurrent(60) elseif TheWorld.state.season == "winter" then inst.replica.sanity:SetMax(120) inst.replica.sanity:SetCurrent(120) elseif TheWorld.state.season == "spring" then inst.replica.sanity:SetMax(60) inst.replica.sanity:SetCurrent(60) elseif TheWorld.state.season == "summer" then inst.replica.sanity:SetMax(30) inst.replica.sanity:SetCurrent(30) end end inst.OnLoad = onload inst.OnNewSpawn = onload inst:WatchWorldState("season", OnSeasonChange) end Do I need to put it somewhere else? !!! Edit !!! : With help of my dad I placed it in the rights place and changed something to let it work but still thank you for the code! Edited January 11, 2017 by Dranix fixed the problem Link to comment Share on other sites More sharing options...
zUsername Posted January 11, 2017 Share Posted January 11, 2017 inst:WatchWorldState("season", function (inst,data) if TheWorld.state.season == "autumn" then inst.components.sanity:SetMax(60) elseif TheWorld.state.season == "winter" then inst.components.sanity:SetMax(120) elseif TheWorld.state.season == "spring" then inst.components.sanity:SetMax(60) elseif TheWorld.state.season == "summer" then inst.components.sanity:SetMax(30) end end) For who want the working code. 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