Jump to content

Need Help with various character/item attributes!


Recommended Posts

Hello fellow modders and DST players,

I decided to post another thread with multiple specific questions instead of posting multiple threads with single and/or wide topics. This thread's goal is to find out how to design the various attributes of my mod character and its class items. Below I will post the character mod, its description and questions relating to the programming/technical side of the character and its items.

(Note: Currently the only digital assets used are the ones from the extended character template, a wand item example and More weapons and Magic mod. These assets are temporary placeholders until I can hire a graphic artist, once mod complications are fixed.)

-----Character Description-----

Name: Gwen, The Faithful
Health: 150
Hunger: 125
Sanity: 125

Has been here before

  • Can craft Night tools by default. (Axe, Pickaxe, Shovel, hammer, pitchfork!) (Machete for SW?)
  • Can craft Rickidy Staff by default.
  • Knows first science tech level by default.
  • Knows first magic tech level by default.
  • Cooks in half the time.
  • Picks things in half the time.

Social and talkative

  • Gains sanity when nearby a player, non-cumulative. (Removed to balance healing staff sanity regeneration.)
  • Positive sanity aura for nearby players.
  • Once every 15 seconds you emote, heal 1 HP to yourself and nearby players.

Starting items

  • Starts with a Rickidy Staff.
  • Starts with a Night Axe.
  • Starts with a Night Pickaxe.
  • Starts with a Night Shovel.

-----Item Details-----

Rickidy Staff, details:

  • The staff functions as a walking cane.
  • While held provides +2 sanity/min.
  • Is able to cast both healing/resurrection spells at a cost.
  • Non-Walking Cane functions only work for Gwen.

Night Tools, details: (Note: Each tool spends 2 sanity per complete chopping, mining, digging, pitching, or smashing action.)

  • Don't have durability.
  • Uses sanity per partial action or attack.
  • The amount of sanity is the fraction from the following. [2 / # of partial actions] or [2 per attack]
  • If you have no sanity, costs nothing to use.

-----Questions-----

  1. How do I make a tool use sanity on actions, including chopping and attacking for example? Complete
  2. How do I make a dapperness (Sanity gain) effect only work on a specific character (prefab) while using/owner of an item? Complete
  3. How do I make a character know the first level of the magic tree by default? Complete
  4. How do I make a character pick things in half the time? Complete
  5. How do I make a character cook things in half the time? Complete
  6. How do I make the chat emote heal ability?

I'll update this list if I have any more questions.

 

I'd be extremely grateful if someone can answer these questions. I'll update the main post to state which questions have been answered.

Hopefully these questions will help with your own mod character or item, as a useful reference. :)

Gwen The Faithful.zip

client_log.txt

Edited by neahxx
Link to comment
Share on other sites

1: How do I make a tool use sanity on actions, including chopping and attacking for example?

Spoiler

Sanity draining costs like wickerbottom's books or staffs just do a sanity:DoDelta(negative number)
The tricky bit is linking this simple drain to your specific action:

Some components such as weapon have customfns you can take advantage of onattack. e.g. firestaff/redstaff

Others such as chopping might require using listenforevents on the owner of the item to see if they are working a specific thing.

This is more complicated but requires understanding how eventlisteners work in relation to pushedevents.
More detail can be elaborated but as always its best to see if there is similar code existing in the base game or mods that do what you need to do.

2: How do I make a dapperness (Sanity gain) effect only work on a specific character (prefab)?

Spoiler

This depends on what you mean by dapperness, if you mean like how maxwell gets a permanent sanity dapperness?

If so in his character's master_postinit you'll find:     inst.components.sanity.dapperness = TUNING.DAPPERNESS_LARGE

If you check the tuning.lua file for this DAPPERNESS_LARGE you'll find that this is just a pointer to some math which equates 0.111 sanity per second. You can change inst.components.sanity.dapperness = any number you desire just note this will be the number that is updated per second. 

This code would be placed in your character's prefab file, similar to maxwells.

3: How do I make a character know the first level of the magic tree by default?

Spoiler

Wickerbottom has this line of code: inst.components.builder.science_bonus = 1
If you look at the builder component it also has other convenient tech bonuses
 science_bonus, magic_bonus, ancient_bonus, shadow_bonus
adding inst.components.builder.magic_bonus = 1 will get you the desired effect in the master_postinit of your character.

4: How do I make a character pick things in half the time?
This is a common thing I have seen in a few modded characters. I would suggest just copying one of their methods.

5: How do I make a character cook things in half the time?

Spoiler

I am guessing you mean cook things in a crockpot 2x as fast? or Cook on a campfire 2x as fast?
If the former then this is what I use for allowing willow and one of my custom characters too cook 2x as fast.


local old_cook_fn = ACTIONS.COOK.fn
ACTIONS.COOK.fn = function(act, ...)
  local result = old_cook_fn(act,...)
  local stewer = act.target.components.stewer
  if result and stewer ~= nil and act.doer:HasTag("expertchef") then
    local fn = stewer.task.fn
    local t = GetTaskRemaining(stewer.task)
    stewer.task:Cancel()
    stewer.task = stewer.inst:DoTaskInTime(t*.5, fn, stewer)
  end
  return result
end

