Jump to content

Modding help needed!


Recommended Posts

So I made myself an extended character (aka a modded chara), but I wanted to implement sanity loss from eating too much. My character has the trait Never Hungry as one of their perks, which means their hunger depletion is slower (0.5), but I wanted to make it that if you were to per say eat over 100 hunger, you would suffer a huge sanity loss. Could anyone help me out in figuring out how to code that in?

Link to comment
Share on other sites

36 minutes ago, Kunimatsu said:

So I made myself an extended character (aka a modded chara), but I wanted to implement sanity loss from eating too much. My character has the trait Never Hungry as one of their perks, which means their hunger depletion is slower (0.5), but I wanted to make it that if you were to per say eat over 100 hunger, you would suffer a huge sanity loss. Could anyone help me out in figuring out how to code that in?

I forgot to mention that I also need help implementing

- Sanity gain around a certain character whilst playing as a certain character

- Getting weaker dependent on how low your hunger is (I know I could strip this from wolfgang but I'm not sure where the code'll go.)

Link to comment
Share on other sites

Well heres a start:

local function hungercheck(inst)
    if (inst.components.hunger:GetPercent() < .5) then --50%
   inst.components.combat.damagemultiplier = 0.9
    elseif (inst.components.hunger:GetPercent() < .25)  then --25%
    inst.components.combat.damagemultiplier = 0.8

else

 inst.components.combat.damagemultiplier = 1
end
end

 

local master_postinit = function(inst) --reference on where the code goes

local function charactercheckfn(inst)
local x,y,z = inst.Transform:GetWorldPosition()
local delta = 0
local max_rad = 10
local ents = TheSim:FindEntities(x,y,z, max_rad, nil, nil, {"charactertag"}) --look for this tag
    for k,v in pairs(ents) do
if not (v.components.health and v.components.health:IsDead()) then
local sz = TUNING.SANITYAURA_MED --small, med, large
local rad = 10
sz = sz * ( math.min(max_rad, rad) / max_rad )
local distsq = inst:GetDistanceSqToInst(v)
delta = delta + sz/math.max(1, distsq)
    end
    end
    return delta
end

inst.components.sanity.custom_rate_fn = charactercheckfn --call the function

inst:DoPeriodicTask(2, hungercheck, nil, inst) --do this task every 2 seconds

Read through the notes and make the changes and all this is inside the character lua file. The other thing you need to do is give that other character a tag like below:

local common_postinit = function(inst) --reference

inst:AddTag("charactertag")

Final notes, I did the periodictask as doing listenforevent hungerdelta does it consistently and may overwhelm the game into a crash.

 

Well now I managed to get the sanity loss from eating while over 100 hunger:

local function eatcheck(inst)
if inst.components.hunger.current > 100 then
inst.components.sanity:DoDelta(-50)
end
end

local master_postinit = function(inst)--reference

inst:ListenForEvent("oneat", eatcheck)

Edited by K1NGT1GER609
Managed to do the thing that was requested or something.
Link to comment
Share on other sites

On 4/9/2018 at 10:32 PM, K1NGT1GER609 said:

Well heres a start:

local function hungercheck(inst)
    if (inst.components.hunger:GetPercent() < .5) then --50%
   inst.components.combat.damagemultiplier = 0.9
    elseif (inst.components.hunger:GetPercent() < .25)  then --25%
    inst.components.combat.damagemultiplier = 0.8

else

 inst.components.combat.damagemultiplier = 1
end
end

 

local master_postinit = function(inst) --reference on where the code goes

local function charactercheckfn(inst)
local x,y,z = inst.Transform:GetWorldPosition()
local delta = 0
local max_rad = 10
local ents = TheSim:FindEntities(x,y,z, max_rad, nil, nil, {"charactertag"}) --look for this tag
    for k,v in pairs(ents) do
if not (v.components.health and v.components.health:IsDead()) then
local sz = TUNING.SANITYAURA_MED --small, med, large
local rad = 10
sz = sz * ( math.min(max_rad, rad) / max_rad )
local distsq = inst:GetDistanceSqToInst(v)
delta = delta + sz/math.max(1, distsq)
    end
    end
    return delta
end

inst.components.sanity.custom_rate_fn = charactercheckfn --call the function

inst:DoPeriodicTask(2, hungercheck, nil, inst) --do this task every 2 seconds

Read through the notes and make the changes and all this is inside the character lua file. The other thing you need to do is give that other character a tag like below:

local common_postinit = function(inst) --reference

inst:AddTag("charactertag")

