Jump to content

Custom/Vanilla perk addition issues. Simple Friends Character


Recommended Posts

I'm having an issue adding any Perk to my/friends characters. [Have been posting in the Don't Starve forums, Sorry!]

 

ginnokaze.lua

 

And willows increase in sanity when near fire, but when i tried adding them to the characters i either got errors or when trying those specific perks in-game they just didn't work

I'm new to Modding in general and would like to learn more, but everything im trying fails and i don't know how most of this works, Anyone want to assist or try to help me learn sometime? This is for my friends character, mine is in another post with much more custom Perks and such i have little idea on how to go about these lua files outside of following a video.

 

 

ginnokaze.lua

Link to comment
Share on other sites

I'm going to assume the beard part of the code is working since you left that in.
As for Willow's sanity when near fire, that is all in the sanityfn function of willow.lua:

local function sanityfn(inst)    local x, y, z = inst.Transform:GetWorldPosition()     local delta = 0    local max_rad = 10    local ents = TheSim:FindEntities(x, y, z, max_rad, { "fire" })    for i, v in ipairs(ents) do        if v.components.burnable ~= nil and v.components.burnable:IsBurning() then            local rad = v.components.burnable:GetLargestLightRadius() or 1            local sz = TUNING.SANITYAURA_TINY * math.min(max_rad, rad) / max_rad            local distsq = inst:GetDistanceSqToInst(v) - 9            -- shift the value so that a distance of 3 is the minimum            delta = delta + sz / math.max(1, distsq)        end    end    return deltaend

 
 
So, breaking it down into individual lines to explain what is happening: (And if someone wants to correct me if I get something wrong go ahead, as this is my half-assed way of understanding the little LUA I know about DST)
 
Start a function called sanityfn, with an argument of inst. ( All functions need to end with an "end", which is in the last line)

local function sanityfn(inst)

-
Define a local variable called x, y, z, making it reffer to what is after the equal (inst.Transform:GetWorldPosition())
What that means is from now on in all the proceeding lines, whenever you see "x, y, z" it is the same as typing "inst.Transform:GetWorldPosition()"

local x, y, z = inst.Transform:GetWorldPosition() 

-
Define a local variable called delta, and assign the number 0 to it. (Not the same as saying local delta = zero)

local delta = 0

-
Define a local variable max_rad, and assign the number 10 to it.

local max_rad = 10

-
Define a local variable called ents, and assign TheSim:FindEntities(x, y, z, max_rad, { "fire" })
What that means is, in the same way as when we defined "x, y, z", from now on every time ents is used it will search for the entity "fire", in the world position (x, y, z), in a radius of 10 (max_rad).

local ents = TheSim:FindEntities(x, y, z, max_rad, { "fire" })

-
Search for all the values in the table "ents" (the variable we defined before, which searches for fire), and then for each value run the entire block of code:

    for i, v in ipairs(ents) do        if v.components.burnable ~= nil and v.components.burnable:IsBurning() then            local rad = v.components.burnable:GetLargestLightRadius() or 1            local sz = TUNING.SANITYAURA_TINY * math.min(max_rad, rad) / max_rad            local distsq = inst:GetDistanceSqToInst(v) - 9            -- shift the value so that a distance of 3 is the minimum            delta = delta + sz / math.max(1, distsq)        end    end

