Jump to content

Sanity loss perk help!

Recommended Posts

Hello! I've been browsing the forums and found some useful code lines, but when I try to implement them, nothing happens.

I want my character to lose 5 sanity per hit against anything that isn't a monster, boss, structure or wall.

Here's what I've got.

local master_postinit = function(inst)

inst:ListenForEvent("onattackother", combatdrain)

local function IsValidVictim(victim)
    return victim ~= nil
        and not (victim:HasTag("epic") or
                victim:HasTag("monster") or
                victim:HasTag("structure") or
        and victim.components.health ~= nil
        and victim.components.combat ~= nil

local function combatdrain(inst, data)
local victim = data.victim
    if IsValidVictim(victim) then

However, it isn't working. I'm sure I must have done something stupid, like put it in the wrong place. It is currently in my character's .lua file in scripts/prefabs. Could someone help me get this to work?

Link to comment
Share on other sites

local function master_postinit(inst)
inst:ListenForEvent("onattackother", combatdrain)
local function combatdrain(inst, data) -- to other functions
            if data ~= nil and data.target ~= nil then
            if not data.target:HasTag("epic") or
            data.target:HasTag("structure") or
            data.target:HasTag("wall") or
            and data.target.components.health ~= nil
            and data.target.components.combat ~= nil then
  • Like 1
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

  • Create New...