Final notes, I did the periodictask as doing listenforevent hungerdelta does it consistently and may overwhelm the game into a crash.

 

Well now I managed to get the sanity loss from eating while over 100 hunger:

local function eatcheck(inst)
if inst.components.hunger.current > 100 then
inst.components.sanity:DoDelta(-50)
end
end

local master_postinit = function(inst)--reference

inst:ListenForEvent("oneat", eatcheck)

Oh jeez uh could you potentially format the aura portion a lil differently? I'm having trouble understanding how to put in that portion.

Link to comment
Share on other sites

Hmm k hows this (goes into the character lua file):

local function hungercheck(inst)
    if (inst.components.hunger:GetPercent() < .5) then --50%
   inst.components.combat.damagemultiplier = 0.9
    elseif (inst.components.hunger:GetPercent() < .25)  then --25%
    inst.components.combat.damagemultiplier = 0.8

else

inst.components.combat.damagemultiplier = 1
end
end

local function eatcheck(inst)
if inst.components.hunger.current > 100 then
inst.components.sanity:DoDelta(-50)
end
end

local common_postinit = function(inst) --reference

inst:AddTag("charactertag")

 

local master_postinit = function(inst) --reference on where the code goes

local function charactercheckfn(inst)
local x,y,z = inst.Transform:GetWorldPosition()
local delta = 0
local max_rad = 10
local ents = TheSim:FindEntities(x,y,z, max_rad, nil, nil, {"charactertag"}) --look for this tag
    for k,v in pairs(ents) do
if not (v.components.health and v.components.health:IsDead()) then
local sz = TUNING.SANITYAURA_MED --small, med, large
local rad = 10
sz = sz * ( math.min(max_rad, rad) / max_rad )
local distsq = inst:GetDistanceSqToInst(v)
delta = delta + sz/math.max(1, distsq)
    end
    end
    return delta
end

inst.components.sanity.custom_rate_fn = charactercheckfn --call the function

inst:DoPeriodicTask(2, hungercheck, nil, inst) --do this task every 2 seconds

inst:ListenForEvent("oneat", eatcheck)

otherwise I can try making another sanity gain code (it won't be pretty no matter what) from being near another character but that'll take time.

Link to comment
Share on other sites

9 minutes ago, K1NGT1GER609 said:

Hmm k hows this (goes into the character lua file):

local function hungercheck(inst)
    if (inst.components.hunger:GetPercent() < .5) then --50%
   inst.components.combat.damagemultiplier = 0.9
    elseif (inst.components.hunger:GetPercent() < .25)  then --25%
    inst.components.combat.damagemultiplier = 0.8

else

inst.components.combat.damagemultiplier = 1
end
end

local function eatcheck(inst)
if inst.components.hunger.current > 100 then
inst.components.sanity:DoDelta(-50)
end
end

local common_postinit = function(inst) --reference

inst:AddTag("charactertag")

 

local master_postinit = function(inst) --reference on where the code goes

local function charactercheckfn(inst)
local x,y,z = inst.Transform:GetWorldPosition()
local delta = 0
local max_rad = 10
local ents = TheSim:FindEntities(x,y,z, max_rad, nil, nil, {"charactertag"}) --look for this tag
    for k,v in pairs(ents) do
if not (v.components.health and v.components.health:IsDead()) then
local sz = TUNING.SANITYAURA_MED --small, med, large
local rad = 10
sz = sz * ( math.min(max_rad, rad) / max_rad )
local distsq = inst:GetDistanceSqToInst(v)
delta = delta + sz/math.max(1, distsq)
    end
    end
    return delta
end

inst.components.sanity.custom_rate_fn = charactercheckfn --call the function

inst:DoPeriodicTask(2, hungercheck, nil, inst) --do this task every 2 seconds

inst:ListenForEvent("oneat", eatcheck)

otherwise I can try making another sanity gain code (it won't be pretty no matter what) from being near another character but that'll take time.

Naw it's cool I dont want to put you through the trouble. But I wanted to ask, where would I find the character tag? Or is that just the name of the character? (I also just tested the hunger portion of the code and it works fine no crashes or errors happened)

Edited by Kunimatsu
Link to comment
Share on other sites

Usually there in the common_postinit, not sure if you made the other character as you would have to add inst:AddTag("charactertag") to that other character. You can rename it anything meaningful for you (hopefully you don't use one that already exists) but if the other character doesn't have tags and isn't yours then...it'll be difficult on my end to make code to find something else.

Edited by K1NGT1GER609
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...