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)
end

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

local function combatdrain(inst, data)
local victim = data.victim
    if IsValidVictim(victim) then
    inst.components.sanity:DoDelta(-5)
    end
end


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
            data.target:HasTag("monster")
            and data.target.components.health ~= nil
            and data.target.components.combat ~= nil then
                inst.components.sanity:DoDelta(-5)
            end
        end
    end
  • 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
 Share

×
  • Create New...