Jump to content

Don't lose sanity with other player ghosts


Recommended Posts

Hello!

 

I want to coding my mod character don't lose any sanity with ghosts and other player's ghosts because he likes paranormal stuff. I looked up my mod's lua and DST's sanity lua but still can't find out how. 

 

Is there any way to make it possible?

 

I would be really glad if you can help me. ;~;

Link to comment
Share on other sites

I think I found out how with google, maybe...

I added in my character's lua this ↓

 

inst.components.sanity.ghost_drain_mult = 0

 

Anyone knows it will works or not? ;~; 

If it works, will it works with the mob ghosts too?

Link to comment
Share on other sites

Just recover what you lose from sanity draining stuff by adding a custom sanity rate function to your character:
 

-- Stolen from sanity.lualocal function GetNumGhostPlayers()    local num = 0    if GetGhostSanityDrain( TheNet:GetServerGameMode() ) then       for i,v in pairs(AllPlayers) do            if v:HasTag("playerghost") then                num = num + 1            end        end    end    return numendlocal function nospooky(inst)    local delta = 0        -- Recover what we lost from ghost players    local ghost_drain_mult = GetNumGhostPlayers()        if ghost_drain_mult > TUNING.MAX_SANITY_GHOST_PLAYER_DRAIN_MULT then        ghost_drain_mult = TUNING.MAX_SANITY_GHOST_PLAYER_DRAIN_MULT    end        delta = delta + TUNING.SANITY_GHOST_PLAYER_DRAIN * ghost_drain_mult * -1        -- Recover what we lost from ghosts    local aura_delta = 0    local x,y,z = inst.Transform:GetWorldPosition()    local ents = TheSim:FindEntities(x,y,z, TUNING.SANITY_EFFECT_RANGE, {"ghost"}) -- Do ghost players have the tag ghost too?    for k,v in pairs(ents) do         if v.components.sanityaura and v ~= inst then            local distsq = inst:GetDistanceSqToInst(v)            local aura_val = v.components.sanityaura:GetAura(inst)/math.max(1, distsq)            if aura_val < 0 then                aura_val = aura_val * inst.components.sanity.neg_aura_mult            end            aura_delta = aura_delta + aura_val        end    end        delta = delta + (aura_delta * -1)        return deltaend...local function master_postinit()    ...    inst.components.sanity.custom_rate_fn = nospooky    ...end...

.. Thought it'd be shorter <<;

sanity.ghost_drain_mult does nothing, it's more or less handled like a local value in the Recalc function:

self.ghost_drain_mult = GetNumGhostPlayers()
Edited by Ryuushu
Link to comment
Share on other sites

 

Just recover what you lose from sanity draining stuff by adding a custom sanity rate function to your character:

 

-- Stolen from sanity.lualocal function GetNumGhostPlayers()    local num = 0    if GetGhostSanityDrain( TheNet:GetServerGameMode() ) then       for i,v in pairs(AllPlayers) do            if v:HasTag("playerghost") then                num = num + 1            end        end    end    return numendlocal function nospooky(inst)    local delta = 0        -- Recover what we lost from ghost players    local ghost_drain_mult = GetNumGhostPlayers()        if ghost_drain_mult > TUNING.MAX_SANITY_GHOST_PLAYER_DRAIN_MULT then        ghost_drain_mult = TUNING.MAX_SANITY_GHOST_PLAYER_DRAIN_MULT    end        delta = delta + TUNING.SANITY_GHOST_PLAYER_DRAIN * ghost_drain_mult * -1        -- Recover what we lost from ghosts    local aura_delta = 0    local x,y,z = inst.Transform:GetWorldPosition()    local ents = TheSim:FindEntities(x,y,z, TUNING.SANITY_EFFECT_RANGE, {"ghost"}) -- Do ghost players have the tag ghost too?    for k,v in pairs(ents) do         if v.components.sanityaura and v ~= inst then            local distsq = inst:GetDistanceSqToInst(v)            local aura_val = v.components.sanityaura:GetAura(inst)/math.max(1, distsq)            if aura_val < 0 then                aura_val = aura_val * inst.components.sanity.neg_aura_mult            end            aura_delta = aura_delta + aura_val        end    end        delta = delta + (aura_delta * -1)        return deltaend...local function master_postinit()    ...    inst.components.sanity.custom_rate_fn = nospooky    ...end...

.. Thought it'd be shorter <<;

sanity.ghost_drain_mult does nothing, it's more or less handled like a local value in the Recalc function:

self.ghost_drain_mult = GetNumGhostPlayers()
 
@Ryuushu Thank you so much to your help! You are so nice! ;▽; 
Should I put this in mycharacter.lua? Can I ask you where should I exactly put in?
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...