I would change the expertchef tag to your character's unique tag or use act.doer.prefab == "your characters prefab"
If the latter


	AddStategraphPostInit("wilson", function(sg)
		local oldCook = sg.actionhandlers[ACTIONS.COOK].deststate
		sg.actionhandlers[ACTIONS.COOK].deststate = function(inst, action,...)
			if inst:HasTag("expertchef") then
				return "domediumaction"
			end
			return oldCook(inst, action,...)
		end
	end)

This is again code I made for my mod as well as for the Gordon Ramsay Mod

6: How do I make the chat emote heal ability?

I don't understand what you mean by this? Do you mean how do you make a chat emote that when activate heals you? Because I have never touched stuff like that, I'm not quite sure how one even knows what emote is playing besides checking states or animation? Maybe somebody else can help with this.

Link to comment
Share on other sites

This feedback is excellent, thank you very much. 

1) Thanks I'm new to lua and need to do some additional research before I can complete that from scratch. But nonetheless this is helpful.

2) I'm sorry, I mean't on the walking cane item. Granting a sanity bonus to holder if is a specific character. (prefab)

3) Thank you, I wasn't sure as it didn't offer it as an autocomplete option. But offered the science one.

4) Thanks, I didn't know many characters did this. Most of the ones I've seen, pick instantly bypassing the animation.

5) Exactly what I was looking for. Although I forgot I could've looked at Warly from SW. I always forget that perk from one of the mods.

6) Don't worry about it, i'm pretty sure nobody has done it before. It's one of my rare ideas I suppose. I'll have to speak with PeterA about it when he is less busy.

 

So far you've solved almost all of my questions aside from the last one. Which is a doozy by the way, so no worries there. XD

Thank you so much for your help, by the way do you know of a character for question #4. I haven't seen one do exactly that.

-----Update-----

So I think the following should suffice for the half pick time.

local quickPick = GLOBAL.ActionHandler(GLOBAL.ACTIONS.PICK, function(inst, action)
    if action.target.components.pickable then
        if action.target.components.pickable.quickpick or inst.prefab == "gwen" then
            return "domediumaction"
        else
            return "dolongaction"
        end
    end
end)
AddStategraphActionHandler("wilson", quickPick)

It may be edtted to be more efficient syntax-wise possibly, but it seems workable to me.

Edited by neahxx
Link to comment
Share on other sites

Note that if you use the same perk as wickerbottom, it should also give you access to all the magic recipes with only the Prestihatitator, so it's something to consider. It's not exactly the same effect as "knowing the first level by default", since it means that you'll also have a benefit for the second level.

This isn't necessarily a bad thing, but you must verify that it's what you want.

Link to comment
Share on other sites

Thanks for the heads up, Lumina. Since I don't know how to program it differently, I'll just accept that benefit.

Thanks for the help everyone, my mod is almost complete programming wise. Just need the digital assets, audio and voice lines. Which I'll hire an artist at a later date.

Link to comment
Share on other sites

20 hours ago, neahxx said:

This feedback is excellent, thank you very much. 

1) Thanks I'm new to lua and need to do some additional research before I can complete that from scratch. But nonetheless this is helpful.

2) I'm sorry, I mean't on the walking cane item. Granting a sanity bonus to holder if is a specific character. (prefab)

3) Thank you, I wasn't sure as it didn't offer it as an autocomplete option. But offered the science one.

4) Thanks, I didn't know many characters did this. Most of the ones I've seen, pick instantly bypassing the animation.

5) Exactly what I was looking for. Although I forgot I could've looked at Warly from SW. I always forget that perk from one of the mods.

6) Don't worry about it, i'm pretty sure nobody has done it before. It's one of my rare ideas I suppose. I'll have to speak with PeterA about it when he is less busy.

2) Equippables have a dapperness attribute built in. 

inst.components.equippable.dapperness = TUNING.DAPPERNESS_LARGE

you can set this to your desired value when onequipped by your character checking for either a tag or prefab of your character and setting it to 0 when unequipped.

3) Alternative method is just unlock specific recipes if you want to preserve the machines usefulness.

	inst:DoTaskInTime(0, function(inst)
		inst.components.builder:AddRecipe("shovel")
		inst:PushEvent("unlockrecipe", { recipe = "shovel" })
	end)

For example unlocking shovel recipe, you would place this in your master_postinit

4) Picking is a little more complicated than cooking because there are 3 different pick animations depending on if you are picking juicy berry bushes, carrots or grass for example. It definitly would require lots of testing as it is quite easy to break something unless you want the same pick animation for your character.

Link to comment
Share on other sites

That helps a lot. Is there a way to check all existing recipes that have a certain science or magic value. Such as prestihatitator.

I'm looking to make it so my character also knows how to make modded items that require a certain station.

 

If you're able to solve that, you're a legend for sure! Because it seems hard to do. (Another forum user helped myself with it.)

 

This should be a functional method of doing so.

inst:DoTaskInTime(0, function(inst)
  for k, v in pairs(AllRecipes) do
    if v and v.level and (v.level.SCIENCE == 1 or v.level.MAGIC == 1) then
      inst.components.builder:AddRecipe(v.name)
      inst:PushEvent("unlockrecipe", { recipe = v.name })
      end
  end
end)
Edited by neahxx
Solved question.
Link to comment
Share on other sites

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
 Share

×
  • Create New...