Cenecal Posted June 22, 2016 Share Posted June 22, 2016 Hello! I am currently in the process of making a custom character for DST. I have all the basics down (customized stats, changed names in the files, etc.), I am still working on the art. However, I would like to implement a quirk that makes the character slowly lose sanity when around fire (exclusively in the daytime, if possible. If it's only possible for it to function all around the clock, that's fine as well). I tried manipulating Willow's .lua file, but I haven't been able to process the idea of changing and transferring it to the custom character's file. If anyone could help me out with this, I would be so grateful! I have scoured the forums for other people looking to do this prior to posting this. I will admit that I am new to coding, and no advice that was given to others was accurate or applicable to the current day (The threads I have found are super outdated). Link to comment Share on other sites More sharing options...
Arkathorn Posted June 22, 2016 Share Posted June 22, 2016 This is the wrong forum. You are asking about the multiplayer version, not the singleplayer. However, the relevant processes are the same for both versions, so this forum is still perfectly valid for this question. I can't look into it now, but I'll come back and edit this post once I have. (Yeah, it's perfectly possible to have this be daytime only. The coding interface for Don't Starve modding is very accommodating.) Link to comment Share on other sites More sharing options...
Cenecal Posted June 22, 2016 Author Share Posted June 22, 2016 2 hours ago, Arkathorn said: This is the wrong forum. You are asking about the multiplayer version, not the singleplayer. However, the relevant processes are the same for both versions, so this forum is still perfectly valid for this question. I can't look into it now, but I'll come back and edit this post once I have. (Yeah, it's perfectly possible to have this be daytime only. The coding interface for Don't Starve modding is very accommodating.) Oops! I thought this was the multiplayer forum. You do make a good point that it is the same process, so I don't think I'll have to have it moved, hopefully? I appreciate the response and information. Thank you for taking the time to reply! Link to comment Share on other sites More sharing options...
Arkathorn Posted June 23, 2016 Share Posted June 23, 2016 Nvm, I'll just post it here. local function makefn(amt) return function(inst) inst:AddComponent("sanityaura") inst.components.sanityaura.aurafn = function(inst, observer) if observer.prefab == "yourcharacterprefab" and GetClock().phase == "day" then if inst.components.fueled then return inst.components.fueled:GetPercent() * amt else return amt end end end end end AddPrefabPostInit("campfire",makefn(TUNING.SANITY_SMALL)) AddPrefabPostInit("firepit",makefn(TUNING.SANITY_MED)) This goes in 'modmain.lua'. Add more 'AddPrefabPostInit' lines for more prefabs. See 'tuning.lua' for the other sanity amounts. This should work in DS, but I'm pretty sure DST puts the Clock somewhere else (inside the SeasonManager?). Just remove this code to leave the daytime restriction out, and make it DST compatible: (Leave the 'then' in.) and GetClock().phase == "day" Or you could ask someone how to get the current phase in DST. Link to comment Share on other sites More sharing options...
DarkXero Posted June 23, 2016 Share Posted June 23, 2016 DST uses neither GetClock() or GetSeasonManager(). I'm going to suggest a tweaked DST Willow approach (to include more than campfire and firepit), with the fuel multiplier thing. local function sanityfn(inst) -- Not day, give 0 back if TheWorld.state.phase ~= "day" then return 0 end -- During day, Willow approach local delta = 0 local x, y, z = inst.Transform:GetWorldPosition() local max_rad = 10 local ents = TheSim:FindEntities(x, y, z, max_rad, {"fire"}) for i, v in ipairs(ents) do local fuel_mult = inst.components.fueled and inst.components.fueled:GetPercent() or 1 if v.components.burnable and v.components.burnable:IsBurning() then local rad = v.components.burnable:GetLargestLightRadius() or 1 local sz = TUNING.SANITYAURA_TINY * math.min(max_rad, rad) / max_rad local distsq = inst:GetDistanceSqToInst(v) - 9 delta = delta + sz / math.max(1, distsq) delta = delta * fuel_mult end end -- Willow would be positive, so we invert it return -delta end -- inside master local function master_postinit(inst) inst.components.sanity.custom_rate_fn = sanityfn end Link to comment Share on other sites More sharing options...
Arkathorn Posted June 23, 2016 Share Posted June 23, 2016 Whoops, I completely missed the 'custom_rate_fn' stuff for the Sanity component! This is a much better approach. Link to comment Share on other sites More sharing options...
Cenecal Posted June 23, 2016 Author Share Posted June 23, 2016 @DarkXero @Arkathorn Thank you both for the coding and the help so far! I followed @Arkathorn's directions to put @DarkXero's code in the modmain.lua file. I'm not sure if there's a specific place to put it, so I put it between "Assets" and "local require". I went into the game with the character to test it out by building myself a campfire, and nothing seemed to happen. Thankfully, the game didn't crash like I've seen happen with others. I feel like I'm overlooking or missing something very obvious. Link to comment Share on other sites More sharing options...
Arkathorn Posted June 23, 2016 Share Posted June 23, 2016 Put the 'sanityfn' function in 'yourcharacter.lua', outside of 'fn'. Inside of 'fn' (but before the "return" line), put the line from 'master_postinit': inst.components.sanity.custom_rate_fn = sanityfn Link to comment Share on other sites More sharing options...
Cenecal Posted June 23, 2016 Author Share Posted June 23, 2016 @Arkathorn I'm not very good at coding, and I appreciate you being so patient with me. I have attached a screenshot of what I have in the charactername.lua file. http://i.imgur.com/g1s7d6A.png Link to comment Share on other sites More sharing options...
Mobbstar Posted June 23, 2016 Share Posted June 23, 2016 @Cenecal you should move the entire "sanityfn" block above the "master_postinit" block, and the line Arkathorn posted in the "master_postinit" function. Link to comment Share on other sites More sharing options...
Cenecal Posted June 23, 2016 Author Share Posted June 23, 2016 @Mobbstar That did it! Thank you so much. Also thanks to everyone that helped! Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.
Please be aware that the content of this thread may be outdated and no longer applicable.