Jump to content

Recommended Posts

Hello, modding community! I'm dipping my toes into trying to make a fairly simple character mod. I have fantastic art skills, but the coding is very intimidating... still, I want to try to make it work, I just don't really know where to start. "Just learn Lua" is a pretty intimidating scope, when I have a pretty small set of things I actually want to do and I don't really want to make a bunch of mods, I just want to play as this one character. I've done some digging through character script files but I haven't found anything that looks like it could be repurposed for what I want with small changes, except that I did figure out how to make his favorite food be Fruit Medley.

Here's my shopping list:

-Gain 10 less food points and take 3 damage when consuming Electric Milk and Ice Cream.

-Gain 5 sanity instead of losing 10 when eating Fish Morsel.

-The big stretch goal is some way to taunt hostile and neutral creatures (by throwing a pinecone/birch nut at them, maybe? yelling at them?) where they'll continue to target the character even when damaged by other sources, and/or a "gives small damage bonus to nearby players (NOT including self) when above x sanity, when below x sanity instead causes very close-by players to lose a very small amount of sanity but gains bonus to own damage" sort of thing, but I'm not expecting this to be within the scope of forum help, I'm just mentioning it in case anyone happens to know something I could dissect for ideas on how to implement.

Any specific resources I could look at that would help me figure these things out or an explanation of the way this stuff is structured would be great, thank you for your time.

Hi, welcome to the forums!

The tutorials and guides subsection has a lot of resources, with this pinned collection acting as some sort of index. This post in particular about character creation is beginner friendly.

Of course, You will have to learn some Lua, but it's quite simple and the code is mostly very easy to read, even with no programming background. I would recommend reading some of the code to see how things are done, particularly those similar to what you're trying to achieve. You can find the code by going to Steam and right-clicking on DST > Properties... > Installed Files > Browse..., from the DST installation folder data > databundles and finally unzipping scripts.zip to somewhere. I'd suggest opening the whole scrips folder in an IDE, common preferences are Notepad++, Sublime Text and VSCode.

Very short intro to DS/DST entities: Prefabs are entities that can exist in the game world. They usually have one or more of the following:

  • custom resources like graphics and sounds,
  • a custom script,
  • a brain for its AI, not needed for player characters,
  • stategraphs to handle animations, you won't need them unless you want to implement new animations
  • and components, which handle the logic for common traits and actions.

As for your character traits:

The sanity effect can be delegated to the sanityaura component. You can give it an aurafn function which determines how much sanity it gives or to whom (IIRC, the sanityaura of a given entity isn't applied to itself, but I might be mistaken).

-- Somewhere in your character .lua file:
local function CalcSanityAura(inst, observer)
  return inst.components.sanity:GetPercent() > .6 and TUNING.SANITYAURA_TINY or inst.components.sanity:GetPercent() < .4 and -TUNING.SANITYAURA_TINY or 0
end

-- In the master_postinit function of your character .lua file:
inst.components.sanityaura.aurafn = CalcSanityAura

There's also an eater component that handles, you guessed it, eating. Again, you can give it a special function for your custom logic, in this case by passing a custom function to SetOnEatFn. You'll want to add a modifier for specific foods.

-- Somewhere in your character .lua file:
local function OnEat(inst, food, feeder)
  if food.prefabname == "fishmeat_small" then
    -- Apply sanity bonus to `inst` here.
  end
  --Check for other foods here.
end

-- In the master_postinit function of your character .lua file:
inst.components.eater:SetOnEatFn(OnEat)

Note that some components allow for easier extension, like here, while other don't, requiring a more complex solution. 

And regarding the taunting, the combat component manages targetting logic. Start with sanity and food bonuses, though.

--

It is quite a bit, so take your time to read the code and understand what's happening, but try to focus on the parts that are relevant to what you want to achieve. Look how other entities solve similar problems. "Find" (ctrl-f) and "Find in all files" (ctrl-shift-f)) are your friends. Good luck!

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