-
Now line by line so it isn't an absolute mess to understand.
If the value (v) we are iterating through right now in the table "ents" is burnable (has the component burnable (~= nil, as in it isn't nil, it exists), hence v.components.burnable, if thing "v" has component (.components) "burnable" (.burnable)), and it IS burning (v.components.burnable:IsBurning(), which returns true if it is and false if it isnt).

if v.components.burnable ~= nil and v.components.burnable:IsBurning() then

-
Then define some variables.
Define a local variable rad, and assign to it the largest right radius the burning item can achieve, or 1 if it doesn't have one.

local rad = v.components.burnable:GetLargestLightRadius() or 1

-
Define a local variable sz, and assign to it TUNING.SANITYAURA_TINY * math.min(max_rad, rad) / max_rad.
What all that means is, if we check the file tuning.lua:
SANITYAURA_TINY = 100/(seg_time*32)
That means that SANITYAURA_TINY is 100 divided by seg_time multiplied by 32. So if we check on the top of the file, seg_time is 30, as in a segment of ingame time is 30 seconds. So if we do 100/(30*32) we get 0,10416. So that is the value of SANITYAURA_TINY.
TUNING.SANITYAURA_TINY = 0.10416.
So next is math.min, which checks which of the arguments it is given (max_rad and rad) is the smallest, multiply the smallest with 0.10416 and then divide it by max_rad, which is 10.
So in the end:
TUNING.SANITYAURA_TINY * math.min(max_rad, rad) / max_rad
OR
0.10416 * math.min(10, rad) / 10
Rad is defined above, as the largest light radius the burning object can achieve or one, so it asks math.min which is smallest, that, or 10.

local sz = TUNING.SANITYAURA_TINY * math.min(max_rad, rad) / max_rad

-
Define a local variable distsq, and assign something that checks the distance squared from you to the burning item, MINUS 9.

local distsq = inst:GetDistanceSqToInst(v) - 9

-
Change delta to be the previous delta (defined above as 0) PLUS sz (defined above to be 0.10416 * math.min(10, rad) / 10), DIVIDED BY whichever is bigger (math.max, as opossed to math.min which checks the smallest) 1, or the distance squared from you to the burning item.

delta = delta + sz / math.max(1, distsq)

-
And then some ends to close the "if" and "for" from before, and then return delta, which is the result this whole function is trying to achieve.
 
 
 
Okay good, so in layman's terms, all this function is doing is getting the world position of your character, finding burning things around it, checking that they can burn and are burning, and calculating the sanity to give to your character according to the distance it is from the burning item and radius of light it can create.
 
 
 
 
SO HOW DO WE USE THIS?!?! you might ask
 
In your character.lua (prefab):

local function sanityfn(inst)    local x, y, z = inst.Transform:GetWorldPosition()     local delta = 0    local max_rad = 10    local ents = TheSim:FindEntities(x, y, z, max_rad, { "fire" })    for i, v in ipairs(ents) do        if v.components.burnable ~= nil and v.components.burnable:IsBurning() then            local rad = v.components.burnable:GetLargestLightRadius() or 1            local sz = TUNING.SANITYAURA_TINY * math.min(max_rad, rad) / max_rad            local distsq = inst:GetDistanceSqToInst(v) - 9            -- shift the value so that a distance of 3 is the minimum            delta = delta + sz / math.max(1, distsq)        end    end    return deltaend

 
 
 
In your character.lua (prefab), but this time INSIDE the master_postinit function:

inst.components.sanity.custom_rate_fn = sanityfn

All that last line does is tell the game "hey our character has a special function for sanity so like use it for sanity and things"
 
 
We FLIPPIN did it

If you tried putting the code together with those instructions and it still didn't work, compare it with this, where I already put it in its proper place:

 

ginnokaze.lua

Link to comment
Share on other sites

Holy post.

 

Yes the beard stuff it working, Its just a bit off because it is for wilson and not the custom character.

How do you show the lua within your posts as if it were a Text document?

 

And for the parts already within the Willow.lua im pretty sure i added everything into the lua before hand but it kept not working, I will try the lua you sent me after backing up the one i have (In case of any issues) And go spawn in a firepit to see if sanity goes up, Though im pretty sure i already tried these but hey, I'm completely new to this x3

 

EDIT: Yes it is working, I could have sworn i took the sanity delta and everything from Willows files, the game didn't crash or anything it just plain didn't work when i tried, i probaly messed a few things up. Thanks for the assistance on this i will keep your post for refrence and try to understand more ^^; Pretty dense. My friends character is done functionality wise now i will just let him work on his art more. thanks again.

Edited by xTheFallenOnesx
Link to comment
Share on other sites

This is from the ginnokaze.lua (Dleowolfs Custom character Thing)

local master_postinit = function(inst)

And this from the Games default prefabs, of willow
 

local function master_postinit(inst)

These are different so perhaps that was the issue? As i did add that last line in master_postinit

The base characters prefabs look differen't from the base ones from Dleowolfs.

Edited by xTheFallenOnesx
Link to comment
Share on other sites

This is from the ginnokaze.lua (Dleowolfs Custom character Thing)

local master_postinit = function(inst)

And this from the Games default prefabs, of willow

 

local function master_postinit(inst)

These are different so perhaps that was the issue? As i did add that last line in master_postinit

The base characters prefabs look differen't from the base ones from Dleowolfs.

 

That's actually something I never thought of, but yes it is different for mods and every mod does it the first way, so probably best to keep it that way.

(Although I have no idea if it actually makes any difference, when in doubt leave it alone)

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