Jump to content

Recommended Posts

Hey there!

I've finished the model of my very first custom character (Spinel from Steven Universe), now it's time to give her some special perks. I have these ideas in my mind, as a beginner Don't Starve modder, I'm not sure how achieveable they are:

- Loses sanity if she stands in one place, gains sanity if she moves

- Gains sanity if she's around creatures, loses sanity if she's alone

Is there a not too compicated way to give her these abilities to her? 

Somewhere to start, you can use a function in a modmain called AddPrefabPostInitAny() that goes through all prefabs in the world applying your change to everything. In the beginning of the function you give it, you could do a check that asks if the prefab has an animal or insect tag and then add a sanity aura. The problems with this is that you'll have to see if it is possible to make a sanity aura apply to only one person/character, as well as the animal may already have a sanity aura. In which case, you might have to do some research on the playerprox component and add a sanity aura to the player themselves when near an animal/insect.

As for moving, you might be able to use the AddComponentPostInit() function and alter the locomotor component. The problem here is that you don't want to use a forever loop and constantly check if the player is walking or else the game will get extremely laggy real quick.

You'll definitely have to look up some of this because I can't explain super specific details about manipulating auras and playerprox and locomotor. If you still want to know more just keep asking and I'll see where I can point you...

Both of these could be done with a repeating timer and polling.  It's the most straightforward approach and easiest to do.

For the first, create a blank vector or a couple of variables to store the old X/Z coords.  Then in the timer callback calculate the squared distance of the player's new position and if it's below a threshold of 0.1, then it's safe to assume the player hasn't moved.  Note that comparing a floating point number to zero could work, but to be on the safe side it's better to assume that there's floating point drift and as such only compare with '<', '<=', '>', or '>='.  Once it has been detected that the player hasn't moved, do a delta on the sanity component for each timer tick.

For the second, do a TheSim:FindEntities call and filter appropriately with tags.  Then either iterate the list to further filter, or assume that your initial filter is perfect and check if the size of the return value is >0 to know if there is something nearby or not.  If you're only wanting to know if the table has at least one element and don't care for the size, you can do: `if next(sometable)` to determine that.  Then do more deltas with sanity component on the player.

 

There are more elegant ways to do this that don't use polling, but for the sake of simplicity and straightforwardness don't be offput by using it.

For example, the first one could be solved by hooking the player's locomotor component and some of its functions to determine the start/stop events you want to know about.  The second wouldn't change much, as ultimately sanity auras use TheSim:FindEntities in the end so it's effectively polling already.

I don't now why you don't just use the inst.components.sanity.custom_rate_fn similar to willow. You could literally bundle all those sanity things into a single fn of math.
She polls fires which could easily be replaced with animals and if the table size is 0 then you can give a negative delta. Also when you get the newest version of your coordinates for the TheSim:FindEntities you can just compare it to the previously saved coordinates if there is any, and if there is a difference add a delta change and update the old saved coordinates.

  • Like 1

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...