Jump to content

Recommended Posts

I was wanting to assign additional benefits and/or penalties to a mod character when they awaken from sleep. I've nosed around various files and found various data in the game files.

 

I had hoped I could modify something based on wickerbottom, but she is simply tagged with 'insomnia' which is checked somewhere in the the game files (I found it, but forget where)

 

If I were to redefine an event in a <character>.lua that was already defined elsewhere in the game files.

(in this case sleeping) which takes priority, The original or the modded version?

 

So, since I dont want to modify the existing game files I started thinking of a new approach.

But I am not sure how one would ovverride the use of the bedrolls, tents, etc.

 

I thought the next best appraoch would be easiest just to add a bump whenever the character did the 'wakeup' animation after sleeping. ie. Put something in the <character>.lua to modify the stats when that event happens.

But I am not even sure how to begin with that, or if it is a better approach.

 

The other option I thought about would be to do the same effect, but instead of listening for the wakeup event it would happen when the character used one of the sleep items (bedroll, furry bedroll, tent, siesta lean-to) but I was afraid that (should I figure out how to do it) the benefits or penalties would be applied if the character attempted to use it, even if they could not because of events such as too hungry to sleep, etc.

 

My programming knowledge of lua is nil,

so anyone who can give advice on this,

 

Thanks

What I would do here is modify how the sleepingbag component is used in the prefabs (tents and so on) that you want to alter.

 

It might look something like this:

 

function giveadditionalbonusestousingtent(inst)

   local oldonsleep = inst.components.onsleep

   inst.components.onsleep = function(inst, sleeper)

      oldonsleep(inst, sleeper)

      if sleeper.prefab == "webber" then

         sleeper:DoTaskInTime(1.2, function()

            sleeper.components.sanity:DoDelta(50)

         end

      end

   end

end
AddPrefabPostInit("tent", giveadditionalbonusestousingtent)

What I would do here is modify how the sleepingbag component is used in the prefabs (tents and so on) that you want to alter.

 

Thanks,

Would this be in the <character>.lua or the modmain.lua?

 

Edited by MidrealmDM

What I would do here is modify how the sleepingbag component is used in the prefabs (tents and so on) that you want to alter.

 

Ok - lets see if I understand this

 

function deepsleeper(inst)

-- we begin by defining a function

 

   local oldonsleep = inst.components.onsleep

--then create 'oldonsleep' which equals the previous onsleep function from the item

 

   inst.components.onsleep = function(inst, sleeper)

--then we detail a new 'onsleep' function to take its place

 

      oldonsleep(inst, sleeper)

--which first executes the oldonsleep

      if sleeper.prefab == "winfred" then

--then checks to see if the sleeper is a specific character (is this supposed to have two equal signs?)

         sleeper:DoTaskInTime(1.2, function()

--if it meets the criteria of being the right character it executes a task

            sleeper.components.sanity:DoDelta(50)

--to alter the sanity by +50

 

         end)-- I added a closing parenthesis, I hope I put it in the right place

      end

   end

end

 

AddPrefabPostInit("tent", deepsleeper)

--this adds our newly defined function to the prefab "tent"

 

 

Well - I've toyed around with it but I keep getting the same error whenever I try to load or craft an item altered by the code Before I even attempt to use it. I'm not sure what it means.

 

QueryServerComplete no callback

...pps/common/dont_starve/data/scripts/entityscript.lua:971: attempt to index local 'v' (a function value)

LUA ERROR stack traceback:

        C:/Program Files/Steam/steamapps/common/dont_starve/data/scripts/entityscript.lua(971,1) in function 'OnBuilt'

        C:/Program Files/Steam/steamapps/common/dont_starve/data/scripts/components/builder.lua(349,1) in function 'DoBuild'

        C:/Program Files/Steam/steamapps/common/dont_starve/data/scripts/actions.lua(635,1) in function 'fn'

        C:/Program Files/Steam/steamapps/common/dont_starve/data/scripts/bufferedaction.lua(19,1) in function 'Do'

        C:/Program Files/Steam/steamapps/common/dont_starve/data/scripts/entityscript.lua(945,1) in function 'PerformBufferedAction'

        C:/Program Files/Steam/steamapps/common/dont_starve/data/scripts/stategraphs/SGwilson.lua(1598,1) in function 'ontimeout'

        C:/Program Files/Steam/steamapps/common/dont_starve/data/scripts/stategraph.lua(458,1) in function 'UpdateState'

        C:/Program Files/Steam/steamapps/common/dont_starve/data/scripts/stategraph.lua(515,1) in function 'Update'

        C:/Program Files/Steam/steamapps/common/dont_starve/data/scripts/stategraph.lua(111,1) in function 'Update'

        C:/Program Files/Steam/steamapps/common/dont_starve/data/scripts/update.lua(121,1)

scripts/frontend.lua(712,1) SCRIPT ERROR! Showing error screen    

...ps/common/dont_starve/data/scripts/mainfunctions.lua:380: attempt to index local 'v' (a function value)

LUA ERROR stack traceback:

        C:/Program Files/Steam/steamapps/common/dont_starve/data/scripts/mainfunctions.lua(380,1)

Force aborting...

 

 

Attaching the original bedroll and tent .lua files (as text files)

And there is also a sleepingbag.lua (in constants folder [not attached]) which calls the function that insomniacs (such as wickerbottom) cannot sleep.

bedroll_furry.txt

bedroll_straw.txt

tent.txt

Edited by MidrealmDM

What I would do here is modify how the sleepingbag component is used in the prefabs (tents and so on) that you want to alter.

 

It might look something like this:

 

inst.components.onsleep should be inst.components.sleepingbag.onsleep

Thanks to both of you, that seemed to do the trick -

 

Final code for anyone else who wants to use this (add to modmain.lua)

 

function <functionname>(inst)

   local oldonsleep = inst.components.sleepingbag.onsleep

   inst.components.sleepingbag.onsleep = function(inst, sleeper)

      oldonsleep(inst, sleeper)

      if sleeper.prefab == "<customcharacter>" then

         sleeper:DoTaskInTime(1.2, function()

            sleeper.components.sanity:DoDelta(<value to add or subtract>, false)

            sleeper.components.health:DoDelta(<value to add or subtract>, false, "bedroll", true)

            sleeper.components.hunger:DoDelta(<value to add or subtract>, false, true)

         end)

      end

   end

end

 

AddPrefabPostInit("bedroll_straw", <functionname>)

AddPrefabPostInit("bedroll_furry", <functionname>

AddPrefabPostInit("bedroll_tent", <functionname>)

 

 

=-=-=-=

 

EDIT

If you want to ADD calories (increase fullness) change the DoTaskInTime value to 1.3 so that it happens after the normal hunger drain, otherwise if the character is already full, the game cannot add anything before taking away the normal amount associated with sleeping.

 

So if you want your numbers to be added or subtracted before the normal sleeping penalties/bonuses leave it at 1.2 but if you want it to come after change it to 1.3.

Edited by MidrealmDM

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
  • Create New...