Jump to content

Custom Character Creation help?


Recommended Posts

Greetings!
I have recently started creating a custom character but i have no experience with modding at all so i was hoping i could get some help over here.
I started the creation using tutorials, however, none of the tutorials i found so far have been getting into detail on how to code new features and stuff.
I put the plans i have for my char below and hope i could get some help on how to implement those features here. 

Spoiler

HP: 200
Hunger: 200
Sanity: 100

Planned features: (Currently only visuals available)

*Regains sanity from foraging (picking berries, carrots, twigs, mushrooms etc. like Flowers)
*can pick evil flowers without penalty
*More resistant to cold, less resistant to heat
*Pigs, Merman, Cave rabbits etc are not hostile towards him
*gets bonus sanity from eating uncooked food
*loses sanity in caves and on boats
*loses sanity from killing non-hostile mobs
*cannot eat any kind of monster meat
*starts with backpack and Stormfang
*can craft sturdier traps (Rabbit traps, bird cages etc)

Item: Stormfang
*Can be charged with moonstones (Charge is shown by percentage)
*Cannot break 
*Base-damage: 30
Chargeddamage: 61

 

Link to comment
Share on other sites

So I have a few questions:

 1. "*loses sanity in caves..." Do you want to lose more sanity in the caves, because it already has a constant sanity drain.

 2. "*cannot eat any kind of monster meat" Do you want it so it doesn't show the eat option? Or do you want it to have very bad effect (e.g. dying)

 3. For Stormfang, do you want the damage based on the charge, or do you want it to always do 61 damage if it's charged?

  • Like 1
Link to comment
Share on other sites

On 8/18/2020 at 11:51 PM, decduck3 said:

So I have a few questions:

 1. "*loses sanity in caves..." Do you want to lose more sanity in the caves, because it already has a constant sanity drain.

 2. "*cannot eat any kind of monster meat" Do you want it so it doesn't show the eat option? Or do you want it to have very bad effect (e.g. dying)

 3. For Stormfang, do you want the damage based on the charge, or do you want it to always do 61 damage if it's charged?

1. Increased sanity yes.
2. He refuses to eat monster meat just like Wigfried wouldn't eat vegetables.
3. Damage would be 61 as long as there is any charge

Link to comment
Share on other sites

1. You could do a couple things: 

    a. Make your character more scared (like Wolfgang) so they take more sanity loss.

    b. Check if the character is in the caves, and then apply a small sanity drain.

2. In wathgrithr.lua (wigrid's character), there is: 

inst.components.eater:SetDiet({ FOODGROUP.OMNI }, { FOODTYPE.MEAT, FOODTYPE.GOODIES })

This prevents her from eating veggies. The problem is that monster foods are meat and monster, so I have no idea how you can exclude monster.

3. Have you go a equip-able item working first?

  • Like 1
Link to comment
Share on other sites

This is in Wolfgang's code:

inst.components.sanity.night_drain_mult = 1.1
inst.components.sanity.neg_aura_mult = 1.1

This makes him more scared.

 

Most of the time, you don't need a tutorial. What you do is find something that is similar to what you want to do, and then adapt it to what you want to do. Also you can look through the game's code, and see what certain values and functions do.

Edited by decduck3
  • Like 2
Link to comment
Share on other sites

Thanks for you help so far!
I am currently trying to figure out how to add sanity from picking berries, carrots and other vegetables. I tried to use the code that gives sanity when picking flowers and apply it to the other plants, but that's in the flower.lua rather than the character codes, so i'm not sure how to add this to my char.

Also i set the backpack as a starting item, but it won't appear since, i assume, backpacks cannot be put into the inventory. Is there a way to make him start with a backpack equipped?

Link to comment
Share on other sites

I’m not currently at my computer, but if you look through player_common.lua, there should be a onpickup function. Override that, check prefab name, add sanity.

 

You should be able to either set the body slot to a backpack, or spawn one in when the first join the game.

 

Edit: Disregard my first comment. There is no pickup function. What you will have to do is go to every item that you want the sanity for, and add it in the onpickupfn, just like the flower.

Edited by decduck3
  • Like 1
Link to comment
Share on other sites

Umm.. What?

local changeOnPickup = function(inst)
	local function onpickedfn(inst, picker)
    if picker ~= nil then
        if picker.components.sanity ~= nil and not picker:HasTag("plantkin") then
            picker.components.sanity:DoDelta(TUNING.SANITY_TINY)
        end
	end
end

AddPrefabPostInit("examplepickup",changeOnPickup) --do for all items

I'm going to assume you are worried about compatibility with other mods:

 

  • Like 1
Link to comment
Share on other sites

3 hours ago, decduck3 said:

*tash.lua

 

Also the AddPrefabPostInit has to be in modmain.lua. It doesn't work anywhere else.

ah, that was the problem xD

However, i don't gain any sanity from picking carrots for some reason

Link to comment
Share on other sites

On 8/31/2020 at 11:05 PM, decduck3 said:

Can you post your code here?

i attached the modmain and tash.lua below.
Also i wasn't sure if only the AddPrefabPostInit line was supposed to go into modmain or the whole local changeOnPickup = function(inst) function part. I tried both and neither seems to work

tash.lua modmain.lua

Link to comment
Share on other sites

Sorry I should of been more specific when I said you have to redefine the onpickup function:

local function onpicked(inst, picker)
    if picker ~= nil then
        if picker.components.sanity ~= nil and not picker:HasTag("plantkin") then
            picker.components.sanity:DoDelta(TUNING.SANITY_TINY)
        end
    end
	TheWorld:PushEvent("beginregrowth", inst)
	inst:Remove()
end

local changeOnPickup = function(inst)
	inst.components.pickable.onpickedfn = onpicked
end

AddPrefabPostInit("carrot",changeOnPickup)

(In your modmain.lua) 

 

The onpicked function has to be outside of the function.

Edited by decduck3
Link to comment
Share on other sites

local function onpicked(inst, picker)
    if picker ~= nil then
        if picker.components.sanity ~= nil and not picker:HasTag("plantkin") then
            picker.components.sanity:DoDelta(TUNING.SANITY_TINY)
        end
    end
	TheWorld:PushEvent("beginregrowth", inst)
	inst:Remove()
end

local changeOnPickup = function(inst)
	if inst.components.pickable ~= nil then
		inst.components.pickable.onpickedfn = onpicked
	end
end

AddPrefabPostInit("carrot",changeOnPickup)

If that doesn't work, I have no idea how to do it, apart from overriding carrot.lua.

Link to comment
Share on other sites

12 hours ago, decduck3 said:

local function onpicked(inst, picker)
    if picker ~= nil then
        if picker.components.sanity ~= nil and not picker:HasTag("plantkin") then
            picker.components.sanity:DoDelta(TUNING.SANITY_TINY)
        end
    end
	TheWorld:PushEvent("beginregrowth", inst)
	inst:Remove()
end

local changeOnPickup = function(inst)
	if inst.components.pickable ~= nil then
		inst.components.pickable.onpickedfn = onpicked
	end
end

AddPrefabPostInit("carrot",changeOnPickup)

If that doesn't work, I have no idea how to do it, apart from overriding carrot.lua.

unfortunately, it does not work. It doesn't crash anymore but there is no sanity gain...

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